From 73a3438c1b6da19adcb099b62ae5376dee95b352 Mon Sep 17 00:00:00 2001 From: sujal shah Date: Sun, 5 Jan 2025 23:45:47 +0530 Subject: [PATCH] api: Add two new fields Node and ServerTime. This commit introduced two field in `/status` endpoint: - The node currently serving the request. - The current server time for debugging time drift issues. fixes #15394. Signed-off-by: sujal shah --- docs/querying/api.md | 2 ++ web/api/v1/api.go | 2 ++ web/ui/mantine-ui/src/pages/StatusPage.tsx | 6 ++++++ web/web.go | 7 +++++++ 4 files changed, 17 insertions(+) diff --git a/docs/querying/api.md b/docs/querying/api.md index 87de463288..f1e7129303 100644 --- a/docs/querying/api.md +++ b/docs/querying/api.md @@ -1158,6 +1158,8 @@ $ curl http://localhost:9090/api/v1/status/runtimeinfo "data": { "startTime": "2019-11-02T17:23:59.301361365+01:00", "CWD": "/", + "hostname" : "DESKTOP-717H17Q", + "serverTime": "2025-01-05T18:27:33Z", "reloadConfigSuccess": true, "lastConfigTime": "2019-11-02T17:23:59+01:00", "timeSeriesCount": 873, diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 392dfc6aab..49112c7888 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -144,6 +144,8 @@ type PrometheusVersion struct { type RuntimeInfo struct { StartTime time.Time `json:"startTime"` CWD string `json:"CWD"` + Hostname string `json:"hostname"` + ServerTime time.Time `json:"serverTime"` ReloadConfigSuccess bool `json:"reloadConfigSuccess"` LastConfigTime time.Time `json:"lastConfigTime"` CorruptionCount int64 `json:"corruptionCount"` diff --git a/web/ui/mantine-ui/src/pages/StatusPage.tsx b/web/ui/mantine-ui/src/pages/StatusPage.tsx index 71dc476a2d..c968f1e866 100644 --- a/web/ui/mantine-ui/src/pages/StatusPage.tsx +++ b/web/ui/mantine-ui/src/pages/StatusPage.tsx @@ -29,6 +29,12 @@ export default function StatusPage() { formatTimestamp(new Date(v as string).valueOf() / 1000, useLocalTime), }, CWD: { title: "Working directory" }, + hostname: { title: "Hostname" }, + serverTime: { + title: "Server Time", + formatValue: (v: string | boolean) => + formatTimestamp(new Date(v as string).valueOf() / 1000, useLocalTime), + }, reloadConfigSuccess: { title: "Configuration reload", formatValue: (v: string | boolean) => (v ? "Successful" : "Unsuccessful"), diff --git a/web/web.go b/web/web.go index 08c683bae8..9ce66b7ff5 100644 --- a/web/web.go +++ b/web/web.go @@ -804,6 +804,13 @@ func (h *Handler) runtimeInfo() (api_v1.RuntimeInfo, error) { GODEBUG: os.Getenv("GODEBUG"), } + hostname, err := os.Hostname() + if err != nil { + return status, fmt.Errorf("Error getting hostname: %w", err) + } + status.Hostname = hostname + status.ServerTime = time.Now().UTC() + if h.options.TSDBRetentionDuration != 0 { status.StorageRetention = h.options.TSDBRetentionDuration.String() }