Repository: prometheus/prometheus (language: go)

Issue:
Include current server hostname and time in the status page
### Proposal

We run Prometheus behind a load balancer, so when opening the GUI in a browser the user may connect to any one of a pool of servers.  Standard webhosting stuff.  Today when debugging a flappy alert issue I received this big warning box:

```
Warning: Error fetching server time: Detected 369.1080000400543 seconds time difference between your browser and the server. Prometheus relies on accurate time and time drift might cause unexpected query results.
```

Okay, well let's go debug that.  Except chasing through the infrastructure I wasn't able to find any problems.  All seemed well, and the warning vanished as ephemerally as it arrived.

In debugging this it would have been useful to hit the `/status` endpoint and see:

- Which node I've been load balanced to
- What the time on that node is

That would have made it easier to try and zero in on the problem from both the client and server side.  It would have been useful to know what Prom thought the server time was when that error was displayed, and I think it would be useful to show generally in the status page.  Thanks.
Include current server hostname and time in the status page
### Proposal

We run Prometheus behind a load balancer, so when opening the GUI in a browser the user may connect to any one of a pool of servers.  Standard webhosting stuff.  Today when debugging a flappy alert issue I received this big warning box:

```
Warning: Error fetching server time: Detected 369.1080000400543 seconds time difference between your browser and the server. Prometheus relies on accurate time and time drift might cause unexpected query results.
```

Okay, well let's go debug that.  Except chasing through the infrastructure I wasn't able to find any problems.  All seemed well, and the warning vanished as ephemerally as it arrived.

In debugging this it would have been useful to hit the `/status` endpoint and see:

- Which node I've been load balanced to
- What the time on that node is

That would have made it easier to try and zero in on the problem from both the client and server side.  It would have been useful to know what Prom thought the server time was when that error was displayed, and I think it would be useful to show generally in the status page.  Thanks.


Discussion / hints:

Fix patch:
diff --git a/docs/querying/api.md b/docs/querying/api.md
index 87de463288c..f1e71293031 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 392dfc6aabf..49112c78883 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 71dc476a2d6..c968f1e8663 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 08c683bae88..9ce66b7ff5e 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()
 	}


Test patch: