Skip to content

Commit c9e3c02

Browse files
committed
api/prometheus/v1/api.go: Add support for /runtimeinfo endpoint
Signed-off-by: Lili Cosic <[email protected]>
1 parent bff02dd commit c9e3c02

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

api/prometheus/v1/api.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const (
137137
epCleanTombstones = apiPrefix + "/admin/tsdb/clean_tombstones"
138138
epConfig = apiPrefix + "/status/config"
139139
epFlags = apiPrefix + "/status/flags"
140+
epRuntimeinfo = apiPrefix + "/status/runtimeinfo"
140141
)
141142

142143
// AlertState models the state of an alert.
@@ -238,6 +239,8 @@ type API interface {
238239
Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error)
239240
// QueryRange performs a query for the given range.
240241
QueryRange(ctx context.Context, query string, r Range) (model.Value, Warnings, error)
242+
// Runtimeinfo returns the various runtime information properties about the Prometheus server.
243+
Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error)
241244
// Series finds series by label matchers.
242245
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, Warnings, error)
243246
// Snapshot creates a snapshot of all current data into snapshots/<datetime>-<rand>
@@ -277,6 +280,22 @@ type ConfigResult struct {
277280
// FlagsResult contains the result from querying the flag endpoint.
278281
type FlagsResult map[string]string
279282

283+
// RuntimeinfoResult contains the result from querying the runtimeinfo endpoint.
284+
type RuntimeinfoResult struct {
285+
StartTime string `json:"startTime"`
286+
CWD string `json:"CWD"`
287+
ReloadConfigSuccess bool `json:"reloadConfigSuccess"`
288+
LastConfigTime string `json:"lastConfigTime"`
289+
ChunkCount int `json:"chunkCount"`
290+
TimeSeriesCount int `json:"timeSeriesCount"`
291+
CorruptionCount int `json:"corruptionCount"`
292+
GoroutineCount int `json:"goroutineCount"`
293+
GOMAXPROCS int `json:"GOMAXPROCS"`
294+
GOGC string `json:"GOGC"`
295+
GODEBUG string `json:"GODEBUG"`
296+
StorageRetention string `json:"storageRetention"`
297+
}
298+
280299
// SnapshotResult contains the result from querying the snapshot endpoint.
281300
type SnapshotResult struct {
282301
Name string `json:"name"`
@@ -640,6 +659,23 @@ func (h *httpAPI) Flags(ctx context.Context) (FlagsResult, error) {
640659
return res, json.Unmarshal(body, &res)
641660
}
642661

662+
func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
663+
u := h.client.URL(epRuntimeinfo, nil)
664+
665+
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
666+
if err != nil {
667+
return RuntimeinfoResult{}, err
668+
}
669+
670+
_, body, _, err := h.client.Do(ctx, req)
671+
if err != nil {
672+
return RuntimeinfoResult{}, err
673+
}
674+
675+
var res RuntimeinfoResult
676+
return res, json.Unmarshal(body, &res)
677+
}
678+
643679
func (h *httpAPI) LabelNames(ctx context.Context) ([]string, Warnings, error) {
644680
u := h.client.URL(epLabels, nil)
645681
req, err := http.NewRequest(http.MethodGet, u.String(), nil)

0 commit comments

Comments
 (0)