metrics.go 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_Api_Status_500 Counter
  14. M_Api_Status_404 Counter
  15. M_Api_User_SignUpStarted Counter
  16. M_Api_User_SignUpCompleted Counter
  17. M_Api_User_SignUpInvite Counter
  18. M_Api_Dashboard_Save Timer
  19. M_Api_Dashboard_Get Timer
  20. M_Api_Dashboard_Search Timer
  21. M_Api_Admin_User_Create Counter
  22. M_Api_Login_Post Counter
  23. M_Api_Login_OAuth Counter
  24. M_Api_Org_Create Counter
  25. M_Api_Dashboard_Snapshot_Create Counter
  26. M_Api_Dashboard_Snapshot_External Counter
  27. M_Api_Dashboard_Snapshot_Get Counter
  28. M_Models_Dashboard_Insert Counter
  29. M_Alerting_Result_State_Critical Counter
  30. M_Alerting_Result_State_Warning Counter
  31. M_Alerting_Result_State_Ok Counter
  32. M_Alerting_Result_State_Paused Counter
  33. M_Alerting_Result_State_Pending Counter
  34. M_Alerting_Result_State_ExecutionError Counter
  35. M_Alerting_Active_Alerts Counter
  36. M_Alerting_Notification_Sent_Slack Counter
  37. M_Alerting_Notification_Sent_Email Counter
  38. M_Alerting_Notification_Sent_Webhook Counter
  39. // Timers
  40. M_DataSource_ProxyReq_Timer Timer
  41. M_Alerting_Exeuction_Time Timer
  42. )
  43. func initMetricVars(settings *MetricSettings) {
  44. UseNilMetrics = settings.Enabled == false
  45. MetricStats = NewRegistry()
  46. M_Instance_Start = RegCounter("instance_start")
  47. M_Page_Status_200 = RegCounter("page.resp_status", "code", "200")
  48. M_Page_Status_500 = RegCounter("page.resp_status", "code", "500")
  49. M_Page_Status_404 = RegCounter("page.resp_status", "code", "404")
  50. M_Api_Status_500 = RegCounter("api.resp_status", "code", "500")
  51. M_Api_Status_404 = RegCounter("api.resp_status", "code", "404")
  52. M_Api_User_SignUpStarted = RegCounter("api.user.signup_started")
  53. M_Api_User_SignUpCompleted = RegCounter("api.user.signup_completed")
  54. M_Api_User_SignUpInvite = RegCounter("api.user.signup_invite")
  55. M_Api_Dashboard_Save = RegTimer("api.dashboard.save")
  56. M_Api_Dashboard_Get = RegTimer("api.dashboard.get")
  57. M_Api_Dashboard_Search = RegTimer("api.dashboard.search")
  58. M_Api_Admin_User_Create = RegCounter("api.admin.user_create")
  59. M_Api_Login_Post = RegCounter("api.login.post")
  60. M_Api_Login_OAuth = RegCounter("api.login.oauth")
  61. M_Api_Org_Create = RegCounter("api.org.create")
  62. M_Api_Dashboard_Snapshot_Create = RegCounter("api.dashboard_snapshot.create")
  63. M_Api_Dashboard_Snapshot_External = RegCounter("api.dashboard_snapshot.external")
  64. M_Api_Dashboard_Snapshot_Get = RegCounter("api.dashboard_snapshot.get")
  65. M_Models_Dashboard_Insert = RegCounter("models.dashboard.insert")
  66. M_Alerting_Result_State_Critical = RegCounter("alerting.result", "state", "critical")
  67. M_Alerting_Result_State_Warning = RegCounter("alerting.result", "state", "warning")
  68. M_Alerting_Result_State_Ok = RegCounter("alerting.result", "state", "ok")
  69. M_Alerting_Result_State_Paused = RegCounter("alerting.result", "state", "paused")
  70. M_Alerting_Result_State_Pending = RegCounter("alerting.result", "state", "pending")
  71. M_Alerting_Result_State_ExecutionError = RegCounter("alerting.result", "state", "execution_error")
  72. M_Alerting_Active_Alerts = RegCounter("alerting.active_alerts")
  73. M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifications_sent", "type", "slack")
  74. M_Alerting_Notification_Sent_Email = RegCounter("alerting.notifications_sent", "type", "email")
  75. M_Alerting_Notification_Sent_Webhook = RegCounter("alerting.notifications_sent", "type", "webhook")
  76. // Timers
  77. M_DataSource_ProxyReq_Timer = RegTimer("api.dataproxy.request.all")
  78. M_Alerting_Exeuction_Time = RegTimer("alerting.execution_time")
  79. }