From 119864d28348b4a83ab0f2e46d67227d63f0f8ff Mon Sep 17 00:00:00 2001 From: Kyle Brandt Date: Thu, 17 Sep 2015 19:31:34 +0000 Subject: [PATCH] cmd/bosun: Add last API route returns most recent datapoint for metric+tagset --- cmd/bosun/web/web.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/bosun/web/web.go b/cmd/bosun/web/web.go index a9e36ea8f4..2141245ba7 100644 --- a/cmd/bosun/web/web.go +++ b/cmd/bosun/web/web.go @@ -93,6 +93,7 @@ func Listen(listenAddr string, devMode bool, tsdbHost string) error { router.Handle("/api/graph", JSON(Graph)) router.Handle("/api/health", JSON(HealthCheck)) router.Handle("/api/host", JSON(Host)) + router.Handle("/api/last", JSON(Last)) router.Handle("/api/incidents", JSON(Incidents)) router.Handle("/api/incidents/events", JSON(IncidentEvents)) router.Handle("/api/metadata/get", JSON(GetMetadata)) @@ -569,6 +570,17 @@ func Host(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interfa return schedule.Host(r.FormValue("filter")), nil } +// Last returns the most recent datapoint for a metric+tagset. The metric+tagset +// string should be formated like os.cpu{host=foo}. The tag porition expects the +// that the keys will be in alphabetical order. +func Last(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interface{}, error) { + var counter bool + if r.FormValue("counter") != "" { + counter = true + } + return schedule.Search.GetLast(r.FormValue("metric"), r.FormValue("tagset"), counter) +} + func Version(w http.ResponseWriter, r *http.Request) { io.WriteString(w, version.GetVersionInfo("bosun")) }