Sfoglia il codice sorgente

convert old metrics to prom metrics

bergquist 8 anni fa
parent
commit
2de94d6548
37 ha cambiato i file con 283 aggiunte e 489 eliminazioni
  1. 1 1
      pkg/api/admin_users.go
  2. 2 2
      pkg/api/cloudwatch/cloudwatch.go
  3. 1 1
      pkg/api/cloudwatch/metrics.go
  4. 3 3
      pkg/api/dashboard_snapshot.go
  5. 1 1
      pkg/api/login.go
  6. 1 1
      pkg/api/login_oauth.go
  7. 1 1
      pkg/api/org.go
  8. 2 2
      pkg/api/org_invite.go
  9. 2 2
      pkg/api/signup.go
  10. 0 60
      pkg/metrics/common.go
  11. 0 72
      pkg/metrics/counter.go
  12. 0 90
      pkg/metrics/gauge.go
  13. 10 0
      pkg/metrics/graphitepublisher/graphite.go
  14. 8 8
      pkg/metrics/graphitepublisher/graphite_test.go
  15. 223 129
      pkg/metrics/metrics.go
  16. 0 53
      pkg/metrics/timer.go
  17. 3 3
      pkg/middleware/logger.go
  18. 2 2
      pkg/middleware/middleware.go
  19. 12 12
      pkg/middleware/request_metrics.go
  20. 2 2
      pkg/services/alerting/eval_handler.go
  21. 3 0
      pkg/services/alerting/notifier.go
  22. 0 2
      pkg/services/alerting/notifiers/dingding.go
  23. 0 2
      pkg/services/alerting/notifiers/email.go
  24. 2 3
      pkg/services/alerting/notifiers/line.go
  25. 0 2
      pkg/services/alerting/notifiers/opsgenie.go
  26. 0 2
      pkg/services/alerting/notifiers/pagerduty.go
  27. 0 2
      pkg/services/alerting/notifiers/pushover.go
  28. 0 2
      pkg/services/alerting/notifiers/sensu.go
  29. 0 2
      pkg/services/alerting/notifiers/slack.go
  30. 0 2
      pkg/services/alerting/notifiers/telegram.go
  31. 0 2
      pkg/services/alerting/notifiers/threema.go
  32. 0 2
      pkg/services/alerting/notifiers/victorops.go
  33. 0 2
      pkg/services/alerting/notifiers/webhook.go
  34. 1 1
      pkg/services/alerting/reader.go
  35. 1 16
      pkg/services/alerting/result_handler.go
  36. 1 1
      pkg/services/sqlstore/dashboard.go
  37. 1 1
      pkg/services/sqlstore/datasource.go

+ 1 - 1
pkg/api/admin_users.go

@@ -35,7 +35,7 @@ func AdminCreateUser(c *middleware.Context, form dtos.AdminCreateUserForm) {
 		return
 	}
 
-	metrics.M_Api_Admin_User_Create.Inc(1)
+	metrics.M_Api_Admin_User_Create.Inc()
 
 	user := cmd.Result
 

+ 2 - 2
pkg/api/cloudwatch/cloudwatch.go

@@ -266,7 +266,7 @@ func handleGetMetricStatistics(req *cwRequest, c *middleware.Context) {
 		c.JsonApiErr(500, "Unable to call AWS API", err)
 		return
 	}
-	metrics.M_Aws_CloudWatch_GetMetricStatistics.Inc(1)
+	metrics.M_Aws_CloudWatch_GetMetricStatistics.Inc()
 
 	c.JSON(200, resp)
 }
