| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- package metrics
- import (
- "runtime"
- "github.com/prometheus/client_golang/prometheus"
- "github.com/grafana/grafana/pkg/setting"
- )
- const exporterName = "grafana"
- var (
- // MInstanceStart is a metric counter for started instances
- MInstanceStart prometheus.Counter
- // MPageStatus is a metric page http response status
- MPageStatus *prometheus.CounterVec
- // MApiStatus is a metric api http response status
- MApiStatus *prometheus.CounterVec
- // MProxyStatus is a metric proxy http response status
- MProxyStatus *prometheus.CounterVec
- // MHttpRequestTotal is a metric http request counter
- MHttpRequestTotal *prometheus.CounterVec
- // MHttpRequestSummary is a metric http request summary
- MHttpRequestSummary *prometheus.SummaryVec
- // MApiUserSignUpStarted is a metric amount of users who started the signup flow
- MApiUserSignUpStarted prometheus.Counter
- // MApiUserSignUpCompleted is a metric amount of users who completed the signup flow
- MApiUserSignUpCompleted prometheus.Counter
- // MApiUserSignUpInvite is a metric amount of users who have been invited
- MApiUserSignUpInvite prometheus.Counter
- // MApiDashboardSave is a metric summary for dashboard save duration
- MApiDashboardSave prometheus.Summary
- // MApiDashboardGet is a metric summary for dashboard get duration
- MApiDashboardGet prometheus.Summary
- // MApiDashboardSearch is a metric summary for dashboard search duration
- MApiDashboardSearch prometheus.Summary
- // MApiAdminUserCreate is a metric api admin user created counter
- MApiAdminUserCreate prometheus.Counter
- // MApiLoginPost is a metric api login post counter
- MApiLoginPost prometheus.Counter
- // MApiLoginOAuth is a metric api login oauth counter
- MApiLoginOAuth prometheus.Counter
- // MApiOrgCreate is a metric api org created counter
- MApiOrgCreate prometheus.Counter
- // MApiDashboardSnapshotCreate is a metric dashboard snapshots created
- MApiDashboardSnapshotCreate prometheus.Counter
- // MApiDashboardSnapshotExternal is a metric external dashboard snapshots created
- MApiDashboardSnapshotExternal prometheus.Counter
- // MApiDashboardSnapshotGet is a metric loaded dashboards
- MApiDashboardSnapshotGet prometheus.Counter
- // MApiDashboardInsert is a metric dashboards inserted
- MApiDashboardInsert prometheus.Counter
- // MAlertingResultState is a metric alert execution result counter
- MAlertingResultState *prometheus.CounterVec
- // MAlertingNotificationSent is a metric counter for how many alert notifications been sent
- MAlertingNotificationSent *prometheus.CounterVec
- // MAwsCloudWatchGetMetricStatistics is a metric counter for getting metric statistics from aws
- MAwsCloudWatchGetMetricStatistics prometheus.Counter
- // MAwsCloudWatchListMetrics is a metric counter for getting list of metrics from aws
- MAwsCloudWatchListMetrics prometheus.Counter
- // MAwsCloudWatchGetMetricData is a metric counter for getting metric data time series from aws
- MAwsCloudWatchGetMetricData prometheus.Counter
- // MDBDataSourceQueryByID is a metric counter for getting datasource by id
- MDBDataSourceQueryByID prometheus.Counter
- // LDAPUsersSyncExecutionTime is a metric summary for LDAP users sync execution duration
- LDAPUsersSyncExecutionTime prometheus.Summary
- )
- // Timers
- var (
- // MDataSourceProxyReqTimer is a metric summary for dataproxy request duration
- MDataSourceProxyReqTimer prometheus.Summary
- // MAlertingExecutionTime is a metric summary of alert exeuction duration
- MAlertingExecutionTime prometheus.Summary
- )
- // StatTotals
- var (
- // MAlertingActiveAlerts is a metric amount of active alerts
- MAlertingActiveAlerts prometheus.Gauge
- // MStatTotalDashboards is a metric total amount of dashboards
- MStatTotalDashboards prometheus.Gauge
- // MStatTotalUsers is a metric total amount of users
- MStatTotalUsers prometheus.Gauge
- // MStatActiveUsers is a metric number of active users
- MStatActiveUsers prometheus.Gauge
- // MStatTotalOrgs is a metric total amount of orgs
- MStatTotalOrgs prometheus.Gauge
- // MStatTotalPlaylists is a metric total amount of playlists
- MStatTotalPlaylists prometheus.Gauge
- // StatsTotalViewers is a metric total amount of viewers
- StatsTotalViewers prometheus.Gauge
- // StatsTotalEditors is a metric total amount of editors
- StatsTotalEditors prometheus.Gauge
- // StatsTotalAdmins is a metric total amount of admins
- StatsTotalAdmins prometheus.Gauge
- // StatsTotalActiveViewers is a metric total amount of viewers
- StatsTotalActiveViewers prometheus.Gauge
- // StatsTotalActiveEditors is a metric total amount of active editors
- StatsTotalActiveEditors prometheus.Gauge
- // StatsTotalActiveAdmins is a metric total amount of active admins
- StatsTotalActiveAdmins prometheus.Gauge
- // grafanaBuildVersion is a metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built
- grafanaBuildVersion *prometheus.GaugeVec
- )
- func init() {
- httpStatusCodes := []string{"200", "404", "500", "unknown"}
- MInstanceStart = prometheus.NewCounter(prometheus.CounterOpts{
- Name: "instance_start_total",
- Help: "counter for started instances",
- Namespace: exporterName,
- })
- MPageStatus = newCounterVecStartingAtZero(
- prometheus.CounterOpts{
- Name: "page_response_status_total",
- Help: "page http response status",
- Namespace: exporterName,
- }, []string{"code"}, httpStatusCodes...)
- MApiStatus = newCounterVecStartingAtZero(
- prometheus.CounterOpts{
- Name: "api_response_status_total",
- Help: "api http response status",
- Namespace: exporterName,
- }, []string{"code"}, httpStatusCodes...)
- MProxyStatus = newCounterVecStartingAtZero(
- prometheus.CounterOpts{
- Name: "proxy_response_status_total",
- Help: "proxy http response status",
- Namespace: exporterName,
- }, []string{"code"}, httpStatusCodes...)
- MHttpRequestTotal = prometheus.NewCounterVec(
- prometheus.CounterOpts{
- Name: "http_request_total",
- Help: "http request counter",
- },
- []string{"handler", "statuscode", "method"},
- )
- MHttpRequestSummary = prometheus.NewSummaryVec(
- prometheus.SummaryOpts{
- Name: "http_request_duration_milliseconds",
- Help: "http request summary",
- },
- []string{"handler", "statuscode", "method"},
- )
- MApiUserSignUpStarted = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_user_signup_started_total",
- Help: "amount of users who started the signup flow",
- Namespace: exporterName,
- })
- MApiUserSignUpCompleted = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_user_signup_completed_total",
- Help: "amount of users who completed the signup flow",
- Namespace: exporterName,
- })
- MApiUserSignUpInvite = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_user_signup_invite_total",
- Help: "amount of users who have been invited",
- Namespace: exporterName,
- })
- MApiDashboardSave = prometheus.NewSummary(prometheus.SummaryOpts{
- Name: "api_dashboard_save_milliseconds",
- Help: "summary for dashboard save duration",
- Namespace: exporterName,
- })
- MApiDashboardGet = prometheus.NewSummary(prometheus.SummaryOpts{
- Name: "api_dashboard_get_milliseconds",
- Help: "summary for dashboard get duration",
- Namespace: exporterName,
- })
- MApiDashboardSearch = prometheus.NewSummary(prometheus.SummaryOpts{
- Name: "api_dashboard_search_milliseconds",
- Help: "summary for dashboard search duration",
- Namespace: exporterName,
- })
- MApiAdminUserCreate = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_admin_user_created_total",
- Help: "api admin user created counter",
- Namespace: exporterName,
- })
- MApiLoginPost = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_login_post_total",
- Help: "api login post counter",
- Namespace: exporterName,
- })
- MApiLoginOAuth = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_login_oauth_total",
- Help: "api login oauth counter",
- Namespace: exporterName,
- })
- MApiOrgCreate = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_org_create_total",
- Help: "api org created counter",
- Namespace: exporterName,
- })
- MApiDashboardSnapshotCreate = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_dashboard_snapshot_create_total",
- Help: "dashboard snapshots created",
- Namespace: exporterName,
- })
- MApiDashboardSnapshotExternal = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_dashboard_snapshot_external_total",
- Help: "external dashboard snapshots created",
- Namespace: exporterName,
- })
- MApiDashboardSnapshotGet = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_dashboard_snapshot_get_total",
- Help: "loaded dashboards",
- Namespace: exporterName,
- })
- MApiDashboardInsert = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "api_models_dashboard_insert_total",
- Help: "dashboards inserted ",
- Namespace: exporterName,
- })
- MAlertingResultState = prometheus.NewCounterVec(prometheus.CounterOpts{
- Name: "alerting_result_total",
- Help: "alert execution result counter",
- Namespace: exporterName,
- }, []string{"state"})
- MAlertingNotificationSent = prometheus.NewCounterVec(prometheus.CounterOpts{
- Name: "alerting_notification_sent_total",
- Help: "counter for how many alert notifications been sent",
- Namespace: exporterName,
- }, []string{"type"})
- MAwsCloudWatchGetMetricStatistics = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "aws_cloudwatch_get_metric_statistics_total",
- Help: "counter for getting metric statistics from aws",
- Namespace: exporterName,
- })
- MAwsCloudWatchListMetrics = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "aws_cloudwatch_list_metrics_total",
- Help: "counter for getting list of metrics from aws",
- Namespace: exporterName,
- })
- MAwsCloudWatchGetMetricData = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "aws_cloudwatch_get_metric_data_total",
- Help: "counter for getting metric data time series from aws",
- Namespace: exporterName,
- })
- MDBDataSourceQueryByID = newCounterStartingAtZero(prometheus.CounterOpts{
- Name: "db_datasource_query_by_id_total",
- Help: "counter for getting datasource by id",
- Namespace: exporterName,
- })
- LDAPUsersSyncExecutionTime = prometheus.NewSummary(prometheus.SummaryOpts{
- Name: "ldap_users_sync_execution_time",
- Help: "summary for LDAP users sync execution duration",
- Namespace: exporterName,
- })
- MDataSourceProxyReqTimer = prometheus.NewSummary(prometheus.SummaryOpts{
- Name: "api_dataproxy_request_all_milliseconds",
- Help: "summary for dataproxy request duration",
- Namespace: exporterName,
- })
- MAlertingExecutionTime = prometheus.NewSummary(prometheus.SummaryOpts{
- Name: "alerting_execution_time_milliseconds",
- Help: "summary of alert exeuction duration",
- Namespace: exporterName,
- })
- MAlertingActiveAlerts = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "alerting_active_alerts",
- Help: "amount of active alerts",
- Namespace: exporterName,
- })
- MStatTotalDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_totals_dashboard",
- Help: "total amount of dashboards",
- Namespace: exporterName,
- })
- MStatTotalUsers = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_total_users",
- Help: "total amount of users",
- Namespace: exporterName,
- })
- MStatActiveUsers = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_active_users",
- Help: "number of active users",
- Namespace: exporterName,
- })
- MStatTotalOrgs = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_total_orgs",
- Help: "total amount of orgs",
- Namespace: exporterName,
- })
- MStatTotalPlaylists = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_total_playlists",
- Help: "total amount of playlists",
- Namespace: exporterName,
- })
- StatsTotalViewers = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_totals_viewers",
- Help: "total amount of viewers",
- Namespace: exporterName,
- })
- StatsTotalEditors = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_totals_editors",
- Help: "total amount of editors",
- Namespace: exporterName,
- })
- StatsTotalAdmins = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_totals_admins",
- Help: "total amount of admins",
- Namespace: exporterName,
- })
- StatsTotalActiveViewers = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_totals_active_viewers",
- Help: "total amount of viewers",
- Namespace: exporterName,
- })
- StatsTotalActiveEditors = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_totals_active_editors",
- Help: "total amount of active editors",
- Namespace: exporterName,
- })
- StatsTotalActiveAdmins = prometheus.NewGauge(prometheus.GaugeOpts{
- Name: "stat_totals_active_admins",
- Help: "total amount of active admins",
- Namespace: exporterName,
- })
- grafanaBuildVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
- Name: "build_info",
- Help: "A metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built",
- Namespace: exporterName,
- }, []string{"version", "revision", "branch", "goversion", "edition"})
- }
- // SetBuildInformation sets the build information for this binary
- func SetBuildInformation(version, revision, branch string) {
- edition := "oss"
- if setting.IsEnterprise {
- edition = "enterprise"
- }
- grafanaBuildVersion.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(1)
- }
- func initMetricVars() {
- prometheus.MustRegister(
- MInstanceStart,
- MPageStatus,
- MApiStatus,
- MProxyStatus,
- MHttpRequestTotal,
- MHttpRequestSummary,
- MApiUserSignUpStarted,
- MApiUserSignUpCompleted,
- MApiUserSignUpInvite,
- MApiDashboardSave,
- MApiDashboardGet,
- MApiDashboardSearch,
- MDataSourceProxyReqTimer,
- MAlertingExecutionTime,
- MApiAdminUserCreate,
- MApiLoginPost,
- MApiLoginOAuth,
- MApiOrgCreate,
- MApiDashboardSnapshotCreate,
- MApiDashboardSnapshotExternal,
- MApiDashboardSnapshotGet,
- MApiDashboardInsert,
- MAlertingResultState,
- MAlertingNotificationSent,
- MAwsCloudWatchGetMetricStatistics,
- MAwsCloudWatchListMetrics,
- MAwsCloudWatchGetMetricData,
- MDBDataSourceQueryByID,
- LDAPUsersSyncExecutionTime,
- MAlertingActiveAlerts,
- MStatTotalDashboards,
- MStatTotalUsers,
- MStatActiveUsers,
- MStatTotalOrgs,
- MStatTotalPlaylists,
- StatsTotalViewers,
- StatsTotalEditors,
- StatsTotalAdmins,
- StatsTotalActiveViewers,
- StatsTotalActiveEditors,
- StatsTotalActiveAdmins,
- grafanaBuildVersion,
- )
- }
- func newCounterVecStartingAtZero(opts prometheus.CounterOpts, labels []string, labelValues ...string) *prometheus.CounterVec {
- counter := prometheus.NewCounterVec(opts, labels)
- for _, label := range labelValues {
- counter.WithLabelValues(label).Add(0)
- }
- return counter
- }
- func newCounterStartingAtZero(opts prometheus.CounterOpts, labelValues ...string) prometheus.Counter {
- counter := prometheus.NewCounter(opts)
- counter.Add(0)
- return counter
- }
|