Commit 2de94d65 by bergquist Committed by Carl Bergquist

convert old metrics to prom metrics

parent 788f677e
......@@ -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
......
......@@ -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))
......
......@@ -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))
......
......@@ -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)
......
......@@ -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)
}
......
......@@ -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+"/")
......
......@@ -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,
......
......@@ -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")
}
......
......@@ -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)
}
......
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
}
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,
}
}
// 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)
}
......@@ -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 {
......
......@@ -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)
}
......
// 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))
}
......@@ -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()
......
......@@ -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
}
......
......@@ -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()
}
}
......@@ -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.
......
......@@ -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) })
}
......
......@@ -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 {
......
......@@ -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,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 {
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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 {
......
......@@ -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()
......
......@@ -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{}
......
......@@ -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 {
......
......@@ -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())
......
......@@ -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
}
......
......@@ -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)
}
}
......@@ -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 {
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment