소스 검색

adds small docs page metrics

bergquist 8 년 전
부모
커밋
bf138d1845
3개의 변경된 파일140개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      docs/sources/administration/metrics.md
  2. 86 0
      pkg/api/route_register.go
  3. 39 0
      pkg/api/route_register_test.go

+ 15 - 0
docs/sources/administration/metrics.md

@@ -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 - 0
pkg/api/route_register.go

@@ -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]
+}

+ 39 - 0
pkg/api/route_register_test.go

@@ -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")
+	}
+}