@@ -302,7 +302,7 @@ func handleListMetrics(req *cwRequest, c *middleware.Context) {
 	var resp cloudwatch.ListMetricsOutput
 	err = svc.ListMetricsPages(params,
 		func(page *cloudwatch.ListMetricsOutput, lastPage bool) bool {
-			metrics.M_Aws_CloudWatch_ListMetrics.Inc(1)
+			metrics.M_Aws_CloudWatch_ListMetrics.Inc()
 			metrics, _ := awsutil.ValuesAtPath(page, "Metrics")
 			for _, metric := range metrics {
 				resp.Metrics = append(resp.Metrics, metric.(*cloudwatch.Metric))

+ 1 - 1
pkg/api/cloudwatch/metrics.go

@@ -275,7 +275,7 @@ func getAllMetrics(cwData *datasourceInfo) (cloudwatch.ListMetricsOutput, error)
 	var resp cloudwatch.ListMetricsOutput
 	err = svc.ListMetricsPages(params,
 		func(page *cloudwatch.ListMetricsOutput, lastPage bool) bool {
-			metrics.M_Aws_CloudWatch_ListMetrics.Inc(1)
+			metrics.M_Aws_CloudWatch_ListMetrics.Inc()
 			metrics, _ := awsutil.ValuesAtPath(page, "Metrics")
 			for _, metric := range metrics {
 				resp.Metrics = append(resp.Metrics, metric.(*cloudwatch.Metric))

+ 3 - 3
pkg/api/dashboard_snapshot.go

@@ -34,13 +34,13 @@ func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapsho
 
 		cmd.OrgId = -1
 		cmd.UserId = -1
-		metrics.M_Api_Dashboard_Snapshot_External.Inc(1)
+		metrics.M_Api_Dashboard_Snapshot_External.Inc()
 	} else {
 		cmd.Key = util.GetRandomString(32)
 		cmd.DeleteKey = util.GetRandomString(32)
 		cmd.OrgId = c.OrgId
 		cmd.UserId = c.UserId
-		metrics.M_Api_Dashboard_Snapshot_Create.Inc(1)
+		metrics.M_Api_Dashboard_Snapshot_Create.Inc()
 	}
 
 	if err := bus.Dispatch(&cmd); err != nil {
@@ -84,7 +84,7 @@ func GetDashboardSnapshot(c *middleware.Context) {
 		},
 	}
 
-	metrics.M_Api_Dashboard_Snapshot_Get.Inc(1)
+	metrics.M_Api_Dashboard_Snapshot_Get.Inc()
 
 	c.Resp.Header().Set("Cache-Control", "public, max-age=3600")
 	c.JSON(200, dto)

+ 1 - 1
pkg/api/login.go

@@ -127,7 +127,7 @@ func LoginPost(c *middleware.Context, cmd dtos.LoginCommand) Response {
 		c.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")
 	}
 
-	metrics.M_Api_Login_Post.Inc(1)
+	metrics.M_Api_Login_Post.Inc()
 
 	return Json(200, result)
 }

+ 1 - 1
pkg/api/login_oauth.go

@@ -186,7 +186,7 @@ func OAuthLogin(ctx *middleware.Context) {
 	// login
 	loginUserWithUser(userQuery.Result, ctx)
 
-	metrics.M_Api_Login_OAuth.Inc(1)
+	metrics.M_Api_Login_OAuth.Inc()
 
 	if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
 		ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")

+ 1 - 1
pkg/api/org.go

@@ -89,7 +89,7 @@ func CreateOrg(c *middleware.Context, cmd m.CreateOrgCommand) Response {
 		return ApiError(500, "Failed to create organization", err)
 	}
 
-	metrics.M_Api_Org_Create.Inc(1)
+	metrics.M_Api_Org_Create.Inc()
 
 	return Json(200, &util.DynMap{
 		"orgId":   cmd.Result.Id,

+ 2 - 2
pkg/api/org_invite.go

@@ -187,8 +187,8 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
 
 	loginUserWithUser(user, c)
 
-	metrics.M_Api_User_SignUpCompleted.Inc(1)
-	metrics.M_Api_User_SignUpInvite.Inc(1)
+	metrics.M_Api_User_SignUpCompleted.Inc()
+	metrics.M_Api_User_SignUpInvite.Inc()
 
 	return ApiSuccess("User created and logged in")
 }

+ 2 - 2
pkg/api/signup.go

@@ -47,7 +47,7 @@ func SignUp(c *middleware.Context, form dtos.SignUpForm) Response {
 		Code:  cmd.Code,
 	})
 
-	metrics.M_Api_User_SignUpStarted.Inc(1)
+	metrics.M_Api_User_SignUpStarted.Inc()
 
 	return Json(200, util.DynMap{"status": "SignUpCreated"})
 }
@@ -111,7 +111,7 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
 	}
 
 	loginUserWithUser(user, c)
-	metrics.M_Api_User_SignUpCompleted.Inc(1)
+	metrics.M_Api_User_SignUpCompleted.Inc()
 
 	return Json(200, apiResponse)
 }

+ 0 - 60
pkg/metrics/common.go

@@ -1,60 +0,0 @@
-package metrics
-
-import "github.com/grafana/grafana/pkg/log"
-
-type MetricMeta struct {
-	tags map[string]string
-	name string
-}
-
-func NewMetricMeta(name string, tagStrings []string) *MetricMeta {
-	if len(tagStrings)%2 != 0 {
-		log.Fatal(3, "Metrics: tags array is missing value for key, %v", tagStrings)
-	}
-
-	tags := make(map[string]string)
-	for i := 0; i < len(tagStrings); i += 2 {
-		tags[tagStrings[i]] = tagStrings[i+1]
-	}
-
-	return &MetricMeta{
-		tags: tags,
-		name: name,
-	}
-}
-
-func (m *MetricMeta) Name() string {
-	return m.name
-}
-
-func (m *MetricMeta) GetTagsCopy() map[string]string {
-	if len(m.tags) == 0 {
-		return make(map[string]string)
-	}
-
-	copy := make(map[string]string)
-	for k2, v2 := range m.tags {
-		copy[k2] = v2
-	}
-
-	return copy
-}
-
-func (m *MetricMeta) StringifyTags() string {
-	if len(m.tags) == 0 {
-		return ""
-	}
-
-	str := ""
-	for key, value := range m.tags {
-		str += "." + key + "_" + value
-	}
-
-	return str
-}
-
-type Metric interface {
-	Name() string
-	GetTagsCopy() map[string]string
-	StringifyTags() string
-}

+ 0 - 72
pkg/metrics/counter.go

@@ -1,72 +0,0 @@
-package metrics
-
-import (
-	"strings"
-	"sync/atomic"
-
-	"github.com/prometheus/client_golang/prometheus"
-)
-
-// Counters hold an int64 value that can be incremented and decremented.
-type Counter interface {
-	Metric
-
-	Inc(int64)
-}
-
-func promifyName(name string) string {
-	return strings.Replace(name, ".", "_", -1)
-}
-
-func RegCounter(name string, tagStrings ...string) Counter {
-	meta := NewMetricMeta(name, tagStrings)
-	promCounter := prometheus.NewCounter(prometheus.CounterOpts{
-		Name:        promifyName(meta.Name()) + "_total",
-		Help:        meta.Name(),
-		ConstLabels: prometheus.Labels(meta.GetTagsCopy()),
-	})
-
-	prometheus.MustRegister(promCounter)
-
-	return &StandardCounter{
-		MetricMeta: meta,
-		count:      0,
-		Counter:    promCounter,
-	}
-}
-
-// StandardCounter is the standard implementation of a Counter and uses the
-// sync/atomic package to manage a single int64 value.
-type StandardCounter struct {
-	count int64 //Due to a bug in golang the 64bit variable need to come first to be 64bit aligned. https://golang.org/pkg/sync/atomic/#pkg-note-BUG
-	*MetricMeta
-	prometheus.Counter
-}
-
-// Clear sets the counter to zero.
-func (c *StandardCounter) Clear() {
-	atomic.StoreInt64(&c.count, 0)
-}
-
-// Count returns the current count.
-func (c *StandardCounter) Count() int64 {
-	return atomic.LoadInt64(&c.count)
-}
-
-// Dec decrements the counter by the given amount.
-func (c *StandardCounter) Dec(i int64) {
-	atomic.AddInt64(&c.count, -i)
-}
-
-// Inc increments the counter by the given amount.
-func (c *StandardCounter) Inc(i int64) {
-	atomic.AddInt64(&c.count, i)
-	c.Counter.Add(float64(i))
-}
-
-func (c *StandardCounter) Snapshot() Metric {
-	return &StandardCounter{
-		MetricMeta: c.MetricMeta,
-		count:      c.count,
-	}
-}

+ 0 - 90
pkg/metrics/gauge.go

@@ -1,90 +0,0 @@
-// includes code from
-// https://raw.githubusercontent.com/rcrowley/go-metrics/master/sample.go
-// Copyright 2012 Richard Crowley. All rights reserved.
-
-package metrics
-
-import (
-	"sync/atomic"
-
-	"github.com/prometheus/client_golang/prometheus"
-)
-
-// Gauges hold an int64 value that can be set arbitrarily.
-type Gauge interface {
-	Metric
-
-	Update(int64)
-	Value() int64
-}
-
-func RegGauge(name string, tagStrings ...string) Gauge {
-	meta := NewMetricMeta(name, tagStrings)
-	promGauge := prometheus.NewGauge(prometheus.GaugeOpts{
-		Name:        promifyName(meta.Name()) + "_total",
-		Help:        meta.Name(),
-		ConstLabels: prometheus.Labels(meta.GetTagsCopy()),
-	})
-
-	prometheus.MustRegister(promGauge)
-
-	return &StandardGauge{
-		MetricMeta: meta,
-		value:      0,
-		Gauge:      promGauge,
-	}
-}
-
-// GaugeSnapshot is a read-only copy of another Gauge.
-type GaugeSnapshot struct {
-	value int64
-	*MetricMeta
-}
-
-// Snapshot returns the snapshot.
-func (g GaugeSnapshot) Snapshot() Metric { return g }
-
-// Update panics.
-func (GaugeSnapshot) Update(int64) {
-	panic("Update called on a GaugeSnapshot")
-}
-
-// Value returns the value at the time the snapshot was taken.
-func (g GaugeSnapshot) Value() int64 { return g.value }
-
-// NilGauge is a no-op Gauge.
-type NilGauge struct{ *MetricMeta }
-
-// Snapshot is a no-op.
-func (NilGauge) Snapshot() Metric { return NilGauge{} }
-
-// Update is a no-op.
-func (NilGauge) Update(v int64) {}
-
-// Value is a no-op.
-func (NilGauge) Value() int64 { return 0 }
-
-// StandardGauge is the standard implementation of a Gauge and uses the
-// sync/atomic package to manage a single int64 value.
-// atomic needs 64-bit aligned memory which is ensure for first word
-type StandardGauge struct {
-	value int64
-	*MetricMeta
-	prometheus.Gauge
-}
-
-// Snapshot returns a read-only copy of the gauge.
-func (g *StandardGauge) Snapshot() Metric {
-	return GaugeSnapshot{MetricMeta: g.MetricMeta, value: g.value}
-}
-
-// Update updates the gauge's value.
-func (g *StandardGauge) Update(v int64) {
-	atomic.StoreInt64(&g.value, v)
-	g.Gauge.Set(float64(v))
-}
-
-// Value returns the gauge's current value.
-func (g *StandardGauge) Value() int64 {
-	return atomic.LoadInt64(&g.value)
-}

+ 10 - 0
pkg/metrics/graphitepublisher/graphite.go

@@ -22,6 +22,7 @@ import (
 	"io"
 	"net"
 	"sort"
+	"strings"
 	"time"
 
 	"github.com/prometheus/common/expfmt"
@@ -52,6 +53,9 @@ const (
 	AbortOnError
 )
 
+var metricCategoryPrefix []string = []string{"proxy_", "api_", "page_", "alerting_", "aws_", "db_", "stat_", "go_", "process_"}
+var ignorePrefix []string = []string{"http_"}
+
 // Config defines the Graphite bridge config.
 type Config struct {
 	// The url to push data to. Required.
@@ -234,6 +238,12 @@ func writeMetric(buf *bufio.Writer, m model.Metric, mf *dto.MetricFamily) error
 	if !hasName {
 		numLabels = len(m)
 	}
+	for _, v := range metricCategoryPrefix {
+		if strings.HasPrefix(string(metricName), v) {
+			group := strings.Replace(v, "_", " ", 1)
+			metricName = model.LabelValue(strings.Replace(string(metricName), v, group, -1))
+		}
+	}
 
 	labelStrings := make([]string, 0, numLabels)
 	for label, value := range m {

+ 8 - 8
pkg/metrics/graphitepublisher/graphite_test.go

@@ -220,7 +220,7 @@ prefix.name_bucket.constname.constvalue.labelname.val2.le._Inf 3 1477043
 func TestCounterVec(t *testing.T) {
 	cntVec := prometheus.NewCounterVec(
 		prometheus.CounterOpts{
-			Name:        "name",
+			Name:        "page_response",
 			Help:        "docstring",
 			ConstLabels: prometheus.Labels{"constname": "constvalue"},
 		},
@@ -254,8 +254,8 @@ func TestCounterVec(t *testing.T) {
 		t.Fatalf("error: %v", err)
 	}
 
-	want := `prefix.name.constname.constvalue.labelname.val1.count 1 1477043
-prefix.name.constname.constvalue.labelname.val2.count 1 1477043
+	want := `prefix.page.response.constname.constvalue.labelname.val1.count 1 1477043
+prefix.page.response.constname.constvalue.labelname.val2.count 1 1477043
 `
 	if got := buf.String(); want != got {
 		t.Fatalf("wanted \n%s\n, got \n%s\n", want, got)
@@ -276,8 +276,8 @@ prefix.name.constname.constvalue.labelname.val2.count 1 1477043
 		t.Fatalf("error: %v", err)
 	}
 
-	want2 := `prefix.name.constname.constvalue.labelname.val1.count 1 1477053
-prefix.name.constname.constvalue.labelname.val2.count 1 1477053
+	want2 := `prefix.page.response.constname.constvalue.labelname.val1.count 1 1477053
+prefix.page.response.constname.constvalue.labelname.val2.count 1 1477053
 `
 	if got := buf.String(); want2 != got {
 		t.Fatalf("wanted \n%s\n, got \n%s\n", want2, got)
@@ -287,7 +287,7 @@ prefix.name.constname.constvalue.labelname.val2.count 1 1477053
 func TestCounter(t *testing.T) {
 	cntVec := prometheus.NewCounter(
 		prometheus.CounterOpts{
-			Name:        "name",
+			Name:        "page_response",
 			Help:        "docstring",
 			ConstLabels: prometheus.Labels{"constname": "constvalue"},
 		})
@@ -318,7 +318,7 @@ func TestCounter(t *testing.T) {
 		t.Fatalf("error: %v", err)
 	}
 
-	want := "prefix.name.constname.constvalue.count 1 1477043\n"
+	want := "prefix.page.response.constname.constvalue.count 1 1477043\n"
 	if got := buf.String(); want != got {
 		t.Fatalf("wanted \n%s\n, got \n%s\n", want, got)
 	}
@@ -337,7 +337,7 @@ func TestCounter(t *testing.T) {
 		t.Fatalf("error: %v", err)
 	}
 
-	want2 := "prefix.name.constname.constvalue.count 1 1477053\n"
+	want2 := "prefix.page.response.constname.constvalue.count 1 1477053\n"
 	if got := buf.String(); want2 != got {
 		t.Fatalf("wanted \n%s\n, got \n%s\n", want2, got)
 	}

+ 223 - 129
pkg/metrics/metrics.go

@@ -12,146 +12,240 @@ import (
 	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/plugins"
 	"github.com/grafana/grafana/pkg/setting"
+	"github.com/prometheus/client_golang/prometheus"
 )
 
 var (
-	M_Instance_Start                       Counter
-	M_Page_Status_200                      Counter
-	M_Page_Status_500                      Counter
-	M_Page_Status_404                      Counter
-	M_Page_Status_Unknown                  Counter
-	M_Api_Status_200                       Counter
-	M_Api_Status_404                       Counter
-	M_Api_Status_500                       Counter
-	M_Api_Status_Unknown                   Counter
-	M_Proxy_Status_200                     Counter
-	M_Proxy_Status_404                     Counter
-	M_Proxy_Status_500                     Counter
-	M_Proxy_Status_Unknown                 Counter
-	M_Api_User_SignUpStarted               Counter
-	M_Api_User_SignUpCompleted             Counter
-	M_Api_User_SignUpInvite                Counter
-	M_Api_Dashboard_Save                   Timer
-	M_Api_Dashboard_Get                    Timer
-	M_Api_Dashboard_Search                 Timer
-	M_Api_Admin_User_Create                Counter
-	M_Api_Login_Post                       Counter
-	M_Api_Login_OAuth                      Counter
-	M_Api_Org_Create                       Counter
-	M_Api_Dashboard_Snapshot_Create        Counter
-	M_Api_Dashboard_Snapshot_External      Counter
-	M_Api_Dashboard_Snapshot_Get           Counter
-	M_Models_Dashboard_Insert              Counter
-	M_Alerting_Result_State_Alerting       Counter
-	M_Alerting_Result_State_Ok             Counter
-	M_Alerting_Result_State_Paused         Counter
-	M_Alerting_Result_State_NoData         Counter
-	M_Alerting_Result_State_Pending        Counter
-	M_Alerting_Notification_Sent_Slack     Counter
-	M_Alerting_Notification_Sent_Email     Counter
-	M_Alerting_Notification_Sent_Webhook   Counter
-	M_Alerting_Notification_Sent_DingDing  Counter
-	M_Alerting_Notification_Sent_PagerDuty Counter
-	M_Alerting_Notification_Sent_LINE      Counter
-	M_Alerting_Notification_Sent_Victorops Counter
-	M_Alerting_Notification_Sent_OpsGenie  Counter
-	M_Alerting_Notification_Sent_Telegram  Counter
-	M_Alerting_Notification_Sent_Threema   Counter
-	M_Alerting_Notification_Sent_Sensu     Counter
-	M_Alerting_Notification_Sent_Pushover  Counter
-	M_Aws_CloudWatch_GetMetricStatistics   Counter
-	M_Aws_CloudWatch_ListMetrics           Counter
-	M_DB_DataSource_QueryById              Counter
+	M_Instance_Start prometheus.Counter
+	M_Page_Status    *prometheus.CounterVec
+	M_Api_Status     *prometheus.CounterVec
+	M_Proxy_Status   *prometheus.CounterVec
+
+	M_Api_User_SignUpStarted   prometheus.Counter
+	M_Api_User_SignUpCompleted prometheus.Counter
+	M_Api_User_SignUpInvite    prometheus.Counter
+	M_Api_Dashboard_Save       prometheus.Summary
+	M_Api_Dashboard_Get        prometheus.Summary
+	M_Api_Dashboard_Search     prometheus.Summary
+	M_Api_Admin_User_Create    prometheus.Counter
+	M_Api_Login_Post           prometheus.Counter
+	M_Api_Login_OAuth          prometheus.Counter
+	M_Api_Org_Create           prometheus.Counter
+
+	M_Api_Dashboard_Snapshot_Create      prometheus.Counter
+	M_Api_Dashboard_Snapshot_External    prometheus.Counter
+	M_Api_Dashboard_Snapshot_Get         prometheus.Counter
+	M_Api_Dashboard_Insert               prometheus.Counter
+	M_Alerting_Result_State              *prometheus.CounterVec
+	M_Alerting_Notification_Sent         *prometheus.CounterVec
+	M_Aws_CloudWatch_GetMetricStatistics prometheus.Counter
+	M_Aws_CloudWatch_ListMetrics         prometheus.Counter
+	M_DB_DataSource_QueryById            prometheus.Counter
 
 	// Timers
-	M_DataSource_ProxyReq_Timer Timer
-	M_Alerting_Execution_Time   Timer
+	M_DataSource_ProxyReq_Timer prometheus.Summary
+	M_Alerting_Execution_Time   prometheus.Summary
 
 	// StatTotals
-	M_Alerting_Active_Alerts Gauge
-	M_StatTotal_Dashboards   Gauge
-	M_StatTotal_Users        Gauge
-	M_StatTotal_Orgs         Gauge
-	M_StatTotal_Playlists    Gauge
+	M_Alerting_Active_Alerts prometheus.Gauge
+	M_StatTotal_Dashboards   prometheus.Gauge
+	M_StatTotal_Users        prometheus.Gauge
+	M_StatTotal_Orgs         prometheus.Gauge
+	M_StatTotal_Playlists    prometheus.Gauge
 )
 
-func initMetricVars(settings *MetricSettings) {
-	M_Instance_Start = RegCounter("instance_start")
-
-	M_Page_Status_200 = RegCounter("page.resp_status", "code", "200")
-	M_Page_Status_500 = RegCounter("page.resp_status", "code", "500")
-	M_Page_Status_404 = RegCounter("page.resp_status", "code", "404")
-	M_Page_Status_Unknown = RegCounter("page.resp_status", "code", "unknown")
-
-	M_Api_Status_200 = RegCounter("api.resp_status", "code", "200")
-	M_Api_Status_404 = RegCounter("api.resp_status", "code", "404")
-	M_Api_Status_500 = RegCounter("api.resp_status", "code", "500")
-	M_Api_Status_Unknown = RegCounter("api.resp_status", "code", "unknown")
-
-	M_Proxy_Status_200 = RegCounter("proxy.resp_status", "code", "200")
-	M_Proxy_Status_404 = RegCounter("proxy.resp_status", "code", "404")
-	M_Proxy_Status_500 = RegCounter("proxy.resp_status", "code", "500")
-	M_Proxy_Status_Unknown = RegCounter("proxy.resp_status", "code", "unknown")
-
-	M_Api_User_SignUpStarted = RegCounter("api.user.signup_started")
-	M_Api_User_SignUpCompleted = RegCounter("api.user.signup_completed")
-	M_Api_User_SignUpInvite = RegCounter("api.user.signup_invite")
-
-	M_Api_Dashboard_Save = RegTimer("api.dashboard.save")
-	M_Api_Dashboard_Get = RegTimer("api.dashboard.get")
-	M_Api_Dashboard_Search = RegTimer("api.dashboard.search")
-
-	M_Api_Admin_User_Create = RegCounter("api.admin.user_create")
-	M_Api_Login_Post = RegCounter("api.login.post")
-	M_Api_Login_OAuth = RegCounter("api.login.oauth")
-	M_Api_Org_Create = RegCounter("api.org.create")
-
-	M_Api_Dashboard_Snapshot_Create = RegCounter("api.dashboard_snapshot.create")
-	M_Api_Dashboard_Snapshot_External = RegCounter("api.dashboard_snapshot.external")
-	M_Api_Dashboard_Snapshot_Get = RegCounter("api.dashboard_snapshot.get")
-
-	M_Models_Dashboard_Insert = RegCounter("models.dashboard.insert")
-
-	M_Alerting_Result_State_Alerting = RegCounter("alerting.result", "state", "alerting")
-	M_Alerting_Result_State_Ok = RegCounter("alerting.result", "state", "ok")
-	M_Alerting_Result_State_Paused = RegCounter("alerting.result", "state", "paused")
-	M_Alerting_Result_State_NoData = RegCounter("alerting.result", "state", "no_data")
-	M_Alerting_Result_State_Pending = RegCounter("alerting.result", "state", "pending")
-
-	M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifications_sent", "type", "slack")
-	M_Alerting_Notification_Sent_Email = RegCounter("alerting.notifications_sent", "type", "email")
-	M_Alerting_Notification_Sent_Webhook = RegCounter("alerting.notifications_sent", "type", "webhook")
-	M_Alerting_Notification_Sent_DingDing = RegCounter("alerting.notifications_sent", "type", "dingding")
-	M_Alerting_Notification_Sent_PagerDuty = RegCounter("alerting.notifications_sent", "type", "pagerduty")
-	M_Alerting_Notification_Sent_Victorops = RegCounter("alerting.notifications_sent", "type", "victorops")
-	M_Alerting_Notification_Sent_OpsGenie = RegCounter("alerting.notifications_sent", "type", "opsgenie")
-	M_Alerting_Notification_Sent_Telegram = RegCounter("alerting.notifications_sent", "type", "telegram")
-	M_Alerting_Notification_Sent_Threema = RegCounter("alerting.notifications_sent", "type", "threema")
-	M_Alerting_Notification_Sent_Sensu = RegCounter("alerting.notifications_sent", "type", "sensu")
-	M_Alerting_Notification_Sent_LINE = RegCounter("alerting.notifications_sent", "type", "LINE")
-	M_Alerting_Notification_Sent_Pushover = RegCounter("alerting.notifications_sent", "type", "pushover")
-
-	M_Aws_CloudWatch_GetMetricStatistics = RegCounter("aws.cloudwatch.get_metric_statistics")
-	M_Aws_CloudWatch_ListMetrics = RegCounter("aws.cloudwatch.list_metrics")
-
-	M_DB_DataSource_QueryById = RegCounter("db.datasource.query_by_id")
-
-	// Timers
-	M_DataSource_ProxyReq_Timer = RegTimer("api.dataproxy.request.all")
-	M_Alerting_Execution_Time = RegTimer("alerting.execution_time")
+func init() {
+	M_Instance_Start = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "instance_start_total",
+		Help: "counter for started instances",
+	})
+
+	M_Page_Status = prometheus.NewCounterVec(
+		prometheus.CounterOpts{
+			Name: "page_response_status_total",
+			Help: "page http response status",
+		},
+		[]string{"code"},
+	)
+
+	M_Api_Status = prometheus.NewCounterVec(
+		prometheus.CounterOpts{
+			Name: "api_response_status_total",
+			Help: "api http response status",
+		},
+		[]string{"code"},
+	)
+
+	M_Proxy_Status = prometheus.NewCounterVec(
+		prometheus.CounterOpts{
+			Name: "proxy_response_status_total",
+			Help: "proxy http response status",
+		},
+		[]string{"code"},
+	)
+
+	M_Api_User_SignUpStarted = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_user_signup_started_total",
+		Help: "amount of users who started the signup flow",
+	})
+
+	M_Api_User_SignUpCompleted = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_user_signup_completed_total",
+		Help: "amount of users who completed the signup flow",
+	})
+
+	M_Api_User_SignUpInvite = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_user_signup_invite_total",
+		Help: "amount of users who have been invited",
+	})
+
+	M_Api_Dashboard_Save = prometheus.NewSummary(prometheus.SummaryOpts{
+		Name: "api_dashboard_save",
+		Help: "summary for dashboard save duration",
+	})
+
+	M_Api_Dashboard_Get = prometheus.NewSummary(prometheus.SummaryOpts{
+		Name: "api_dashboard_get",
+		Help: "summary for dashboard get duration",
+	})
+
+	M_Api_Dashboard_Search = prometheus.NewSummary(prometheus.SummaryOpts{
+		Name: "api_dashboard_search",
+		Help: "summary for dashboard search duration",
+	})
+
+	M_Api_Admin_User_Create = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_admin_user_created_total",
+		Help: "api admin user created counter",
+	})
+	M_Api_Login_Post = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_login_post_total",
+		Help: "api login post counter",
+	})
+	M_Api_Login_OAuth = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_login_oauth_total",
+		Help: "api login oauth counter",
+	})
+	M_Api_Org_Create = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_org_create_total",
+		Help: "api org created counter",
+	})
+
+	M_Api_Dashboard_Snapshot_Create = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_dashboard_snapshot_create_total",
+		Help: "dashboard snapshots created",
+	})
+	M_Api_Dashboard_Snapshot_External = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_dashboard_snapshot_external_total",
+		Help: "external dashboard snapshots created",
+	})
+	M_Api_Dashboard_Snapshot_Get = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_dashboard_snapshot_get_total",
+		Help: "loaded dashboards",
+	})
+
+	M_Api_Dashboard_Insert = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "api_models_dashboard_insert_total",
+		Help: "dashboards inserted ",
+	})
+
+	M_Alerting_Result_State = prometheus.NewCounterVec(prometheus.CounterOpts{
+		Name: "alerting_result_total",
+		Help: "alert execution result counter",
+	}, []string{"state"})
+
+	M_Alerting_Notification_Sent = prometheus.NewCounterVec(prometheus.CounterOpts{
+		Name: "alerting_notification_sent_total",
+		Help: "counter for how many alert notifications been sent",
+	}, []string{"type"})
+
+	M_Aws_CloudWatch_GetMetricStatistics = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "aws_cloudwatch_get_metric_statistics_total",
+		Help: "counter for getting metric statistics from aws",
+	})
+
+	M_Aws_CloudWatch_ListMetrics = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "aws_cloudwatch_list_metrics_total",
+		Help: "counter for getting list of metrics from aws",
+	})
+
+	M_DB_DataSource_QueryById = prometheus.NewCounter(prometheus.CounterOpts{
+		Name: "db_datasource_query_by_id_total",
+		Help: "counter for getting datasource by id",
+	})
+
+	M_DataSource_ProxyReq_Timer = prometheus.NewSummary(prometheus.SummaryOpts{
+		Name: "api_dataproxy_request_all",
+		Help: "summary for dashboard search duration",
+	})
+	M_Alerting_Execution_Time = prometheus.NewSummary(prometheus.SummaryOpts{
+		Name: "alerting_execution_time_seconds",
+		Help: "summary of alert exeuction duration",
+	})
+
+	M_Alerting_Active_Alerts = prometheus.NewGauge(prometheus.GaugeOpts{
+		Name: "alerting_active_alerts",
+		Help: "amount of active alerts",
+	})
+
+	M_StatTotal_Dashboards = prometheus.NewGauge(prometheus.GaugeOpts{
+		Name: "stat_totals_dashboard",
+		Help: "total amount of dashboards",
+	})
+
+	M_StatTotal_Users = prometheus.NewGauge(prometheus.GaugeOpts{
+		Name: "stat_total_users",
+		Help: "total amount of users",
+	})
+
+	M_StatTotal_Orgs = prometheus.NewGauge(prometheus.GaugeOpts{
+		Name: "stat_total_orgs",
+		Help: "total amount of orgs",
+	})
+
+	M_StatTotal_Playlists = prometheus.NewGauge(prometheus.GaugeOpts{
+		Name: "stat_total_playlists",
+		Help: "total amount of playlists",
+	})
+}
 
