diff --git a/cmd/calls/main.go b/cmd/calls/main.go index 9a63a4a..bc9628c 100644 --- a/cmd/calls/main.go +++ b/cmd/calls/main.go @@ -111,7 +111,7 @@ func main() { log.Println(v.Notification.Msg) case *pb.Message_Hello: ver := v.Hello.Version - log.Printf("server says: welcome to %s %s built %s for %s", ver.ServerName, ver.Version, ver.Built, ver.Platform) + log.Printf("server says: welcome to %s %s built %s for %s calls table size %s", ver.ServerName, ver.Version, ver.Built, ver.Platform, ver.CallsSize) default: log.Printf("received other message not known") } diff --git a/pkg/gordio/database/calls.sql.go b/pkg/gordio/database/calls.sql.go index 9050ac4..e0cca12 100644 --- a/pkg/gordio/database/calls.sql.go +++ b/pkg/gordio/database/calls.sql.go @@ -78,6 +78,17 @@ func (q *Queries) AddCall(ctx context.Context, arg AddCallParams) (uuid.UUID, er return id, err } +const getCallsTableSize = `-- name: GetCallsTableSize :one +SELECT pg_size_pretty(pg_total_relation_size('calls')) +` + +func (q *Queries) GetCallsTableSize(ctx context.Context) (string, error) { + row := q.db.QueryRow(ctx, getCallsTableSize) + var pg_size_pretty string + err := row.Scan(&pg_size_pretty) + return pg_size_pretty, err +} + const setCallTranscript = `-- name: SetCallTranscript :exec UPDATE calls SET transcript = $2 WHERE id = $1 ` diff --git a/pkg/gordio/database/querier.go b/pkg/gordio/database/querier.go index b95c6aa..1e3c5f8 100644 --- a/pkg/gordio/database/querier.go +++ b/pkg/gordio/database/querier.go @@ -19,6 +19,7 @@ type Querier interface { DeleteAPIKey(ctx context.Context, apiKey string) error DeleteUser(ctx context.Context, username string) error GetAPIKey(ctx context.Context, apiKey string) (ApiKey, error) + GetCallsTableSize(ctx context.Context) (string, error) GetTalkgroup(ctx context.Context, systemID int, tgid int) (Talkgroup, error) GetTalkgroupIDsByTags(ctx context.Context, anytags []string, alltags []string, nottags []string) ([]GetTalkgroupIDsByTagsRow, error) GetTalkgroupTags(ctx context.Context, sys int, tg int) ([]string, error) diff --git a/pkg/gordio/nexus/client.go b/pkg/gordio/nexus/client.go index 4f37854..536bd53 100644 --- a/pkg/gordio/nexus/client.go +++ b/pkg/gordio/nexus/client.go @@ -7,6 +7,7 @@ import ( "sync" "dynatron.me/x/stillbox/pkg/calls" + "dynatron.me/x/stillbox/pkg/gordio/database" "dynatron.me/x/stillbox/pkg/gordio/version" "dynatron.me/x/stillbox/pkg/pb" @@ -20,7 +21,7 @@ type Client interface { Connection - Hello() + Hello(context.Context) HandleCommand(context.Context, *pb.Command) HandleMessage(context.Context, []byte) } @@ -67,20 +68,27 @@ func (c *client) HandleMessage(ctx context.Context, mesgBytes []byte) { c.HandleCommand(ctx, &msg) } -func pbVersion() *pb.Version { +func pbVersion(ctx context.Context) *pb.Version { + cts, err := database.FromCtx(ctx).GetCallsTableSize(ctx) + if err != nil { + log.Error().Err(err).Msg("get calls table size") + cts = "unknown" + } + return &pb.Version{ ServerName: version.Name, Version: version.Version, Built: version.Built, Platform: runtime.GOOS + "-" + runtime.GOARCH, + CallsSize: cts, } } -func (c *client) Hello() { +func (c *client) Hello(ctx context.Context) { c.Send(&pb.Message{ ToClientMessage: &pb.Message_Hello{ Hello: &pb.Hello{ - Version: pbVersion(), + Version: pbVersion(ctx), }, }, }) diff --git a/pkg/gordio/nexus/websocket.go b/pkg/gordio/nexus/websocket.go index d0de755..22fb391 100644 --- a/pkg/gordio/nexus/websocket.go +++ b/pkg/gordio/nexus/websocket.go @@ -78,13 +78,14 @@ func (wm *wsManager) serveWS(w http.ResponseWriter, r *http.Request) { return } + ctx := r.Context() wsc := newWsConn(conn) cli := wm.NewClient(wsc) wm.Register(cli) - go wsc.readPump(r.Context(), wm, cli) + go wsc.readPump(ctx, wm, cli) go wsc.writePump() - cli.Hello() + cli.Hello(ctx) } func (conn *wsConn) readPump(ctx context.Context, reg Registry, c Client) { diff --git a/pkg/pb/stillbox.pb.go b/pkg/pb/stillbox.pb.go index 033a1d0..a32e46e 100644 --- a/pkg/pb/stillbox.pb.go +++ b/pkg/pb/stillbox.pb.go @@ -1080,6 +1080,7 @@ type Version struct { Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` Built string `protobuf:"bytes,3,opt,name=built,proto3" json:"built,omitempty"` Platform string `protobuf:"bytes,4,opt,name=platform,proto3" json:"platform,omitempty"` + CallsSize string `protobuf:"bytes,5,opt,name=calls_size,json=callsSize,proto3" json:"calls_size,omitempty"` } func (x *Version) Reset() { @@ -1142,6 +1143,13 @@ func (x *Version) GetPlatform() string { return "" } +func (x *Version) GetCallsSize() string { + if x != nil { + return x.CallsSize + } + return "" +} + var File_stillbox_proto protoreflect.FileDescriptor var file_stillbox_proto_rawDesc = []byte{ @@ -1288,14 +1296,16 @@ var file_stillbox_proto_rawDesc = []byte{ 0x2c, 0x0a, 0x12, 0x74, 0x61, 0x6c, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x74, 0x61, 0x67, 0x73, 0x5f, 0x6e, 0x6f, 0x74, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x10, 0x74, 0x61, 0x6c, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x54, 0x61, 0x67, 0x73, 0x4e, 0x6f, 0x74, 0x22, 0x08, 0x0a, - 0x06, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x22, 0x76, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4e, - 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, - 0x05, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x62, 0x75, - 0x69, 0x6c, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x2a, + 0x06, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x22, 0x95, 0x01, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x14, + 0x0a, 0x05, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x62, + 0x75, 0x69, 0x6c, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, + 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x53, 0x69, 0x7a, 0x65, 0x2a, 0x37, 0x0a, 0x09, 0x4c, 0x69, 0x76, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0e, 0x0a, 0x0a, 0x4c, 0x53, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x4c, 0x53, 0x5f, 0x4c, 0x49, 0x56, 0x45, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x4c, 0x53, 0x5f, diff --git a/pkg/pb/stillbox.proto b/pkg/pb/stillbox.proto index 8a49ce8..4af7863 100644 --- a/pkg/pb/stillbox.proto +++ b/pkg/pb/stillbox.proto @@ -110,4 +110,5 @@ message Version { string version = 2; string built = 3; string platform = 4; + string calls_size = 5; } diff --git a/sql/postgres/queries/calls.sql b/sql/postgres/queries/calls.sql index 22dcd3d..a6d734f 100644 --- a/sql/postgres/queries/calls.sql +++ b/sql/postgres/queries/calls.sql @@ -22,3 +22,6 @@ RETURNING id; -- name: SetCallTranscript :exec UPDATE calls SET transcript = $2 WHERE id = $1; + +-- name: GetCallsTableSize :one +SELECT pg_size_pretty(pg_total_relation_size('calls'));