Merge pull request #15784 from sujalshah-bit/15394_server_name_and_time

api: Add two new fields Hostname and ServerTime.
This commit is contained in:
Julius Volz 2025-01-07 13:36:53 +01:00 committed by GitHub
commit 18bb8bf996
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 0 deletions

View file

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

View file

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

View file

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

View file

@ -806,6 +806,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()
}