Commit 75fa1f02 by Oleg Gaidarenko Committed by Torkel Ödegaard

Metrics: use consistent naming for exported variables (#18134)

* Metrics: remove unused metrics

Metric `M_Grafana_Version` is not used anywhere, nor the mentioned
`M_Grafana_Build_Version`. Seems to be an artefact?

* Metrics: make the naming consistent

* Metrics: add comments to exported vars

* Metrics: use proper naming

Fixes #18110
parent 15ce5a68
......@@ -34,7 +34,7 @@ func AdminCreateUser(c *models.ReqContext, form dtos.AdminCreateUserForm) {
return
}
metrics.M_Api_Admin_User_Create.Inc()
metrics.MApiAdminUserCreate.Inc()
user := cmd.Result
......
......@@ -133,7 +133,7 @@ func (hs *HTTPServer) GetDashboard(c *m.ReqContext) Response {
Meta: meta,
}
c.TimeRequest(metrics.M_Api_Dashboard_Get)
c.TimeRequest(metrics.MApiDashboardGet)
return JSON(200, dto)
}
......@@ -282,7 +282,7 @@ func (hs *HTTPServer) PostDashboard(c *m.ReqContext, cmd m.SaveDashboardCommand)
}
}
c.TimeRequest(metrics.M_Api_Dashboard_Save)
c.TimeRequest(metrics.MApiDashboardSave)
return JSON(200, util.DynMap{
"status": "success",
"slug": dashboard.Slug,
......
......@@ -97,7 +97,7 @@ func CreateDashboardSnapshot(c *m.ReqContext, cmd m.CreateDashboardSnapshotComma
cmd.ExternalDeleteUrl = response.DeleteUrl
cmd.Dashboard = simplejson.New()
metrics.M_Api_Dashboard_Snapshot_External.Inc()
metrics.MApiDashboardSnapshotExternal.Inc()
} else {
if cmd.Key == "" {
cmd.Key = util.GetRandomString(32)
......@@ -109,7 +109,7 @@ func CreateDashboardSnapshot(c *m.ReqContext, cmd m.CreateDashboardSnapshotComma
url = setting.ToAbsUrl("dashboard/snapshot/" + cmd.Key)
metrics.M_Api_Dashboard_Snapshot_Create.Inc()
metrics.MApiDashboardSnapshotCreate.Inc()
}
if err := bus.Dispatch(&cmd); err != nil {
......@@ -154,7 +154,7 @@ func GetDashboardSnapshot(c *m.ReqContext) {
},
}
metrics.M_Api_Dashboard_Snapshot_Get.Inc()
metrics.MApiDashboardSnapshotGet.Inc()
c.Resp.Header().Set("Cache-Control", "public, max-age=3600")
c.JSON(200, dto)
......
......@@ -8,7 +8,7 @@ import (
)
func (hs *HTTPServer) ProxyDataSourceRequest(c *m.ReqContext) {
c.TimeRequest(metrics.M_DataSource_ProxyReq_Timer)
c.TimeRequest(metrics.MDataSourceProxyReqTimer)
dsId := c.ParamsInt64(":id")
ds, err := hs.DatasourceCache.GetDatasource(dsId, c.SignedInUser, c.SkipCache)
......
......@@ -138,7 +138,7 @@ func (hs *HTTPServer) LoginPost(c *models.ReqContext, cmd dtos.LoginCommand) Res
c.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")
}
metrics.M_Api_Login_Post.Inc()
metrics.MApiLoginPost.Inc()
return JSON(200, result)
}
......
......@@ -199,7 +199,7 @@ func (hs *HTTPServer) OAuthLogin(ctx *m.ReqContext) {
// login
hs.loginUserWithUser(cmd.Result, ctx)
metrics.M_Api_Login_OAuth.Inc()
metrics.MApiLoginOAuth.Inc()
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")
......
......@@ -88,7 +88,7 @@ func CreateOrg(c *m.ReqContext, cmd m.CreateOrgCommand) Response {
return Error(500, "Failed to create organization", err)
}
metrics.M_Api_Org_Create.Inc()
metrics.MApiOrgCreate.Inc()
return JSON(200, &util.DynMap{
"orgId": cmd.Result.Id,
......
......@@ -188,8 +188,8 @@ func (hs *HTTPServer) CompleteInvite(c *m.ReqContext, completeInvite dtos.Comple
hs.loginUserWithUser(user, c)
metrics.M_Api_User_SignUpCompleted.Inc()
metrics.M_Api_User_SignUpInvite.Inc()
metrics.MApiUserSignUpCompleted.Inc()
metrics.MApiUserSignUpInvite.Inc()
return Success("User created and logged in")
}
......
......@@ -61,6 +61,6 @@ func Search(c *m.ReqContext) Response {
return Error(500, "Search failed", err)
}
c.TimeRequest(metrics.M_Api_Dashboard_Search)
c.TimeRequest(metrics.MApiDashboardSearch)
return JSON(200, searchQuery.Result)
}
......@@ -46,7 +46,7 @@ func SignUp(c *m.ReqContext, form dtos.SignUpForm) Response {
Code: cmd.Code,
})
metrics.M_Api_User_SignUpStarted.Inc()
metrics.MApiUserSignUpStarted.Inc()
return JSON(200, util.DynMap{"status": "SignUpCreated"})
}
......@@ -110,7 +110,7 @@ func (hs *HTTPServer) SignUpStep2(c *m.ReqContext, form dtos.SignUpStep2Form) Re
}
hs.loginUserWithUser(user, c)
metrics.M_Api_User_SignUpCompleted.Inc()
metrics.MApiUserSignUpCompleted.Inc()
return JSON(200, apiResponse)
}
......
......@@ -46,7 +46,7 @@ func (im *InternalMetricsService) Run(ctx context.Context) error {
}
}
M_Instance_Start.Inc()
MInstanceStart.Inc()
<-ctx.Done()
return ctx.Err()
......
......@@ -161,11 +161,11 @@ func (uss *UsageStatsService) updateTotalStats() {
return
}
metrics.M_StatTotal_Dashboards.Set(float64(statsQuery.Result.Dashboards))
metrics.M_StatTotal_Users.Set(float64(statsQuery.Result.Users))
metrics.M_StatActive_Users.Set(float64(statsQuery.Result.ActiveUsers))
metrics.M_StatTotal_Playlists.Set(float64(statsQuery.Result.Playlists))
metrics.M_StatTotal_Orgs.Set(float64(statsQuery.Result.Orgs))
metrics.MStatTotalDashboards.Set(float64(statsQuery.Result.Dashboards))
metrics.MStatTotalUsers.Set(float64(statsQuery.Result.Users))
metrics.MStatActiveUsers.Set(float64(statsQuery.Result.ActiveUsers))
metrics.MStatTotalPlaylists.Set(float64(statsQuery.Result.Playlists))
metrics.MStatTotalOrgs.Set(float64(statsQuery.Result.Orgs))
metrics.StatsTotalViewers.Set(float64(statsQuery.Result.Viewers))
metrics.StatsTotalActiveViewers.Set(float64(statsQuery.Result.ActiveViewers))
metrics.StatsTotalEditors.Set(float64(statsQuery.Result.Editors))
......
......@@ -20,9 +20,9 @@ func RequestMetrics(handler string) macaron.Handler {
code := sanitizeCode(status)
method := sanitizeMethod(req.Method)
metrics.M_Http_Request_Total.WithLabelValues(handler, code, method).Inc()
metrics.MHttpRequestTotal.WithLabelValues(handler, code, method).Inc()
duration := time.Since(now).Nanoseconds() / int64(time.Millisecond)
metrics.M_Http_Request_Summary.WithLabelValues(handler, code, method).Observe(float64(duration))
metrics.MHttpRequestSummary.WithLabelValues(handler, code, method).Observe(float64(duration))
if strings.HasPrefix(req.RequestURI, "/api/datasources/proxy") {
countProxyRequests(status)
......@@ -37,39 +37,39 @@ func RequestMetrics(handler string) macaron.Handler {
func countApiRequests(status int) {
switch status {
case 200:
metrics.M_Api_Status.WithLabelValues("200").Inc()
metrics.MApiStatus.WithLabelValues("200").Inc()
case 404:
metrics.M_Api_Status.WithLabelValues("404").Inc()
metrics.MApiStatus.WithLabelValues("404").Inc()
case 500:
metrics.M_Api_Status.WithLabelValues("500").Inc()
metrics.MApiStatus.WithLabelValues("500").Inc()
default:
metrics.M_Api_Status.WithLabelValues("unknown").Inc()
metrics.MApiStatus.WithLabelValues("unknown").Inc()
}
}
func countPageRequests(status int) {
switch status {
case 200:
metrics.M_Page_Status.WithLabelValues("200").Inc()
metrics.MPageStatus.WithLabelValues("200").Inc()
case 404:
metrics.M_Page_Status.WithLabelValues("404").Inc()
metrics.MPageStatus.WithLabelValues("404").Inc()
case 500:
metrics.M_Page_Status.WithLabelValues("500").Inc()
metrics.MPageStatus.WithLabelValues("500").Inc()
default:
metrics.M_Page_Status.WithLabelValues("unknown").Inc()
metrics.MPageStatus.WithLabelValues("unknown").Inc()
}
}
func countProxyRequests(status int) {
switch status {
case 200:
metrics.M_Proxy_Status.WithLabelValues("200").Inc()
metrics.MProxyStatus.WithLabelValues("200").Inc()
case 404:
metrics.M_Proxy_Status.WithLabelValues("400").Inc()
metrics.MProxyStatus.WithLabelValues("400").Inc()
case 500:
metrics.M_Proxy_Status.WithLabelValues("500").Inc()
metrics.MProxyStatus.WithLabelValues("500").Inc()
default:
metrics.M_Proxy_Status.WithLabelValues("unknown").Inc()
metrics.MProxyStatus.WithLabelValues("unknown").Inc()
}
}
......
......@@ -70,5 +70,5 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
context.EndTime = time.Now()
elapsedTime := context.EndTime.Sub(context.StartTime).Nanoseconds() / int64(time.Millisecond)
metrics.M_Alerting_Execution_Time.Observe(float64(elapsedTime))
metrics.MAlertingExecutionTime.Observe(float64(elapsedTime))
}
......@@ -57,7 +57,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
notifier := notifierState.notifier
n.log.Debug("Sending notification", "type", notifier.GetType(), "uid", notifier.GetNotifierUID(), "isDefault", notifier.GetIsDefault())
metrics.M_Alerting_Notification_Sent.WithLabelValues(notifier.GetType()).Inc()
metrics.MAlertingNotificationSent.WithLabelValues(notifier.GetType()).Inc()
err := notifier.Notify(evalContext)
......
......@@ -43,6 +43,6 @@ func (arr *defaultRuleReader) fetch() []*Rule {
}
}
metrics.M_Alerting_Active_Alerts.Set(float64(len(res)))
metrics.MAlertingActiveAlerts.Set(float64(len(res)))
return res
}
......@@ -44,7 +44,7 @@ func (handler *defaultResultHandler) handle(evalContext *EvalContext) error {
annotationData.Set("noData", true)
}
metrics.M_Alerting_Result_State.WithLabelValues(string(evalContext.Rule.State)).Inc()
metrics.MAlertingResultState.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)
......
......@@ -87,7 +87,7 @@ func saveDashboard(sess *DBSession, cmd *m.SaveDashboardCommand) error {
dash.CreatedBy = userId
dash.Updated = time.Now()
dash.UpdatedBy = userId
metrics.M_Api_Dashboard_Insert.Inc()
metrics.MApiDashboardInsert.Inc()
affectedRows, err = sess.Insert(dash)
} else {
dash.SetVersion(dash.Version + 1)
......
......@@ -25,7 +25,7 @@ func init() {
}
func GetDataSourceById(query *m.GetDataSourceByIdQuery) error {
metrics.M_DB_DataSource_QueryById.Inc()
metrics.MDBDataSourceQueryByID.Inc()
datasource := m.DataSource{OrgId: query.OrgId, Id: query.Id}
has, err := x.Get(&datasource)
......
......@@ -37,7 +37,7 @@ func (e *CloudWatchExecutor) executeGetMetricDataQuery(ctx context.Context, regi
if err != nil {
return queryResponses, err
}
metrics.M_Aws_CloudWatch_GetMetricData.Add(float64(len(params.MetricDataQueries)))
metrics.MAwsCloudWatchGetMetricData.Add(float64(len(params.MetricDataQueries)))
for _, r := range resp.MetricDataResults {
if _, ok := mdr[*r.Id]; !ok {
......
......@@ -81,7 +81,7 @@ func (e *CloudWatchExecutor) executeQuery(ctx context.Context, query *CloudWatch
resp = partResp
}
metrics.M_Aws_CloudWatch_GetMetricStatistics.Inc()
metrics.MAwsCloudWatchGetMetricStatistics.Inc()
}
queryRes, err := parseResponse(resp, query)
......
......@@ -642,7 +642,7 @@ func (e *CloudWatchExecutor) cloudwatchListMetrics(region string, namespace stri
var resp cloudwatch.ListMetricsOutput
err = svc.ListMetricsPages(params,
func(page *cloudwatch.ListMetricsOutput, lastPage bool) bool {
metrics.M_Aws_CloudWatch_ListMetrics.Inc()
metrics.MAwsCloudWatchListMetrics.Inc()
metrics, _ := awsutil.ValuesAtPath(page, "Metrics")
for _, metric := range metrics {
resp.Metrics = append(resp.Metrics, metric.(*cloudwatch.Metric))
......@@ -722,7 +722,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()
metrics.MAwsCloudWatchListMetrics.Inc()
metrics, _ := awsutil.ValuesAtPath(page, "Metrics")
for _, metric := range metrics {
resp.Metrics = append(resp.Metrics, metric.(*cloudwatch.Metric))
......
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