metrics.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_Critical Counter
  37. M_Alerting_Result_State_Warning Counter
  38. M_Alerting_Result_State_Ok Counter
  39. M_Alerting_Result_State_Paused Counter
  40. M_Alerting_Result_State_Unknown Counter
  41. M_Alerting_Result_State_ExecutionError Counter
  42. M_Alerting_Active_Alerts Counter
  43. M_Alerting_Notification_Sent_Slack Counter
  44. M_Alerting_Notification_Sent_Email Counter
  45. M_Alerting_Notification_Sent_Webhook Counter
  46. // Timers
  47. M_DataSource_ProxyReq_Timer Timer
  48. M_Alerting_Exeuction_Time Timer
  49. )
  50. func initMetricVars(settings *MetricSettings) {
  51. UseNilMetrics = settings.Enabled == false
  52. MetricStats = NewRegistry()
  53. M_Instance_Start = RegCounter("instance_start")
  54. M_Page_Status_200 = RegCounter("page.resp_status", "code", "200")
  55. M_Page_Status_500 = RegCounter("page.resp_status", "code", "500")
  56. M_Page_Status_404 = RegCounter("page.resp_status", "code", "404")
  57. M_Page_Status_Unknown = RegCounter("page.resp_status", "code", "unknown")
  58. M_Api_Status_200 = RegCounter("api.resp_status", "code", "200")
  59. M_Api_Status_404 = RegCounter("api.resp_status", "code", "404")
  60. M_Api_Status_500 = RegCounter("api.resp_status", "code", "500")
  61. M_Api_Status_Unknown = RegCounter("api.resp_status", "code", "unknown")
  62. M_Proxy_Status_200 = RegCounter("proxy.resp_status", "code", "200")
  63. M_Proxy_Status_404 = RegCounter("proxy.resp_status", "code", "404")
  64. M_Proxy_Status_500 = RegCounter("proxy.resp_status", "code", "500")
  65. M_Proxy_Status_Unknown = RegCounter("proxy.resp_status", "code", "unknown")
  66. M_Api_User_SignUpStarted = RegCounter("api.user.signup_started")
  67. M_Api_User_SignUpCompleted = RegCounter("api.user.signup_completed")
  68. M_Api_User_SignUpInvite = RegCounter("api.user.signup_invite")
  69. M_Api_Dashboard_Save = RegTimer("api.dashboard.save")
  70. M_Api_Dashboard_Get = RegTimer("api.dashboard.get")
  71. M_Api_Dashboard_Search = RegTimer("api.dashboard.search")
  72. M_Api_Admin_User_Create = RegCounter("api.admin.user_create")
  73. M_Api_Login_Post = RegCounter("api.login.post")
  74. M_Api_Login_OAuth = RegCounter("api.login.oauth")
  75. M_Api_Org_Create = RegCounter("api.org.create")
  76. M_Api_Dashboard_Snapshot_Create = RegCounter("api.dashboard_snapshot.create")
  77. M_Api_Dashboard_Snapshot_External = RegCounter("api.dashboard_snapshot.external")
  78. M_Api_Dashboard_Snapshot_Get = RegCounter("api.dashboard_snapshot.get")
  79. M_Models_Dashboard_Insert = RegCounter("models.dashboard.insert")
  80. M_Alerting_Result_State_Critical = RegCounter("alerting.result", "state", "critical")
  81. M_Alerting_Result_State_Warning = RegCounter("alerting.result", "state", "warning")
  82. M_Alerting_Result_State_Ok = RegCounter("alerting.result", "state", "ok")
  83. M_Alerting_Result_State_Paused = RegCounter("alerting.result", "state", "paused")
  84. M_Alerting_Result_State_Unknown = RegCounter("alerting.result", "state", "unknown")
  85. M_Alerting_Result_State_ExecutionError = RegCounter("alerting.result", "state", "execution_error")
  86. M_Alerting_Active_Alerts = RegCounter("alerting.active_alerts")
  87. M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifications_sent", "type", "slack")
  88. M_Alerting_Notification_Sent_Email = RegCounter("alerting.notifications_sent", "type", "email")
  89. M_Alerting_Notification_Sent_Webhook = RegCounter("alerting.notifications_sent", "type", "webhook")
  90. // Timers
  91. M_DataSource_ProxyReq_Timer = RegTimer("api.dataproxy.request.all")
  92. M_Alerting_Exeuction_Time = RegTimer("alerting.execution_time")
  93. }