metrics.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_Models_Dashboard_Insert Counter
  36. M_Alerting_Result_State_Alerting Counter
  37. M_Alerting_Result_State_Ok Counter
  38. M_Alerting_Result_State_Paused Counter
  39. M_Alerting_Result_State_NoData Counter
  40. M_Alerting_Result_State_Pending Counter
  41. M_Alerting_Notification_Sent_Slack Counter
  42. M_Alerting_Notification_Sent_Email Counter
  43. M_Alerting_Notification_Sent_Webhook Counter
  44. M_Alerting_Notification_Sent_PagerDuty Counter
  45. M_Alerting_Notification_Sent_LINE Counter
  46. M_Alerting_Notification_Sent_Victorops Counter
  47. M_Alerting_Notification_Sent_OpsGenie Counter
  48. M_Alerting_Notification_Sent_Telegram Counter
  49. M_Alerting_Notification_Sent_Sensu Counter
  50. M_Aws_CloudWatch_GetMetricStatistics Counter
  51. M_Aws_CloudWatch_ListMetrics Counter
  52. // Timers
  53. M_DataSource_ProxyReq_Timer Timer
  54. M_Alerting_Execution_Time Timer
  55. // StatTotals
  56. M_Alerting_Active_Alerts Gauge
  57. M_StatTotal_Dashboards Gauge
  58. M_StatTotal_Users Gauge
  59. M_StatTotal_Orgs Gauge
  60. M_StatTotal_Playlists Gauge
  61. )
  62. func initMetricVars(settings *MetricSettings) {
  63. UseNilMetrics = settings.Enabled == false
  64. MetricStats = NewRegistry()
  65. M_Instance_Start = RegCounter("instance_start")
  66. M_Page_Status_200 = RegCounter("page.resp_status", "code", "200")
  67. M_Page_Status_500 = RegCounter("page.resp_status", "code", "500")
  68. M_Page_Status_404 = RegCounter("page.resp_status", "code", "404")
  69. M_Page_Status_Unknown = RegCounter("page.resp_status", "code", "unknown")
  70. M_Api_Status_200 = RegCounter("api.resp_status", "code", "200")
  71. M_Api_Status_404 = RegCounter("api.resp_status", "code", "404")
  72. M_Api_Status_500 = RegCounter("api.resp_status", "code", "500")
  73. M_Api_Status_Unknown = RegCounter("api.resp_status", "code", "unknown")
  74. M_Proxy_Status_200 = RegCounter("proxy.resp_status", "code", "200")
  75. M_Proxy_Status_404 = RegCounter("proxy.resp_status", "code", "404")
  76. M_Proxy_Status_500 = RegCounter("proxy.resp_status", "code", "500")
  77. M_Proxy_Status_Unknown = RegCounter("proxy.resp_status", "code", "unknown")
  78. M_Api_User_SignUpStarted = RegCounter("api.user.signup_started")
  79. M_Api_User_SignUpCompleted = RegCounter("api.user.signup_completed")
  80. M_Api_User_SignUpInvite = RegCounter("api.user.signup_invite")
  81. M_Api_Dashboard_Save = RegTimer("api.dashboard.save")
  82. M_Api_Dashboard_Get = RegTimer("api.dashboard.get")
  83. M_Api_Dashboard_Search = RegTimer("api.dashboard.search")
  84. M_Api_Admin_User_Create = RegCounter("api.admin.user_create")
  85. M_Api_Login_Post = RegCounter("api.login.post")
  86. M_Api_Login_OAuth = RegCounter("api.login.oauth")
  87. M_Api_Org_Create = RegCounter("api.org.create")
  88. M_Api_Dashboard_Snapshot_Create = RegCounter("api.dashboard_snapshot.create")
  89. M_Api_Dashboard_Snapshot_External = RegCounter("api.dashboard_snapshot.external")
  90. M_Api_Dashboard_Snapshot_Get = RegCounter("api.dashboard_snapshot.get")
  91. M_Models_Dashboard_Insert = RegCounter("models.dashboard.insert")
  92. M_Alerting_Result_State_Alerting = RegCounter("alerting.result", "state", "alerting")
  93. M_Alerting_Result_State_Ok = RegCounter("alerting.result", "state", "ok")
  94. M_Alerting_Result_State_Paused = RegCounter("alerting.result", "state", "paused")
  95. M_Alerting_Result_State_NoData = RegCounter("alerting.result", "state", "no_data")
  96. M_Alerting_Result_State_Pending = RegCounter("alerting.result", "state", "pending")
  97. M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifications_sent", "type", "slack")
  98. M_Alerting_Notification_Sent_Email = RegCounter("alerting.notifications_sent", "type", "email")
  99. M_Alerting_Notification_Sent_Webhook = RegCounter("alerting.notifications_sent", "type", "webhook")
  100. M_Alerting_Notification_Sent_PagerDuty = RegCounter("alerting.notifications_sent", "type", "pagerduty")
  101. M_Alerting_Notification_Sent_Victorops = RegCounter("alerting.notifications_sent", "type", "victorops")
  102. M_Alerting_Notification_Sent_OpsGenie = RegCounter("alerting.notifications_sent", "type", "opsgenie")
  103. M_Alerting_Notification_Sent_Telegram = RegCounter("alerting.notifications_sent", "type", "telegram")
  104. M_Alerting_Notification_Sent_Sensu = RegCounter("alerting.notifications_sent", "type", "sensu")
  105. M_Alerting_Notification_Sent_LINE = RegCounter("alerting.notifications_sent", "type", "LINE")
  106. M_Aws_CloudWatch_GetMetricStatistics = RegCounter("aws.cloudwatch.get_metric_statistics")
  107. M_Aws_CloudWatch_ListMetrics = RegCounter("aws.cloudwatch.list_metrics")
  108. // Timers
  109. M_DataSource_ProxyReq_Timer = RegTimer("api.dataproxy.request.all")
  110. M_Alerting_Execution_Time = RegTimer("alerting.execution_time")
  111. // StatTotals
  112. M_Alerting_Active_Alerts = RegGauge("alerting.active_alerts")
  113. M_StatTotal_Dashboards = RegGauge("stat_totals", "stat", "dashboards")
  114. M_StatTotal_Users = RegGauge("stat_totals", "stat", "users")
  115. M_StatTotal_Orgs = RegGauge("stat_totals", "stat", "orgs")
  116. M_StatTotal_Playlists = RegGauge("stat_totals", "stat", "playlists")
  117. }