-	// StatTotals
-	M_Alerting_Active_Alerts = RegGauge("alerting.active_alerts")
-	M_StatTotal_Dashboards = RegGauge("stat_totals", "stat", "dashboards")
-	M_StatTotal_Users = RegGauge("stat_totals", "stat", "users")
-	M_StatTotal_Orgs = RegGauge("stat_totals", "stat", "orgs")
-	M_StatTotal_Playlists = RegGauge("stat_totals", "stat", "playlists")
+func initMetricVars(settings *MetricSettings) {
+	prometheus.MustRegister(
+		M_Instance_Start,
+		M_Page_Status,
+		M_Api_Status,
+		M_Api_User_SignUpStarted,
+		M_Api_User_SignUpCompleted,
+		M_Api_User_SignUpInvite,
+		M_Api_Dashboard_Save,
+		M_Api_Dashboard_Get,
+		M_Api_Dashboard_Search,
+		M_DataSource_ProxyReq_Timer,
+		M_Alerting_Execution_Time,
+		M_Api_Admin_User_Create,
+		M_Api_Login_Post,
+		M_Api_Login_OAuth,
+		M_Api_Org_Create,
+		M_Api_Dashboard_Snapshot_Create,
+		M_Api_Dashboard_Snapshot_External,
+		M_Api_Dashboard_Snapshot_Get,
+		M_Api_Dashboard_Insert,
+		M_Alerting_Result_State,
+		M_Alerting_Notification_Sent,
+		M_Aws_CloudWatch_GetMetricStatistics,
+		M_Aws_CloudWatch_ListMetrics,
+		M_DB_DataSource_QueryById,
+		M_Alerting_Active_Alerts,
+		M_StatTotal_Dashboards,
+		M_StatTotal_Users,
+		M_StatTotal_Orgs,
+		M_StatTotal_Playlists)
 
 	go instrumentationLoop(settings)
 }
 
 func instrumentationLoop(settings *MetricSettings) chan struct{} {
-	M_Instance_Start.Inc(1)
+	M_Instance_Start.Inc()
 
 	onceEveryDayTick := time.NewTicker(time.Hour * 24)
 	secondTicker := time.NewTicker(time.Second * time.Duration(settings.IntervalSeconds))
@@ -177,10 +271,10 @@ func updateTotalStats() {
 			return
 		}
 
-		M_StatTotal_Dashboards.Update(statsQuery.Result.Dashboards)
-		M_StatTotal_Users.Update(statsQuery.Result.Users)
-		M_StatTotal_Playlists.Update(statsQuery.Result.Playlists)
-		M_StatTotal_Orgs.Update(statsQuery.Result.Orgs)
+		M_StatTotal_Dashboards.Set(float64(statsQuery.Result.Dashboards))
+		M_StatTotal_Users.Set(float64(statsQuery.Result.Users))
+		M_StatTotal_Playlists.Set(float64(statsQuery.Result.Playlists))
+		M_StatTotal_Orgs.Set(float64(statsQuery.Result.Orgs))
 	}
 }
 

