Skip to content

Commit 056e8af

Browse files
authored
Merge pull request #755 from lilic/add-runtimeinfo
api/prometheus/v1/api.go: Add support for status/runtimeinfo endpoint
2 parents 59508bb + 6c43f2e commit 056e8af

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-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)

api/prometheus/v1/api_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ func TestAPIs(t *testing.T) {
144144
}
145145
}
146146

147+
doRuntimeinfo := func() func() (interface{}, Warnings, error) {
148+
return func() (interface{}, Warnings, error) {
149+
v, err := promAPI.Runtimeinfo(context.Background())
150+
return v, nil, err
151+
}
152+
}
153+
147154
doLabelNames := func(label string) func() (interface{}, Warnings, error) {
148155
return func() (interface{}, Warnings, error) {
149156
return promAPI.LabelNames(context.Background())
@@ -605,6 +612,48 @@ func TestAPIs(t *testing.T) {
605612
err: fmt.Errorf("some error"),
606613
},
607614

615+
{
616+
do: doRuntimeinfo(),
617+
reqMethod: "GET",
618+
reqPath: "/api/v1/status/runtimeinfo",
619+
inErr: fmt.Errorf("some error"),
620+
err: fmt.Errorf("some error"),
621+
},
622+
623+
{
624+
do: doRuntimeinfo(),
625+
reqMethod: "GET",
626+
reqPath: "/api/v1/status/runtimeinfo",
627+
inRes: map[string]interface{}{
628+
"startTime": "2020-05-18T15:52:53.4503113Z",
629+
"CWD": "/prometheus",
630+
"reloadConfigSuccess": true,
631+
"lastConfigTime": "2020-05-18T15:52:56Z",
632+
"chunkCount": 72692,
633+
"timeSeriesCount": 18476,
634+
"corruptionCount": 0,
635+
"goroutineCount": 217,
636+
"GOMAXPROCS": 2,
637+
"GOGC": "100",
638+
"GODEBUG": "allocfreetrace",
639+
"storageRetention": "1d",
640+
},
641+
res: RuntimeinfoResult{
642+
StartTime: "2020-05-18T15:52:53.4503113Z",
643+
CWD: "/prometheus",
644+
ReloadConfigSuccess: true,
645+
LastConfigTime: "2020-05-18T15:52:56Z",
646+
ChunkCount: 72692,
647+
TimeSeriesCount: 18476,
648+
CorruptionCount: 0,
649+
GoroutineCount: 217,
650+
GOMAXPROCS: 2,
651+
GOGC: "100",
652+
GODEBUG: "allocfreetrace",
653+
StorageRetention: "1d",
654+
},
655+
},
656+
608657
{
609658
do: doAlertManagers(),
610659
reqMethod: "GET",

0 commit comments

Comments
 (0)