diff --git a/api/api.go b/api/api.go index 7a6bf7ca5..7aa4e891a 100644 --- a/api/api.go +++ b/api/api.go @@ -2,6 +2,7 @@ package api import ( "code.google.com/p/gorest" + "github.com/prometheus/prometheus/storage/metric" "github.com/prometheus/prometheus/utility" ) @@ -10,5 +11,14 @@ type MetricsService struct { query gorest.EndPoint `method:"GET" path:"/query?{expr:string}&{json:string}" output:"string"` queryRange gorest.EndPoint `method:"GET" path:"/query_range?{expr:string}&{end:int64}&{range:int64}&{step:int64}" output:"string"` - time utility.Time + metrics gorest.EndPoint `method:"GET" path:"/metrics" output:"string"` + + persistence metric.MetricPersistence + time utility.Time +} + +func NewMetricsService(p metric.MetricPersistence) *MetricsService { + return &MetricsService{ + persistence: p, + } } diff --git a/api/query.go b/api/query.go index c25082024..a13bfeb5e 100644 --- a/api/query.go +++ b/api/query.go @@ -2,9 +2,11 @@ package api import ( "code.google.com/p/gorest" + "encoding/json" "errors" "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/rules/ast" + "log" "sort" "time" ) @@ -65,3 +67,22 @@ func (serv MetricsService) QueryRange(Expr string, End int64, Range int64, Step sort.Sort(matrix) return ast.TypedValueToJSON(matrix, "matrix") } + +func (serv MetricsService) Metrics() string { + metricNames, err := serv.persistence.GetAllMetricNames() + rb := serv.ResponseBuilder() + rb.SetContentType(gorest.Application_Json) + if err != nil { + log.Printf("Error loading metric names: %v", err) + rb.SetResponseCode(500) + return err.Error() + } + sort.Strings(metricNames) + resultBytes, err := json.Marshal(metricNames) + if err != nil { + log.Printf("Error marshalling metric names: %v", err) + rb.SetResponseCode(500) + return err.Error() + } + return string(resultBytes) +} diff --git a/main.go b/main.go index fef264131..b5c7995dd 100644 --- a/main.go +++ b/main.go @@ -49,8 +49,7 @@ func main() { persistence, err := leveldb.NewLevelDBMetricPersistence(*metricsStoragePath) if err != nil { - log.Print(err) - os.Exit(1) + log.Fatalf("Error opening storage: %v", err) } go func() { @@ -79,7 +78,7 @@ func main() { } go func() { - gorest.RegisterService(new(api.MetricsService)) + gorest.RegisterService(api.NewMetricsService(persistence)) exporter := registry.DefaultRegistry.YieldExporter() http.Handle("/", gorest.Handle()) diff --git a/static/graph.html b/static/graph.html index b3bc371b2..2d64d9e6a 100644 --- a/static/graph.html +++ b/static/graph.html @@ -22,7 +22,12 @@