+ 0 - 53
pkg/metrics/timer.go

@@ -1,53 +0,0 @@
-// includes code from
-// https://raw.githubusercontent.com/rcrowley/go-metrics/master/sample.go
-// Copyright 2012 Richard Crowley. All rights reserved.
-
-package metrics
-
-import (
-	"time"
-
-	"github.com/prometheus/client_golang/prometheus"
-)
-
-// Timers capture the duration and rate of events.
-type Timer interface {
-	Metric
-
-	Update(time.Duration)
-	UpdateSince(time.Time)
-}
-
-func RegTimer(name string, tagStrings ...string) Timer {
-	meta := NewMetricMeta(name, tagStrings)
-	promSummary := prometheus.NewSummary(prometheus.SummaryOpts{
-		Name:        promifyName(meta.Name()),
-		Help:        meta.Name(),
-		ConstLabels: prometheus.Labels(meta.GetTagsCopy()),
-	})
-
-	prometheus.MustRegister(promSummary)
-
-	return &StandardTimer{
-		MetricMeta: meta,
-		Summary:    promSummary,
-	}
-}
-
-// StandardTimer is the standard implementation of a Timer and uses a Histogram
-// and Meter.
-type StandardTimer struct {
-	*MetricMeta
-
-	prometheus.Summary
-}
-
-// Record the duration of an event.
-func (t *StandardTimer) Update(d time.Duration) {
-	t.Summary.Observe(float64(d))
-}
-
-// Record the duration of an event that started at a time and ends now.
-func (t *StandardTimer) UpdateSince(ts time.Time) {
-	t.Summary.Observe(float64(time.Since(ts) / time.Millisecond))
-}

