@@ -128,6 +128,7 @@ const (
128
128
epLabelValues = apiPrefix + "/label/:name/values"
129
129
epSeries = apiPrefix + "/series"
130
130
epTargets = apiPrefix + "/targets"
131
+ epTargetsMetadata = apiPrefix + "/targets/metadata"
131
132
epRules = apiPrefix + "/rules"
132
133
epSnapshot = apiPrefix + "/admin/tsdb/snapshot"
133
134
epDeleteSeries = apiPrefix + "/admin/tsdb/delete_series"
@@ -151,6 +152,9 @@ type RuleType string
151
152
// RuleHealth models the health status of a rule.
152
153
type RuleHealth string
153
154
155
+ // MetricType models the type of a metric.
156
+ type MetricType string
157
+
154
158
const (
155
159
// Possible values for AlertState.
156
160
AlertStateFiring AlertState = "firing"
@@ -179,6 +183,16 @@ const (
179
183
RuleHealthGood = "ok"
180
184
RuleHealthUnknown = "unknown"
181
185
RuleHealthBad = "err"
186
+
187
+ // Possible values for MetricType
188
+ MetricTypeCounter MetricType = "counter"
189
+ MetricTypeGauge MetricType = "gauge"
190
+ MetricTypeHistogram MetricType = "histogram"
191
+ MetricTypeGaugeHistogram MetricType = "gaugehistogram"
192
+ MetricTypeSummary MetricType = "summary"
193
+ MetricTypeInfo MetricType = "info"
194
+ MetricTypeStateset MetricType = "stateset"
195
+ MetricTypeUnknown MetricType = "unknown"
182
196
)
183
197
184
198
// Error is an error returned by the API.
@@ -242,6 +256,8 @@ type API interface {
242
256
Rules (ctx context.Context ) (RulesResult , api.Error )
243
257
// Targets returns an overview of the current state of the Prometheus target discovery.
244
258
Targets (ctx context.Context ) (TargetsResult , api.Error )
259
+ // TargetsMetadata returns metadata about metrics currently scraped by the target.
260
+ TargetsMetadata (ctx context.Context , matchTarget string , metric string , limit string ) ([]MetricMetadata , api.Error )
245
261
}
246
262
247
263
// AlertsResult contains the result from querying the alerts endpoint.
@@ -351,6 +367,15 @@ type DroppedTarget struct {
351
367
DiscoveredLabels map [string ]string `json:"discoveredLabels"`
352
368
}
353
369
370
+ // MetricMetadata models the metadata of a metric.
371
+ type MetricMetadata struct {
372
+ Target map [string ]string `json:"target"`
373
+ Metric string `json:"metric,omitempty"`
374
+ Type MetricType `json:"type"`
375
+ Help string `json:"help"`
376
+ Unit string `json:"unit"`
377
+ }
378
+
354
379
// queryResult contains result data for a query.
355
380
type queryResult struct {
356
381
Type model.ValueType `json:"resultType"`
@@ -760,6 +785,31 @@ func (h *httpAPI) Targets(ctx context.Context) (TargetsResult, api.Error) {
760
785
return res , api .NewErrorAPI (err , nil )
761
786
}
762
787
788
+ func (h * httpAPI ) TargetsMetadata (ctx context.Context , matchTarget string , metric string , limit string ) ([]MetricMetadata , api.Error ) {
789
+ u := h .client .URL (epTargetsMetadata , nil )
790
+ q := u .Query ()
791
+
792
+ q .Set ("match_target" , matchTarget )
793
+ q .Set ("metric" , metric )
794
+ q .Set ("limit" , limit )
795
+
796
+ u .RawQuery = q .Encode ()
797
+
798
+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
799
+ if err != nil {
800
+ return nil , api .NewErrorAPI (err , nil )
801
+ }
802
+
803
+ _ , body , apiErr := h .client .Do (ctx , req )
804
+ if apiErr != nil {
805
+ return nil , apiErr
806
+ }
807
+
808
+ var res []MetricMetadata
809
+ err = json .Unmarshal (body , & res )
810
+ return res , api .NewErrorAPI (err , nil )
811
+ }
812
+
763
813
// apiClient wraps a regular client and processes successful API responses.
764
814
// Successful also includes responses that errored at the API level.
765
815
type apiClient struct {
0 commit comments