diff --git a/cmd/bosun/search/search.go b/cmd/bosun/search/search.go index 21faa3dcbd..8406afc8cb 100644 --- a/cmd/bosun/search/search.go +++ b/cmd/bosun/search/search.go @@ -284,6 +284,21 @@ func (s *Search) TagKeysByMetric(Metric string) []string { return r } +func (s *Search) MetricsWithTagKeys() map[string][]string { + metricToKeys := make(map[string][]string) + searchResult := s.Read.Tagk.Copy() + for metric, v := range searchResult { + keys := make([]string, len(v)) + i := 0 + for tK := range v { + keys[i] = tK + i++ + } + metricToKeys[metric] = keys + } + return metricToKeys +} + func (s *Search) tagValuesByMetricTagKey(Metric, Tagk string, since time.Duration) []string { var t int64 if since > 0 { diff --git a/cmd/bosun/web/search.go b/cmd/bosun/web/search.go index be1be4543d..8df7cb494d 100644 --- a/cmd/bosun/web/search.go +++ b/cmd/bosun/web/search.go @@ -56,6 +56,11 @@ func MetricsByTagPair(t miniprofiler.Timer, w http.ResponseWriter, r *http.Reque return values, nil } +func MetricsWithTagKeys(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interface{}, error) { + values := schedule.Search.MetricsWithTagKeys() + return values, nil +} + func TagValuesByTagKey(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interface{}, error) { vars := mux.Vars(r) tagk := vars["tagk"] diff --git a/cmd/bosun/web/web.go b/cmd/bosun/web/web.go index 949cf678ec..e9ec7984ed 100644 --- a/cmd/bosun/web/web.go +++ b/cmd/bosun/web/web.go @@ -99,6 +99,7 @@ func Listen(listenAddr string, devMode bool, tsdbHost string) error { router.Handle("/api/metadata/put", JSON(PutMetadata)) router.Handle("/api/metric", JSON(UniqueMetrics)) router.Handle("/api/metric/{tagk}/{tagv}", JSON(MetricsByTagPair)) + router.Handle("/api/metric/tagkey", JSON(MetricsWithTagKeys)) router.Handle("/api/rule", JSON(Rule)) router.HandleFunc("/api/shorten", Shorten) router.Handle("/api/silence/clear", JSON(SilenceClear)) diff --git a/docs/api.md b/docs/api.md index ccf8bb55e7..d1d79ee85b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -87,6 +87,10 @@ Returns dashboard-ready data for all hosts. Returns the metrics that have been relayed through bosun. +### /api/metric/tagkey + +Returns the metrics that have been relayed through bosun and their associated tag keys. + ### /api/metric/{tagk}/{tagv} Returns the metrics that are available for the specified tagk/tagv pair. For