+ 3 - 3
pkg/middleware/logger.go

@@ -19,8 +19,8 @@ import (
 	"net/http"
 	"time"
 
-	"github.com/grafana/grafana/pkg/metrics"
 	"github.com/grafana/grafana/pkg/setting"
+	"github.com/prometheus/client_golang/prometheus"
 	"gopkg.in/macaron.v1"
 )
 
@@ -35,8 +35,8 @@ func Logger() macaron.Handler {
 		timeTakenMs := time.Since(start) / time.Millisecond
 
 		if timer, ok := c.Data["perfmon.timer"]; ok {
-			timerTyped := timer.(metrics.Timer)
-			timerTyped.Update(timeTakenMs)
+			timerTyped := timer.(prometheus.Summary)
+			timerTyped.Observe(float64(timeTakenMs))
 		}
 
 		status := rw.Status()

+ 2 - 2
pkg/middleware/middleware.go

@@ -10,10 +10,10 @@ import (
 	"github.com/grafana/grafana/pkg/components/apikeygen"
 	"github.com/grafana/grafana/pkg/log"
 	l "github.com/grafana/grafana/pkg/login"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/util"
+	"github.com/prometheus/client_golang/prometheus"
 )
 
 type Context struct {
@@ -251,7 +251,7 @@ func (ctx *Context) HasHelpFlag(flag m.HelpFlags1) bool {
 	return ctx.HelpFlags1.HasFlag(flag)
 }
 
-func (ctx *Context) TimeRequest(timer metrics.Timer) {
+func (ctx *Context) TimeRequest(timer prometheus.Summary) {
 	ctx.Data["perfmon.timer"] = timer
 }
 

+ 12 - 12
pkg/middleware/request_metrics.go

@@ -28,38 +28,38 @@ func RequestMetrics() macaron.Handler {
 func countApiRequests(status int) {
 	switch status {
 	case 200:
-		metrics.M_Api_Status_200.Inc(1)
+		metrics.M_Api_Status.WithLabelValues("200").Inc()
 	case 404:
-		metrics.M_Api_Status_404.Inc(1)
+		metrics.M_Api_Status.WithLabelValues("404").Inc()
 	case 500:
-		metrics.M_Api_Status_500.Inc(1)
+		metrics.M_Api_Status.WithLabelValues("500").Inc()
 	default:
-		metrics.M_Api_Status_Unknown.Inc(1)
+		metrics.M_Api_Status.WithLabelValues("unknown").Inc()
 	}
 }
 
 func countPageRequests(status int) {
 	switch status {
 	case 200:
-		metrics.M_Page_Status_200.Inc(1)
+		metrics.M_Page_Status.WithLabelValues("200").Inc()
 	case 404:
-		metrics.M_Page_Status_404.Inc(1)
+		metrics.M_Page_Status.WithLabelValues("404").Inc()
 	case 500:
-		metrics.M_Page_Status_500.Inc(1)
+		metrics.M_Page_Status.WithLabelValues("500").Inc()
 	default:
-		metrics.M_Page_Status_Unknown.Inc(1)
+		metrics.M_Page_Status.WithLabelValues("unknown").Inc()
 	}
 }
 
 func countProxyRequests(status int) {
 	switch status {
 	case 200:
-		metrics.M_Proxy_Status_200.Inc(1)
+		metrics.M_Proxy_Status.WithLabelValues("200").Inc()
 	case 404:
-		metrics.M_Proxy_Status_404.Inc(1)
+		metrics.M_Proxy_Status.WithLabelValues("400").Inc()
 	case 500:
-		metrics.M_Proxy_Status_500.Inc(1)
+		metrics.M_Proxy_Status.WithLabelValues("500").Inc()
 	default:
-		metrics.M_Proxy_Status_Unknown.Inc(1)
+		metrics.M_Proxy_Status.WithLabelValues("unknown").Inc()
 	}
 }

+ 2 - 2
pkg/services/alerting/eval_handler.go

@@ -63,8 +63,8 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
 	context.EndTime = time.Now()
 	context.Rule.State = e.getNewState(context)
 
-	elapsedTime := context.EndTime.Sub(context.StartTime) / time.Millisecond
-	metrics.M_Alerting_Execution_Time.Update(elapsedTime)
+	elapsedTime := context.EndTime.Sub(context.StartTime).Seconds()
+	metrics.M_Alerting_Execution_Time.Observe(elapsedTime)
 }
 
 // This should be move into evalContext once its been refactored.

+ 3 - 0
pkg/services/alerting/notifier.go

@@ -10,6 +10,8 @@ import (
 	"github.com/grafana/grafana/pkg/components/imguploader"
 	"github.com/grafana/grafana/pkg/components/renderer"
 	"github.com/grafana/grafana/pkg/log"
+	"github.com/grafana/grafana/pkg/metrics"
+
 	m "github.com/grafana/grafana/pkg/models"
 )
 
@@ -66,6 +68,7 @@ func (n *notificationService) sendNotifications(context *EvalContext, notifiers
 	for _, notifier := range notifiers {
 		not := notifier //avoid updating scope variable in go routine
 		n.log.Info("Sending notification", "type", not.GetType(), "id", not.GetNotifierId(), "isDefault", not.GetIsDefault())
+		metrics.M_Alerting_Notification_Sent.WithLabelValues(not.GetType()).Inc()
 		g.Go(func() error { return not.Notify(context) })
 	}
 

+ 0 - 2
pkg/services/alerting/notifiers/dingding.go

@@ -4,7 +4,6 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -47,7 +46,6 @@ type DingDingNotifier struct {
 
 func (this *DingDingNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Sending dingding")
-	metrics.M_Alerting_Notification_Sent_DingDing.Inc(1)
 
 	messageUrl, err := evalContext.GetRuleUrl()
 	if err != nil {

+ 0 - 2
pkg/services/alerting/notifiers/email.go

@@ -6,7 +6,6 @@ import (
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/setting"
@@ -61,7 +60,6 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
 
 func (this *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Sending alert notification to", "addresses", this.Addresses)
-	metrics.M_Alerting_Notification_Sent_Email.Inc(1)
 
 	ruleUrl, err := evalContext.GetRuleUrl()
 	if err != nil {

+ 2 - 3
pkg/services/alerting/notifiers/line.go

@@ -2,12 +2,12 @@ package notifiers
 
 import (
 	"fmt"
+	"net/url"
+
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
-	"net/url"
 )
 
 func init() {
@@ -53,7 +53,6 @@ type LineNotifier struct {
 
 func (this *LineNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Executing line notification", "ruleId", evalContext.Rule.Id, "notification", this.Name)
-	metrics.M_Alerting_Notification_Sent_LINE.Inc(1)
 
 	var err error
 	switch evalContext.Rule.State {

+ 0 - 2
pkg/services/alerting/notifiers/opsgenie.go

@@ -7,7 +7,6 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -65,7 +64,6 @@ type OpsGenieNotifier struct {
 }
 
 func (this *OpsGenieNotifier) Notify(evalContext *alerting.EvalContext) error {
-	metrics.M_Alerting_Notification_Sent_OpsGenie.Inc(1)
 
 	var err error
 	switch evalContext.Rule.State {

+ 0 - 2
pkg/services/alerting/notifiers/pagerduty.go

@@ -6,7 +6,6 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -63,7 +62,6 @@ type PagerdutyNotifier struct {
 }
 
 func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
-	metrics.M_Alerting_Notification_Sent_PagerDuty.Inc(1)
 
 	if evalContext.Rule.State == m.AlertStateOK && !this.AutoResolve {
 		this.log.Info("Not sending a trigger to Pagerduty", "state", evalContext.Rule.State, "auto resolve", this.AutoResolve)

+ 0 - 2
pkg/services/alerting/notifiers/pushover.go

@@ -7,7 +7,6 @@ import (
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -125,7 +124,6 @@ type PushoverNotifier struct {
 }
 
 func (this *PushoverNotifier) Notify(evalContext *alerting.EvalContext) error {
-	metrics.M_Alerting_Notification_Sent_Pushover.Inc(1)
 	ruleUrl, err := evalContext.GetRuleUrl()
 	if err != nil {
 		this.log.Error("Failed get rule link", "error", err)

+ 0 - 2
pkg/services/alerting/notifiers/sensu.go

@@ -7,7 +7,6 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -74,7 +73,6 @@ type SensuNotifier struct {
 
 func (this *SensuNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Sending sensu result")
-	metrics.M_Alerting_Notification_Sent_Sensu.Inc(1)
 
 	bodyJSON := simplejson.New()
 	bodyJSON.Set("ruleId", evalContext.Rule.Id)

+ 0 - 2
pkg/services/alerting/notifiers/slack.go

@@ -6,7 +6,6 @@ import (
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/setting"
@@ -79,7 +78,6 @@ type SlackNotifier struct {
 
 func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Executing slack notification", "ruleId", evalContext.Rule.Id, "notification", this.Name)
-	metrics.M_Alerting_Notification_Sent_Slack.Inc(1)
 
 	ruleUrl, err := evalContext.GetRuleUrl()
 	if err != nil {

+ 0 - 2
pkg/services/alerting/notifiers/telegram.go

@@ -6,7 +6,6 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -80,7 +79,6 @@ func NewTelegramNotifier(model *m.AlertNotification) (alerting.Notifier, error)
 func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Sending alert notification to", "bot_token", this.BotToken)
 	this.log.Info("Sending alert notification to", "chat_id", this.ChatID)
-	metrics.M_Alerting_Notification_Sent_Telegram.Inc(1)
 
 	bodyJSON := simplejson.New()
 

+ 0 - 2
pkg/services/alerting/notifiers/threema.go

@@ -7,7 +7,6 @@ import (
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -118,7 +117,6 @@ func NewThreemaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
 func (notifier *ThreemaNotifier) Notify(evalContext *alerting.EvalContext) error {
 	notifier.log.Info("Sending alert notification from", "threema_id", notifier.GatewayID)
 	notifier.log.Info("Sending alert notification to", "threema_id", notifier.RecipientID)
-	metrics.M_Alerting_Notification_Sent_Threema.Inc(1)
 
 	// Set up basic API request data
 	data := url.Values{}

+ 0 - 2
pkg/services/alerting/notifiers/victorops.go

@@ -6,7 +6,6 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/setting"
@@ -72,7 +71,6 @@ type VictoropsNotifier struct {
 // Notify sends notification to Victorops via POST to URL endpoint
 func (this *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Executing victorops notification", "ruleId", evalContext.Rule.Id, "notification", this.Name)
-	metrics.M_Alerting_Notification_Sent_Victorops.Inc(1)
 
 	ruleUrl, err := evalContext.GetRuleUrl()
 	if err != nil {

+ 0 - 2
pkg/services/alerting/notifiers/webhook.go

@@ -4,7 +4,6 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/log"
-	"github.com/grafana/grafana/pkg/metrics"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
@@ -68,7 +67,6 @@ type WebhookNotifier struct {
 
 func (this *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
 	this.log.Info("Sending webhook")
-	metrics.M_Alerting_Notification_Sent_Webhook.Inc(1)
 
 	bodyJSON := simplejson.New()
 	bodyJSON.Set("title", evalContext.GetNotificationTitle())

+ 1 - 1
pkg/services/alerting/reader.go

@@ -59,7 +59,7 @@ func (arr *DefaultRuleReader) Fetch() []*Rule {
 		}
 	}
 
-	metrics.M_Alerting_Active_Alerts.Update(int64(len(res)))
+	metrics.M_Alerting_Active_Alerts.Set(float64(len(res)))
 	return res
 }
 

+ 1 - 16
pkg/services/alerting/result_handler.go

@@ -42,7 +42,7 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
 		annotationData.Set("noData", true)
 	}
 
-	countStateResult(evalContext.Rule.State)
+	metrics.M_Alerting_Result_State.WithLabelValues(string(evalContext.Rule.State)).Inc()
 	if evalContext.ShouldUpdateAlertState() {
 		handler.log.Info("New state change", "alertId", evalContext.Rule.Id, "newState", evalContext.Rule.State, "prev state", evalContext.PrevAlertState)
 
@@ -95,18 +95,3 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
 
 	return nil
 }
-
-func countStateResult(state m.AlertStateType) {
-	switch state {
-	case m.AlertStatePending:
-		metrics.M_Alerting_Result_State_Pending.Inc(1)
-	case m.AlertStateAlerting:
-		metrics.M_Alerting_Result_State_Alerting.Inc(1)
-	case m.AlertStateOK:
-		metrics.M_Alerting_Result_State_Ok.Inc(1)
-	case m.AlertStatePaused:
-		metrics.M_Alerting_Result_State_Paused.Inc(1)
-	case m.AlertStateNoData:
-		metrics.M_Alerting_Result_State_NoData.Inc(1)
-	}
-}

+ 1 - 1
pkg/services/sqlstore/dashboard.go

@@ -75,7 +75,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
 
 		if dash.Id == 0 {
 			dash.Version = 1
-			metrics.M_Models_Dashboard_Insert.Inc(1)
+			metrics.M_Api_Dashboard_Insert.Inc()
 			dash.Data.Set("version", dash.Version)
 			affectedRows, err = sess.Insert(dash)
 		} else {

+ 1 - 1
pkg/services/sqlstore/datasource.go

@@ -20,7 +20,7 @@ func init() {
 }
 
 func GetDataSourceById(query *m.GetDataSourceByIdQuery) error {
-	metrics.M_DB_DataSource_QueryById.Inc(1)
+	metrics.M_DB_DataSource_QueryById.Inc()
 
 	datasource := m.DataSource{OrgId: query.OrgId, Id: query.Id}
 	has, err := x.Get(&datasource)