adds small docs page metrics

This commit is contained in:
bergquist 2017-09-07 17:37:01 +02:00 committed by Carl Bergquist
parent c177a9a77a
commit bf138d1845
3 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,15 @@
+++
title = "Internal metrics"
description = "Internal metrics exposed by Grafana"
keywords = ["grafana", "metrics", "internal metrics"]
type = "docs"
[menu.docs]
parent = "admin"
weight = 8
+++
# Internal metrics
Grafana collects some metrics about it self internally. Currently Grafana supports pushing metrics to graphite and exposing them to be scraped by Prometheus.
To enabled internal metrics you have to enable it under the [metrics] section in your [grafana.ini](http://docs.grafana.org/installation/configuration/#enabled-6) config file.If you want to push metrics to graphite you have also have to configure the [metrics.graphite](http://docs.grafana.org/installation/configuration/#metrics-graphite) section.

86
pkg/api/route_register.go Normal file
View File

@ -0,0 +1,86 @@
package api
import (
"net/http"
macaron "gopkg.in/macaron.v1"
)
type RouteRegister interface {
Get(string, ...macaron.Handler)
Post(string, ...macaron.Handler)
Delete(string, ...macaron.Handler)
Put(string, ...macaron.Handler)
Group(string, func(RouteRegister), ...macaron.Handler)
}
func newRouteRegister(rr *macaron.Router) RouteRegister {
return &routeRegister{
prefix: "",
routes: []route{},
}
}
type route struct {
method string
pattern string
handlers []macaron.Handler
}
type routeRegister struct {
prefix string
subfixHandlers []macaron.Handler
routes []route
}
func (rr *routeRegister) Group(pattern string, fn func(rr RouteRegister), handlers ...macaron.Handler) {
group := &routeRegister{
prefix: rr.prefix + pattern,
subfixHandlers: handlers,
routes: rr.routes,
}
fn(group)
}
func (rr *routeRegister) Get(pattern string, handlers ...macaron.Handler) {
rr.routes = append(rr.routes, route{
method: http.MethodGet,
pattern: rr.prefix + pattern,
handlers: handlers,
})
println("get: get ", len(rr.routes))
rr.routes = rr.routes[:len(rr.routes)-1]
}
func (rr *routeRegister) Post(pattern string, handlers ...macaron.Handler) {
rr.routes = append(rr.routes, route{
method: http.MethodPost,
pattern: rr.prefix + pattern,
handlers: handlers,
})
println("get: post ", len(rr.routes))
rr.routes = rr.routes[:len(rr.routes)-1]
}
func (rr *routeRegister) Delete(pattern string, handlers ...macaron.Handler) {
rr.routes = append(rr.routes, route{
method: http.MethodDelete,
pattern: rr.prefix + pattern,
handlers: handlers,
})
println("get: delete ", len(rr.routes))
rr.routes = rr.routes[:len(rr.routes)-1]
}
func (rr *routeRegister) Put(pattern string, handlers ...macaron.Handler) {
rr.routes = append(rr.routes, route{
method: http.MethodPut,
pattern: rr.prefix + pattern,
handlers: handlers,
})
rr.routes = rr.routes[:len(rr.routes)-1]
}

View File

@ -0,0 +1,39 @@
package api
import "testing"
func TestRouteRegister(t *testing.T) {
rr := &routeRegister{
prefix: "",
routes: []route{},
}
rr.Delete("/admin")
rr.Get("/down")
rr.Group("/user", func(innerRR RouteRegister) {
innerRR.Delete("")
innerRR.Get("/friends")
})
println("len", len(rr.routes))
if rr.routes[0].pattern != "/admin" && rr.routes[0].method != "DELETE" {
t.Errorf("expected first route to be DELETE /admin")
}
if rr.routes[1].pattern != "/down" && rr.routes[1].method != "GET" {
t.Errorf("expected first route to be GET /down")
}
println("len", len(rr.routes))
if rr.routes[2].pattern != "/user" && rr.routes[2].method != "DELETE" {
t.Errorf("expected first route to be DELETE /admin")
}
if rr.routes[3].pattern != "/user/friends" && rr.routes[3].method != "GET" {
t.Errorf("expected first route to be GET /down")
}
}