Private
Public Access
1
0

Add png graph handler
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-12-09 13:53:56 -08:00
parent 69cc4b4e80
commit e824274998
13 changed files with 400 additions and 135 deletions

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.22.0
// sqlc v1.24.0
package ntpdb

View File

@@ -1,14 +1,58 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.22.0
// sqlc v1.24.0
package ntpdb
import (
"database/sql"
"database/sql/driver"
"fmt"
"time"
)
type ServersIpVersion string
const (
ServersIpVersionV4 ServersIpVersion = "v4"
ServersIpVersionV6 ServersIpVersion = "v6"
)
func (e *ServersIpVersion) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = ServersIpVersion(s)
case string:
*e = ServersIpVersion(s)
default:
return fmt.Errorf("unsupported scan type for ServersIpVersion: %T", src)
}
return nil
}
type NullServersIpVersion struct {
ServersIpVersion ServersIpVersion `json:"servers_ip_version"`
Valid bool `json:"valid"` // Valid is true if ServersIpVersion is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullServersIpVersion) Scan(value interface{}) error {
if value == nil {
ns.ServersIpVersion, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.ServersIpVersion.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullServersIpVersion) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.ServersIpVersion), nil
}
type ZoneServerCountsIpVersion string
const (
@@ -50,3 +94,21 @@ func (ns NullZoneServerCountsIpVersion) Value() (driver.Value, error) {
}
return string(ns.ZoneServerCountsIpVersion), nil
}
type Server struct {
ID uint32 `db:"id" json:"id"`
Ip string `db:"ip" json:"ip"`
IpVersion ServersIpVersion `db:"ip_version" json:"ip_version"`
UserID uint32 `db:"user_id" json:"user_id"`
AccountID sql.NullInt32 `db:"account_id" json:"account_id"`
Hostname sql.NullString `db:"hostname" json:"hostname"`
Stratum sql.NullInt32 `db:"stratum" json:"stratum"`
InPool uint32 `db:"in_pool" json:"in_pool"`
InServerList uint32 `db:"in_server_list" json:"in_server_list"`
Netspeed uint32 `db:"netspeed" json:"netspeed"`
CreatedOn time.Time `db:"created_on" json:"created_on"`
UpdatedOn time.Time `db:"updated_on" json:"updated_on"`
ScoreTs sql.NullTime `db:"score_ts" json:"score_ts"`
ScoreRaw float64 `db:"score_raw" json:"score_raw"`
DeletionOn sql.NullTime `db:"deletion_on" json:"deletion_on"`
}

View File

@@ -78,6 +78,52 @@ func (_d QuerierTxWithTracing) Commit(ctx context.Context) (err error) {
return _d.QuerierTx.Commit(ctx)
}
// GetServerByID implements QuerierTx
func (_d QuerierTxWithTracing) GetServerByID(ctx context.Context, id uint32) (s1 Server, err error) {
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetServerByID")
defer func() {
if _d._spanDecorator != nil {
_d._spanDecorator(_span, map[string]interface{}{
"ctx": ctx,
"id": id}, map[string]interface{}{
"s1": s1,
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
)
}
_span.End()
}()
return _d.QuerierTx.GetServerByID(ctx, id)
}
// GetServerByIP implements QuerierTx
func (_d QuerierTxWithTracing) GetServerByIP(ctx context.Context, ip string) (s1 Server, err error) {
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetServerByIP")
defer func() {
if _d._spanDecorator != nil {
_d._spanDecorator(_span, map[string]interface{}{
"ctx": ctx,
"ip": ip}, map[string]interface{}{
"s1": s1,
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
)
}
_span.End()
}()
return _d.QuerierTx.GetServerByIP(ctx, ip)
}
// GetServerNetspeed implements QuerierTx
func (_d QuerierTxWithTracing) GetServerNetspeed(ctx context.Context, ip string) (u1 uint32, err error) {
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetServerNetspeed")

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.22.0
// sqlc v1.24.0
package ntpdb
@@ -9,6 +9,8 @@ import (
)
type Querier interface {
GetServerByID(ctx context.Context, id uint32) (Server, error)
GetServerByIP(ctx context.Context, ip string) (Server, error)
GetServerNetspeed(ctx context.Context, ip string) (uint32, error)
GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow, error)
GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStatsV2Row, error)

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.22.0
// sqlc v1.24.0
// source: query.sql
package ntpdb
@@ -10,6 +10,64 @@ import (
"time"
)
const getServerByID = `-- name: GetServerByID :one
select id, ip, ip_version, user_id, account_id, hostname, stratum, in_pool, in_server_list, netspeed, created_on, updated_on, score_ts, score_raw, deletion_on from servers
where
id = ?
`
func (q *Queries) GetServerByID(ctx context.Context, id uint32) (Server, error) {
row := q.db.QueryRowContext(ctx, getServerByID, id)
var i Server
err := row.Scan(
&i.ID,
&i.Ip,
&i.IpVersion,
&i.UserID,
&i.AccountID,
&i.Hostname,
&i.Stratum,
&i.InPool,
&i.InServerList,
&i.Netspeed,
&i.CreatedOn,
&i.UpdatedOn,
&i.ScoreTs,
&i.ScoreRaw,
&i.DeletionOn,
)
return i, err
}
const getServerByIP = `-- name: GetServerByIP :one
select id, ip, ip_version, user_id, account_id, hostname, stratum, in_pool, in_server_list, netspeed, created_on, updated_on, score_ts, score_raw, deletion_on from servers
where
ip = ?
`
func (q *Queries) GetServerByIP(ctx context.Context, ip string) (Server, error) {
row := q.db.QueryRowContext(ctx, getServerByIP, ip)
var i Server
err := row.Scan(
&i.ID,
&i.Ip,
&i.IpVersion,
&i.UserID,
&i.AccountID,
&i.Hostname,
&i.Stratum,
&i.InPool,
&i.InServerList,
&i.Netspeed,
&i.CreatedOn,
&i.UpdatedOn,
&i.ScoreTs,
&i.ScoreRaw,
&i.DeletionOn,
)
return i, err
}
const getServerNetspeed = `-- name: GetServerNetspeed :one
select netspeed from servers where ip = ?
`