Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add runtime telemetry to heartbeat #583

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/legacy/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (

const (
logFileName = "retina.log"
heartbeatInterval = 5 * time.Minute
heartbeatInterval = 10 * time.Minute

nodeNameEnvKey = "NODE_NAME"
nodeIPEnvKey = "NODE_IP"
Expand Down
23 changes: 22 additions & 1 deletion pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"runtime"
"runtime/debug"
"strconv"
"sync"
"time"

Expand All @@ -20,6 +21,13 @@ import (
var (
client appinsights.TelemetryClient
version string
mbShift uint64 = 20

// property keys
kernelversion = "kernelversion"
allocatedmem = "allocmem"
sysmem = "sysmem"
goroutines = "goroutines"
)

type Telemetry interface {
Expand Down Expand Up @@ -143,7 +151,20 @@ func (t *TelemetryClient) heartbeat(ctx context.Context) {
t.trackWarning(err, "failed to get kernel version")
}

t.TrackEvent("heartbeat", map[string]string{"kernelversion": kernelVersion})
var m runtime.MemStats
runtime.ReadMemStats(&m)
props := map[string]string{
kernelversion: kernelVersion,
allocatedmem: strconv.FormatUint(bToMb(m.Alloc), 10),
sysmem: strconv.FormatUint(bToMb(m.Sys), 10),
goroutines: strconv.Itoa(runtime.NumGoroutine()),
}

t.TrackEvent("heartbeat", props)
}

func bToMb(b uint64) uint64 {
return b >> mbShift
}

func (t *TelemetryClient) TrackEvent(name string, properties map[string]string) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ func TestTelemetryClient_StopPerf(t *testing.T) {
})
}
}

func TestBtoMB(t *testing.T) {
require.Equal(t, uint64(1), bToMb(1048576))
}
Loading