@@ -130,6 +130,7 @@ const (
130
130
epSeries = apiPrefix + "/series"
131
131
epTargets = apiPrefix + "/targets"
132
132
epTargetsMetadata = apiPrefix + "/targets/metadata"
133
+ epMetadata = apiPrefix + "/metadata"
133
134
epRules = apiPrefix + "/rules"
134
135
epSnapshot = apiPrefix + "/admin/tsdb/snapshot"
135
136
epDeleteSeries = apiPrefix + "/admin/tsdb/delete_series"
@@ -248,6 +249,8 @@ type API interface {
248
249
Targets (ctx context.Context ) (TargetsResult , error )
249
250
// TargetsMetadata returns metadata about metrics currently scraped by the target.
250
251
TargetsMetadata (ctx context.Context , matchTarget string , metric string , limit string ) ([]MetricMetadata , error )
252
+ // Metadata returns metadata about metrics currently scraped by the metric name.
253
+ Metadata (ctx context.Context , metric string , limit string ) (map [string ][]Metadata , error )
251
254
}
252
255
253
256
// AlertsResult contains the result from querying the alerts endpoint.
@@ -357,7 +360,7 @@ type DroppedTarget struct {
357
360
DiscoveredLabels map [string ]string `json:"discoveredLabels"`
358
361
}
359
362
360
- // MetricMetadata models the metadata of a metric.
363
+ // MetricMetadata models the metadata of a metric with its scrape target and name .
361
364
type MetricMetadata struct {
362
365
Target map [string ]string `json:"target"`
363
366
Metric string `json:"metric,omitempty"`
@@ -366,6 +369,13 @@ type MetricMetadata struct {
366
369
Unit string `json:"unit"`
367
370
}
368
371
372
+ // Metadata models the metadata of a metric.
373
+ type Metadata struct {
374
+ Type MetricType `json:"type"`
375
+ Help string `json:"help"`
376
+ Unit string `json:"unit"`
377
+ }
378
+
369
379
// queryResult contains result data for a query.
370
380
type queryResult struct {
371
381
Type model.ValueType `json:"resultType"`
@@ -802,6 +812,29 @@ func (h *httpAPI) TargetsMetadata(ctx context.Context, matchTarget string, metri
802
812
return res , json .Unmarshal (body , & res )
803
813
}
804
814
815
+ func (h * httpAPI ) Metadata (ctx context.Context , metric string , limit string ) (map [string ][]Metadata , error ) {
816
+ u := h .client .URL (epMetadata , nil )
817
+ q := u .Query ()
818
+
819
+ q .Set ("metric" , metric )
820
+ q .Set ("limit" , limit )
821
+
822
+ u .RawQuery = q .Encode ()
823
+
824
+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
825
+ if err != nil {
826
+ return nil , err
827
+ }
828
+
829
+ _ , body , _ , err := h .client .Do (ctx , req )
830
+ if err != nil {
831
+ return nil , err
832
+ }
833
+
834
+ var res map [string ][]Metadata
835
+ return res , json .Unmarshal (body , & res )
836
+ }
837
+
805
838
// Warnings is an array of non critical errors
806
839
type Warnings []string
807
840
0 commit comments