Merge branch 'master' into alerting_definitions
Conflicts: conf/defaults.ini pkg/api/dashboard.go
This commit is contained in:
+4
-1
@@ -237,7 +237,10 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/search/", Search)
|
||||
|
||||
// metrics
|
||||
r.Get("/metrics/test", GetTestMetrics)
|
||||
r.Get("/metrics/test", wrap(GetTestMetrics))
|
||||
|
||||
// metrics
|
||||
r.Get("/metrics", wrap(GetInternalMetrics))
|
||||
|
||||
r.Group("/alerts", func() {
|
||||
r.Group("/rules", func() {
|
||||
|
||||
@@ -30,7 +30,7 @@ func InitAppPluginRoutes(r *macaron.Macaron) {
|
||||
}
|
||||
handlers = append(handlers, AppPluginRoute(route, plugin.Id))
|
||||
r.Route(url, route.Method, handlers...)
|
||||
log.Info("Plugins: Adding proxy route %s", url)
|
||||
log.Debug("Plugins: Adding proxy route %s", url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -12,8 +12,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
NotFound = ApiError(404, "Not found", nil)
|
||||
ServerError = ApiError(500, "Server error", nil)
|
||||
NotFound = func() Response {
|
||||
return ApiError(404, "Not found", nil)
|
||||
}
|
||||
ServerError = func(err error) Response {
|
||||
return ApiError(500, "Server error", err)
|
||||
}
|
||||
)
|
||||
|
||||
type Response interface {
|
||||
@@ -34,7 +38,7 @@ func wrap(action interface{}) macaron.Handler {
|
||||
if err == nil && val != nil && len(val) > 0 {
|
||||
res = val[0].Interface().(Response)
|
||||
} else {
|
||||
res = ServerError
|
||||
res = ServerError(err)
|
||||
}
|
||||
|
||||
res.WriteTo(c.Resp)
|
||||
|
||||
@@ -32,8 +32,6 @@ func isDashboardStarredByUser(c *middleware.Context, dashId int64) (bool, error)
|
||||
}
|
||||
|
||||
func GetDashboard(c *middleware.Context) {
|
||||
metrics.M_Api_Dashboard_Get.Inc(1)
|
||||
|
||||
slug := strings.ToLower(c.Params(":slug"))
|
||||
|
||||
query := m.GetDashboardQuery{Slug: slug, OrgId: c.OrgId}
|
||||
@@ -77,6 +75,7 @@ func GetDashboard(c *middleware.Context) {
|
||||
},
|
||||
}
|
||||
|
||||
c.TimeRequest(metrics.M_Api_Dashboard_Get)
|
||||
c.JSON(200, dto)
|
||||
}
|
||||
|
||||
@@ -166,8 +165,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
|
||||
}
|
||||
}
|
||||
|
||||
metrics.M_Api_Dashboard_Post.Inc(1)
|
||||
|
||||
c.TimeRequest(metrics.M_Api_Dashboard_Save)
|
||||
c.JSON(200, util.DynMap{"status": "success", "slug": cmd.Result.Slug, "version": cmd.Result.Version})
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/cloudwatch"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -80,7 +81,10 @@ func getDatasource(id int64, orgId int64) (*m.DataSource, error) {
|
||||
}
|
||||
|
||||
func ProxyDataSourceRequest(c *middleware.Context) {
|
||||
c.TimeRequest(metrics.M_DataSource_ProxyReq_Timer)
|
||||
|
||||
ds, err := getDatasource(c.ParamsInt64(":id"), c.OrgId)
|
||||
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Unable to load datasource meta data", err)
|
||||
return
|
||||
|
||||
+55
-2
@@ -1,10 +1,15 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func GetTestMetrics(c *middleware.Context) {
|
||||
@@ -34,3 +39,51 @@ func GetTestMetrics(c *middleware.Context) {
|
||||
|
||||
c.JSON(200, &result)
|
||||
}
|
||||
|
||||
func GetInternalMetrics(c *middleware.Context) Response {
|
||||
if metrics.UseNilMetrics {
|
||||
return Json(200, util.DynMap{"message": "Metrics disabled"})
|
||||
}
|
||||
|
||||
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],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var b []byte
|
||||
var err error
|
||||
if b, err = json.MarshalIndent(resp, "", " "); err != nil {
|
||||
return ApiError(500, "body json marshal", err)
|
||||
}
|
||||
|
||||
return &NormalResponse{
|
||||
body: b,
|
||||
status: 200,
|
||||
header: http.Header{
|
||||
"Content-Type": []string{"application/json"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
)
|
||||
@@ -42,5 +43,6 @@ func Search(c *middleware.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.TimeRequest(metrics.M_Api_Dashboard_Search)
|
||||
c.JSON(200, searchQuery.Result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user