feat(instrumentation): more work

This commit is contained in:
Torkel Ödegaard
2016-06-03 15:06:57 +02:00
parent eee49a4995
commit 1a05ae2eaa
10 changed files with 138 additions and 164 deletions

View File

@@ -237,6 +237,9 @@ func Register(r *macaron.Macaron) {
// metrics
r.Get("/metrics/test", GetTestMetrics)
// metrics
r.Get("/metrics", wrap(GetInternalMetrics))
}, reqSignedIn)
// admin api

View File

@@ -17,6 +17,8 @@ import (
"github.com/grafana/grafana/pkg/util"
)
var i int = 0
var dataProxyTransport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Proxy: http.ProxyFromEnvironment,

View File

@@ -1,10 +1,12 @@
package api
import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/middleware"
"math/rand"
"strconv"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
)
func GetTestMetrics(c *middleware.Context) {
@@ -34,3 +36,35 @@ func GetTestMetrics(c *middleware.Context) {
c.JSON(200, &result)
}
func GetInternalMetrics(c middleware.Context) Response {
snapshots := metrics.MetricStats.GetSnapshots()
resp := make(map[string]interface{})
for _, m := range snapshots {
metricName := m.Name() + m.StringifyTags()
switch metric := m.(type) {
case metrics.Counter:
resp[metricName] = map[string]interface{}{
"count": metric.Count(),
}
case metrics.Timer:
percentiles := metric.Percentiles([]float64{0.25, 0.75, 0.90, 0.99})
resp[metricName] = map[string]interface{}{
"count": metric.Count(),
"min": metric.Min(),
"max": metric.Max(),
"mean": metric.Mean(),
"std": metric.StdDev(),
"p25": percentiles[0],
"p75": percentiles[1],
"p90": percentiles[2],
"p99": percentiles[3],
}
}
}
return Json(200, resp)
}