mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(instrumentation): more work
This commit is contained in:
@@ -237,6 +237,9 @@ func Register(r *macaron.Macaron) {
|
||||
// metrics
|
||||
r.Get("/metrics/test", GetTestMetrics)
|
||||
|
||||
// metrics
|
||||
r.Get("/metrics", wrap(GetInternalMetrics))
|
||||
|
||||
}, reqSignedIn)
|
||||
|
||||
// admin api
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user