Calls size

This commit is contained in:
Daniel 2024-10-20 12:26:32 -04:00
parent f6fd5f7089
commit 9f2ddada28
8 changed files with 50 additions and 15 deletions

View file

@ -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")
}

View file

@ -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
`

View file

@ -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)

View file

@ -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),
},
},
})

View file

@ -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) {

View file

@ -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,

View file

@ -110,4 +110,5 @@ message Version {
string version = 2;
string built = 3;
string platform = 4;
string calls_size = 5;
}

View file

@ -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'));