metrics.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package metrics
  2. var MetricStats Registry
  3. var UseNilMetrics bool
  4. func init() {
  5. // init with nil metrics
  6. initMetricVars(&MetricSettings{})
  7. }
  8. var (
  9. M_Instance_Start Counter
  10. M_Page_Status_200 Counter
  11. M_Page_Status_500 Counter
  12. M_Page_Status_404 Counter
  13. M_Page_Status_Unknown Counter
  14. M_Api_Status_200 Counter
  15. M_Api_Status_404 Counter
  16. M_Api_Status_500 Counter
  17. M_Api_Status_Unknown Counter
  18. M_Proxy_Status_200 Counter
  19. M_Proxy_Status_404 Counter
  20. M_Proxy_Status_500 Counter
  21. M_Proxy_Status_Unknown Counter
  22. M_Api_User_SignUpStarted Counter
  23. M_Api_User_SignUpCompleted Counter
  24. M_Api_User_SignUpInvite Counter
  25. M_Api_Dashboard_Save Timer
  26. M_Api_Dashboard_Get Timer
  27. M_Api_Dashboard_Search Timer
  28. M_Api_Admin_User_Create Counter
  29. M_Api_Login_Post Counter
  30. M_Api_Login_OAuth Counter
  31. M_Api_Org_Create Counter
  32. M_Api_Dashboard_Snapshot_Create Counter
  33. M_Api_Dashboard_Snapshot_External Counter
  34. M_Api_Dashboard_Snapshot_Get Counter
  35. M_Api_UserGroup_Create Counter
  36. M_Api_Dashboard_Acl_Update Counter
  37. M_Models_Dashboard_Insert Counter
  38. M_Alerting_Result_State_Alerting Counter
  39. M_Alerting_Result_State_Ok Counter
  40. M_Alerting_Result_State_Paused Counter
  41. M_Alerting_Result_State_NoData Counter
  42. M_Alerting_Result_State_Pending Counter
  43. M_Alerting_Notification_Sent_Slack Counter
  44. M_Alerting_Notification_Sent_Email Counter
  45. M_Alerting_Notification_Sent_Webhook Counter
  46. M_Alerting_Notification_Sent_DingDing Counter
  47. M_Alerting_Notification_Sent_PagerDuty Counter
  48. M_Alerting_Notification_Sent_LINE Counter
  49. M_Alerting_Notification_Sent_Victorops Counter
  50. M_Alerting_Notification_Sent_OpsGenie Counter
  51. M_Alerting_Notification_Sent_Telegram Counter
  52. M_Alerting_Notification_Sent_Threema Counter
  53. M_Alerting_Notification_Sent_Sensu Counter
  54. M_Alerting_Notification_Sent_Pushover Counter
  55. M_Aws_CloudWatch_GetMetricStatistics Counter
  56. M_Aws_CloudWatch_ListMetrics Counter
  57. M_DB_DataSource_QueryById Counter
  58. // Timers
  59. M_DataSource_ProxyReq_Timer Timer
  60. M_Alerting_Execution_Time Timer
  61. // StatTotals
  62. M_Alerting_Active_Alerts Gauge
  63. M_StatTotal_Dashboards Gauge
  64. M_StatTotal_Users Gauge
  65. M_StatTotal_Orgs Gauge
  66. M_StatTotal_Playlists Gauge
  67. )
  68. func initMetricVars(settings *MetricSettings) {
  69. UseNilMetrics = settings.Enabled == false
  70. MetricStats = NewRegistry()
  71. M_Instance_Start = RegCounter("instance_start")
  72. M_Page_Status_200 = RegCounter("page.resp_status", "code", "200")
  73. M_Page_Status_500 = RegCounter("page.resp_status", "code", "500")
  74. M_Page_Status_404 = RegCounter("page.resp_status", "code", "404")
  75. M_Page_Status_Unknown = RegCounter("page.resp_status", "code", "unknown")
  76. M_Api_Status_200 = RegCounter("api.resp_status", "code", "200")
  77. M_Api_Status_404 = RegCounter("api.resp_status", "code", "404")
  78. M_Api_Status_500 = RegCounter("api.resp_status", "code", "500")
  79. M_Api_Status_Unknown = RegCounter("api.resp_status", "code", "unknown")
  80. M_Proxy_Status_200 = RegCounter("proxy.resp_status", "code", "200")
  81. M_Proxy_Status_404 = RegCounter("proxy.resp_status", "code", "404")
  82. M_Proxy_Status_500 = RegCounter("proxy.resp_status", "code", "500")
  83. M_Proxy_Status_Unknown = RegCounter("proxy.resp_status", "code", "unknown")
  84. M_Api_User_SignUpStarted = RegCounter("api.user.signup_started")
  85. M_Api_User_SignUpCompleted = RegCounter("api.user.signup_completed")
  86. M_Api_User_SignUpInvite = RegCounter("api.user.signup_invite")
  87. M_Api_UserGroup_Create = RegCounter("api.usergroup.create")
  88. M_Api_Dashboard_Acl_Update = RegCounter("api.dashboard.acl.update")
  89. M_Api_Dashboard_Save = RegTimer("api.dashboard.save")
  90. M_Api_Dashboard_Get = RegTimer("api.dashboard.get")
  91. M_Api_Dashboard_Search = RegTimer("api.dashboard.search")
  92. M_Api_Admin_User_Create = RegCounter("api.admin.user_create")
  93. M_Api_Login_Post = RegCounter("api.login.post")
  94. M_Api_Login_OAuth = RegCounter("api.login.oauth")
  95. M_Api_Org_Create = RegCounter("api.org.create")
  96. M_Api_Dashboard_Snapshot_Create = RegCounter("api.dashboard_snapshot.create")
  97. M_Api_Dashboard_Snapshot_External = RegCounter("api.dashboard_snapshot.external")
  98. M_Api_Dashboard_Snapshot_Get = RegCounter("api.dashboard_snapshot.get")
  99. M_Models_Dashboard_Insert = RegCounter("models.dashboard.insert")
  100. M_Alerting_Result_State_Alerting = RegCounter("alerting.result", "state", "alerting")
  101. M_Alerting_Result_State_Ok = RegCounter("alerting.result", "state", "ok")
  102. M_Alerting_Result_State_Paused = RegCounter("alerting.result", "state", "paused")
  103. M_Alerting_Result_State_NoData = RegCounter("alerting.result", "state", "no_data")
  104. M_Alerting_Result_State_Pending = RegCounter("alerting.result", "state", "pending")
  105. M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifications_sent", "type", "slack")
  106. M_Alerting_Notification_Sent_Email = RegCounter("alerting.notifications_sent", "type", "email")
  107. M_Alerting_Notification_Sent_Webhook = RegCounter("alerting.notifications_sent", "type", "webhook")
  108. M_Alerting_Notification_Sent_DingDing = RegCounter("alerting.notifications_sent", "type", "dingding")
  109. M_Alerting_Notification_Sent_PagerDuty = RegCounter("alerting.notifications_sent", "type", "pagerduty")
  110. M_Alerting_Notification_Sent_Victorops = RegCounter("alerting.notifications_sent", "type", "victorops")
  111. M_Alerting_Notification_Sent_OpsGenie = RegCounter("alerting.notifications_sent", "type", "opsgenie")
  112. M_Alerting_Notification_Sent_Telegram = RegCounter("alerting.notifications_sent", "type", "telegram")
  113. M_Alerting_Notification_Sent_Threema = RegCounter("alerting.notifications_sent", "type", "threema")
  114. M_Alerting_Notification_Sent_Sensu = RegCounter("alerting.notifications_sent", "type", "sensu")
  115. M_Alerting_Notification_Sent_LINE = RegCounter("alerting.notifications_sent", "type", "LINE")
  116. M_Alerting_Notification_Sent_Pushover = RegCounter("alerting.notifications_sent", "type", "pushover")
  117. M_Aws_CloudWatch_GetMetricStatistics = RegCounter("aws.cloudwatch.get_metric_statistics")
  118. M_Aws_CloudWatch_ListMetrics = RegCounter("aws.cloudwatch.list_metrics")
  119. M_DB_DataSource_QueryById = RegCounter("db.datasource.query_by_id")
  120. // Timers
  121. M_DataSource_ProxyReq_Timer = RegTimer("api.dataproxy.request.all")
  122. M_Alerting_Execution_Time = RegTimer("alerting.execution_time")
  123. // StatTotals
  124. M_Alerting_Active_Alerts = RegGauge("alerting.active_alerts")
  125. M_StatTotal_Dashboards = RegGauge("stat_totals", "stat", "dashboards")
  126. M_StatTotal_Users = RegGauge("stat_totals", "stat", "users")
  127. M_StatTotal_Orgs = RegGauge("stat_totals", "stat", "orgs")
  128. M_StatTotal_Playlists = RegGauge("stat_totals", "stat", "playlists")
  129. }