diff options
| author | Will Norris <will@tailscale.com> | 2025-06-27 13:11:59 -0400 |
|---|---|---|
| committer | Will Norris <will@willnorris.com> | 2025-06-28 21:39:58 -0700 |
| commit | f85e4bcb3287a0adef9567ff79ba58d9cec4e1d2 (patch) | |
| tree | e2a13291cfef9a647b05fce2b1d22f3dee42fc51 | |
| parent | ee8c3560ef74613443859e1f78a0c9b9071bac76 (diff) | |
| download | tailscale-f85e4bcb3287a0adef9567ff79ba58d9cec4e1d2.tar.xz tailscale-f85e4bcb3287a0adef9567ff79ba58d9cec4e1d2.zip | |
client/systray: replace counter metric with gauge
Replace the existing systray_start counter metrics with a
systray_running gauge metrics.
This also adds an IncrementGauge method to local client to parallel
IncrementCounter. The LocalAPI handler supports both, we've just never
added a client method for gauges.
Updates #1708
Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <will@tailscale.com>
| -rw-r--r-- | client/local/local.go | 17 | ||||
| -rw-r--r-- | client/systray/systray.go | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/client/local/local.go b/client/local/local.go index 12bf2f7d6..74c4f0b6f 100644 --- a/client/local/local.go +++ b/client/local/local.go @@ -398,6 +398,23 @@ func (lc *Client) IncrementCounter(ctx context.Context, name string, delta int) return err } +// IncrementGauge increments the value of a Tailscale daemon's gauge +// metric by the given delta. If the metric has yet to exist, a new gauge +// metric is created and initialized to delta. The delta value can be negative. +func (lc *Client) IncrementGauge(ctx context.Context, name string, delta int) error { + type metricUpdate struct { + Name string `json:"name"` + Type string `json:"type"` + Value int `json:"value"` // amount to increment by + } + _, err := lc.send(ctx, "POST", "/localapi/v0/upload-client-metrics", 200, jsonBody([]metricUpdate{{ + Name: name, + Type: "gauge", + Value: delta, + }})) + return err +} + // TailDaemonLogs returns a stream the Tailscale daemon's logs as they arrive. // Close the context to stop the stream. func (lc *Client) TailDaemonLogs(ctx context.Context) (io.Reader, error) { diff --git a/client/systray/systray.go b/client/systray/systray.go index 195a157fb..a87783c06 100644 --- a/client/systray/systray.go +++ b/client/systray/systray.go @@ -61,7 +61,8 @@ func (menu *Menu) Run() { case <-menu.bgCtx.Done(): } }() - go menu.lc.IncrementCounter(menu.bgCtx, "systray_start", 1) + go menu.lc.IncrementGauge(menu.bgCtx, "systray_running", 1) + defer menu.lc.IncrementGauge(menu.bgCtx, "systray_running", -1) systray.Run(menu.onReady, menu.onExit) } |
