forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetrics.go
781 lines (634 loc) · 27.4 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
package metrics
import (
"runtime"
"github.com/prometheus/client_golang/prometheus"
"github.com/grafana/grafana/pkg/infra/metrics/metricutil"
"github.com/grafana/grafana/pkg/services/accesscontrol"
pubdash "github.com/grafana/grafana/pkg/services/publicdashboards/models"
"github.com/grafana/grafana/pkg/setting"
)
// ExporterName is used as namespace for exposing prometheus metrics
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
// 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
// MApiLoginSAML is a metric api login SAML counter
MApiLoginSAML 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
// MAlertingNotificationSent is a metric counter for how many alert notifications that failed
MAlertingNotificationFailed *prometheus.CounterVec
// 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
// MRenderingRequestTotal is a metric counter for image rendering requests
MRenderingRequestTotal *prometheus.CounterVec
// MRenderingQueue is a metric gauge for image rendering queue size
MRenderingQueue prometheus.Gauge
// MAccessEvaluationCount is a metric gauge for total number of evaluation requests
MAccessEvaluationCount prometheus.Counter
// MAccessPermissionsCacheUsage is a metric counter for cache usage
MAccessPermissionsCacheUsage *prometheus.CounterVec
// MAccessSearchUserPermissionsCacheUsage is a metric counter for cache usage
MAccessSearchUserPermissionsCacheUsage *prometheus.CounterVec
// MPublicDashboardRequestCount is a metric counter for public dashboards requests
MPublicDashboardRequestCount prometheus.Counter
// MPublicDashboardDatasourceQuerySuccess is a metric counter for successful queries labelled by datasource
MPublicDashboardDatasourceQuerySuccess *prometheus.CounterVec
// MFolderIDsAPICount is a metric counter for folder ids count in the api package
MFolderIDsAPICount *prometheus.CounterVec
// MFolderIDsServicesCount is a metric counter for folder ids count in the services package
MFolderIDsServiceCount *prometheus.CounterVec
)
// Timers
var (
// MDataSourceProxyReqTimer is a metric summary for dataproxy request duration
MDataSourceProxyReqTimer prometheus.Summary
// MAlertingExecutionTime is a metric summary of alert execution duration
MAlertingExecutionTime prometheus.Summary
// MRenderingSummary is a metric summary for image rendering request duration
MRenderingSummary *prometheus.SummaryVec
// MRenderingUserLookupSummary is a metric summary for image rendering user lookup duration
MRenderingUserLookupSummary *prometheus.SummaryVec
// MAccessPermissionsSummary is a metric summary for loading permissions request duration when evaluating access
MAccessPermissionsSummary prometheus.Histogram
// MSearchPermissionsSummary is a metric summary for searching permissions request duration
MAccessSearchPermissionsSummary prometheus.Histogram
// MAccessEvaluationsSummary is a metric summary for loading permissions request duration when evaluating access
MAccessEvaluationsSummary prometheus.Histogram
)
// StatTotals
var (
// MAlertingActiveAlerts is a metric amount of active alerts
MAlertingActiveAlerts prometheus.Gauge
// MStatTotalDashboards is a metric total amount of dashboards
MStatTotalDashboards prometheus.Gauge
// MStatTotalFolders is a metric total amount of folders
MStatTotalFolders prometheus.Gauge
// MStatTotalUsers is a metric total amount of users
MStatTotalUsers prometheus.Gauge
// MStatTotalTeams is a metric total amount of teams
MStatTotalTeams 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
// StatsTotalDataSources is a metric total number of defined datasources, labeled by pluginId
StatsTotalDataSources *prometheus.GaugeVec
// StatsTotalAnnotations is a metric of total number of annotations stored in Grafana.
StatsTotalAnnotations prometheus.Gauge
// StatsTotalAlertRules is a metric of total number of alert rules stored in Grafana.
StatsTotalAlertRules prometheus.Gauge
// StatsTotalRuleGroups is a metric of total number of alert rule groups stored in Grafana.
StatsTotalRuleGroups prometheus.Gauge
// StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana.
StatsTotalDashboardVersions prometheus.Gauge
grafanaPluginBuildInfoDesc *prometheus.GaugeVec
// StatsTotalLibraryPanels is a metric of total number of library panels stored in Grafana.
StatsTotalLibraryPanels prometheus.Gauge
// StatsTotalLibraryVariables is a metric of total number of library variables stored in Grafana.
StatsTotalLibraryVariables prometheus.Gauge
// StatsTotalDataKeys is a metric of total number of data keys stored in Grafana.
StatsTotalDataKeys *prometheus.GaugeVec
// MStatTotalPublicDashboards is a metric total amount of public dashboards
MStatTotalPublicDashboards prometheus.Gauge
// MStatTotalCorrelations is a metric total amount of correlations
MStatTotalCorrelations prometheus.Gauge
)
const (
// FolderID API
GetAlerts string = "GetAlerts"
GetDashboard string = "GetDashboard"
RestoreDashboardVersion string = "RestoreDashboardVersion"
GetFolderByID string = "GetFolderByID"
GetFolderDescendantCounts string = "GetFolderDescendantCounts"
SearchFolders string = "searchFolders"
GetFolderPermissionList string = "GetFolderPermissionList"
UpdateFolderPermissions string = "UpdateFolderPermissions"
GetFolderACL string = "getFolderACL"
Search string = "Search"
GetDashboardACL string = "getDashboardACL"
NewToFolderDTO string = "newToFolderDto"
GetFolders string = "GetFolders"
// FolderID services
Folder string = "folder"
Dashboard string = "dashboards"
LibraryElements string = "libraryelements"
LibraryPanels string = "librarypanels"
NGAlerts string = "ngalert"
Provisioning string = "provisioning"
PublicDashboards string = "publicdashboards"
AccessControl string = "accesscontrol"
Guardian string = "guardian"
DashboardImport string = "dashboardimport"
)
func init() {
httpStatusCodes := []string{"200", "404", "500", "unknown"}
objectiveMap := map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
apiFolderIDMethods := []string{GetAlerts, GetDashboard, RestoreDashboardVersion, GetFolderByID, GetFolderDescendantCounts, SearchFolders, GetFolderPermissionList, UpdateFolderPermissions, GetFolderACL, Search, GetDashboardACL, NewToFolderDTO, GetFolders}
folderIDServices := []string{Folder, Dashboard, LibraryElements, LibraryPanels, NGAlerts, Provisioning, PublicDashboards, AccessControl, Guardian, Search, DashboardImport}
MInstanceStart = prometheus.NewCounter(prometheus.CounterOpts{
Name: "instance_start_total",
Help: "counter for started instances",
Namespace: ExporterName,
})
MPageStatus = metricutil.NewCounterVecStartingAtZero(
prometheus.CounterOpts{
Name: "page_response_status_total",
Help: "page http response status",
Namespace: ExporterName,
}, []string{"code"}, map[string][]string{"code": httpStatusCodes})
MApiStatus = metricutil.NewCounterVecStartingAtZero(
prometheus.CounterOpts{
Name: "api_response_status_total",
Help: "api http response status",
Namespace: ExporterName,
}, []string{"code"}, map[string][]string{"code": httpStatusCodes})
MProxyStatus = metricutil.NewCounterVecStartingAtZero(
prometheus.CounterOpts{
Name: "proxy_response_status_total",
Help: "proxy http response status",
Namespace: ExporterName,
}, []string{"code"}, map[string][]string{"code": httpStatusCodes})
MApiUserSignUpStarted = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_user_signup_started_total",
Help: "amount of users who started the signup flow",
Namespace: ExporterName,
})
MApiUserSignUpCompleted = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_user_signup_completed_total",
Help: "amount of users who completed the signup flow",
Namespace: ExporterName,
})
MApiUserSignUpInvite = metricutil.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",
Objectives: objectiveMap,
Namespace: ExporterName,
})
MApiDashboardGet = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "api_dashboard_get_milliseconds",
Help: "summary for dashboard get duration",
Objectives: objectiveMap,
Namespace: ExporterName,
})
MApiDashboardSearch = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "api_dashboard_search_milliseconds",
Help: "summary for dashboard search duration",
Objectives: objectiveMap,
Namespace: ExporterName,
})
MApiAdminUserCreate = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_admin_user_created_total",
Help: "api admin user created counter",
Namespace: ExporterName,
})
MApiLoginPost = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_login_post_total",
Help: "api login post counter",
Namespace: ExporterName,
})
MApiLoginOAuth = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_login_oauth_total",
Help: "api login oauth counter",
Namespace: ExporterName,
})
MApiLoginSAML = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_login_saml_total",
Help: "api login saml counter",
Namespace: ExporterName,
})
MApiOrgCreate = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_org_create_total",
Help: "api org created counter",
Namespace: ExporterName,
})
MApiDashboardSnapshotCreate = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_dashboard_snapshot_create_total",
Help: "dashboard snapshots created",
Namespace: ExporterName,
})
MApiDashboardSnapshotExternal = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_dashboard_snapshot_external_total",
Help: "external dashboard snapshots created",
Namespace: ExporterName,
})
MApiDashboardSnapshotGet = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_dashboard_snapshot_get_total",
Help: "loaded dashboards",
Namespace: ExporterName,
})
MApiDashboardInsert = metricutil.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 have been sent",
Namespace: ExporterName,
}, []string{"type"})
MAlertingNotificationFailed = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "alerting_notification_failed_total",
Help: "counter for how many alert notifications have failed",
Namespace: ExporterName,
}, []string{"type"})
MDBDataSourceQueryByID = metricutil.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",
Objectives: objectiveMap,
Namespace: ExporterName,
})
MRenderingRequestTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rendering_request_total",
Help: "counter for rendering requests",
Namespace: ExporterName,
},
[]string{"status", "type"},
)
MRenderingSummary = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "rendering_request_duration_milliseconds",
Help: "summary of rendering request duration",
Objectives: objectiveMap,
Namespace: ExporterName,
},
[]string{"status", "type"},
)
MRenderingUserLookupSummary = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "rendering_user_lookup_duration_milliseconds",
Help: "summary of rendering user lookup duration",
Objectives: objectiveMap,
Namespace: ExporterName,
},
[]string{"success", "from"},
)
MRenderingQueue = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "rendering_queue_size",
Help: "size of rendering queue",
Namespace: ExporterName,
})
MDataSourceProxyReqTimer = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "api_dataproxy_request_all_milliseconds",
Help: "summary for dataproxy request duration",
Objectives: objectiveMap,
Namespace: ExporterName,
})
MAlertingExecutionTime = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "alerting_execution_time_milliseconds",
Help: "summary of alert execution duration",
Objectives: objectiveMap,
Namespace: ExporterName,
})
MAlertingActiveAlerts = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "alerting_active_alerts",
Help: "amount of active alerts",
Namespace: ExporterName,
})
MPublicDashboardRequestCount = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "public_dashboard_request_count",
Help: "counter for public dashboards requests",
Namespace: ExporterName,
})
MPublicDashboardDatasourceQuerySuccess = metricutil.NewCounterVecStartingAtZero(prometheus.CounterOpts{
Name: "public_dashboard_datasource_query_success",
Help: "counter for queries to public dashboard datasources labelled by datasource type and success status success/failed",
Namespace: ExporterName,
}, []string{"datasource", "status"}, map[string][]string{"status": pubdash.QueryResultStatuses})
MFolderIDsAPICount = metricutil.NewCounterVecStartingAtZero(prometheus.CounterOpts{
Name: "folder_id_api_count",
Help: "counter for folder id usage in api package",
Namespace: ExporterName,
}, []string{"method"}, map[string][]string{"method": apiFolderIDMethods})
MFolderIDsServiceCount = metricutil.NewCounterVecStartingAtZero(prometheus.CounterOpts{
Name: "folder_id_service_count",
Help: "counter for folder id usage in service package",
Namespace: ExporterName,
}, []string{"service"}, map[string][]string{"service": folderIDServices})
MStatTotalDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_dashboard",
Help: "total amount of dashboards",
Namespace: ExporterName,
})
MStatTotalFolders = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_folder",
Help: "total amount of folders",
Namespace: ExporterName,
})
MStatTotalUsers = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_total_users",
Help: "total amount of users",
Namespace: ExporterName,
})
MStatTotalTeams = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_total_teams",
Help: "total amount of teams",
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 active 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,
})
StatsTotalDataSources = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "stat_totals_datasource",
Help: "total number of defined datasources, labeled by pluginId",
Namespace: ExporterName,
}, []string{"plugin_id"})
grafanaPluginBuildInfoDesc = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "plugin_build_info",
Help: "A metric with a constant '1' value labeled by pluginId, pluginType and version from which Grafana plugin was built",
Namespace: ExporterName,
}, []string{"plugin_id", "plugin_type", "version", "signature_status"})
StatsTotalDashboardVersions = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_dashboard_versions",
Help: "total amount of dashboard versions in the database",
Namespace: ExporterName,
})
StatsTotalAnnotations = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_annotations",
Help: "total amount of annotations in the database",
Namespace: ExporterName,
})
StatsTotalAlertRules = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_alert_rules",
Help: "total amount of alert rules in the database",
Namespace: ExporterName,
})
StatsTotalRuleGroups = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_rule_groups",
Help: "total amount of alert rule groups in the database",
Namespace: ExporterName,
})
MAccessPermissionsSummary = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "access_permissions_duration",
Help: "Histogram for the runtime of permissions check function.",
Buckets: prometheus.ExponentialBuckets(0.00001, 4, 10),
})
MAccessEvaluationsSummary = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "access_evaluation_duration",
Help: "Histogram for the runtime of evaluation function.",
Buckets: prometheus.ExponentialBuckets(0.00001, 4, 10),
})
MAccessEvaluationCount = prometheus.NewCounter(prometheus.CounterOpts{
Name: "access_evaluation_count",
Help: "number of evaluation calls",
Namespace: ExporterName,
})
MAccessSearchPermissionsSummary = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "access_search_permissions_duration",
Help: "Histogram for the runtime of permissions search function",
Buckets: prometheus.ExponentialBuckets(0.001, 10, 6),
})
MAccessPermissionsCacheUsage = metricutil.NewCounterVecStartingAtZero(prometheus.CounterOpts{
Name: "access_permissions_cache_usage",
Help: "access control permissions cache hit/miss",
Namespace: ExporterName,
}, []string{"status"}, map[string][]string{"status": accesscontrol.CacheUsageStatuses})
MAccessSearchUserPermissionsCacheUsage = metricutil.NewCounterVecStartingAtZero(prometheus.CounterOpts{
Name: "access_search_user_permissions_cache_usage",
Help: "access control search user permissions cache hit/miss",
Namespace: ExporterName,
}, []string{"status"}, map[string][]string{"status": accesscontrol.CacheUsageStatuses})
StatsTotalLibraryPanels = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_library_panels",
Help: "total amount of library panels in the database",
Namespace: ExporterName,
})
StatsTotalLibraryVariables = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_library_variables",
Help: "total amount of library variables in the database",
Namespace: ExporterName,
})
StatsTotalDataKeys = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "stat_totals_data_keys",
Help: "total amount of data keys in the database",
Namespace: ExporterName,
}, []string{"active"})
MStatTotalPublicDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_public_dashboard",
Help: "total amount of public dashboards",
Namespace: ExporterName,
})
MStatTotalCorrelations = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_correlations",
Help: "total amount of correlations",
Namespace: ExporterName,
})
}
// SetBuildInformation sets the build information for this binary
func SetBuildInformation(reg prometheus.Registerer, version, revision, branch string, buildTimestamp int64) {
edition := "oss"
if setting.IsEnterprise {
edition = "enterprise"
}
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"})
grafanaBuildTimestamp := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "build_timestamp",
Help: "A metric exposing when the binary was built in epoch",
Namespace: ExporterName,
}, []string{"version", "revision", "branch", "goversion", "edition"})
reg.MustRegister(grafanaBuildVersion, grafanaBuildTimestamp)
grafanaBuildVersion.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(1)
grafanaBuildTimestamp.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(float64(buildTimestamp))
}
// SetEnvironmentInformation exposes environment values provided by the operators as an `_info` metric.
// If there are no environment metrics labels configured, this metric will not be exposed.
func SetEnvironmentInformation(reg prometheus.Registerer, labels map[string]string) error {
if len(labels) == 0 {
return nil
}
grafanaEnvironmentInfo := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "environment_info",
Help: "A metric with a constant '1' value labeled by environment information about the running instance.",
Namespace: ExporterName,
ConstLabels: labels,
})
reg.MustRegister(grafanaEnvironmentInfo)
grafanaEnvironmentInfo.Set(1)
return nil
}
func SetPluginBuildInformation(pluginID, pluginType, version, signatureStatus string) {
grafanaPluginBuildInfoDesc.WithLabelValues(pluginID, pluginType, version, signatureStatus).Set(1)
}
func initMetricVars(reg prometheus.Registerer) {
reg.MustRegister(
MInstanceStart,
MPageStatus,
MApiStatus,
MProxyStatus,
MApiUserSignUpStarted,
MApiUserSignUpCompleted,
MApiUserSignUpInvite,
MApiDashboardSave,
MApiDashboardGet,
MApiDashboardSearch,
MDataSourceProxyReqTimer,
MAlertingExecutionTime,
MApiAdminUserCreate,
MApiLoginPost,
MApiLoginOAuth,
MApiLoginSAML,
MApiOrgCreate,
MApiDashboardSnapshotCreate,
MApiDashboardSnapshotExternal,
MApiDashboardSnapshotGet,
MApiDashboardInsert,
MAlertingResultState,
MAlertingNotificationSent,
MAlertingNotificationFailed,
MDBDataSourceQueryByID,
LDAPUsersSyncExecutionTime,
MRenderingRequestTotal,
MRenderingSummary,
MRenderingUserLookupSummary,
MRenderingQueue,
MAccessPermissionsSummary,
MAccessEvaluationsSummary,
MAccessSearchPermissionsSummary,
MAccessEvaluationCount,
MAccessPermissionsCacheUsage,
MAccessSearchUserPermissionsCacheUsage,
MAlertingActiveAlerts,
MStatTotalDashboards,
MStatTotalFolders,
MStatTotalUsers,
MStatTotalTeams,
MStatActiveUsers,
MStatTotalOrgs,
MStatTotalPlaylists,
StatsTotalViewers,
StatsTotalEditors,
StatsTotalAdmins,
StatsTotalActiveViewers,
StatsTotalActiveEditors,
StatsTotalActiveAdmins,
StatsTotalDataSources,
grafanaPluginBuildInfoDesc,
StatsTotalDashboardVersions,
StatsTotalAnnotations,
StatsTotalAlertRules,
StatsTotalRuleGroups,
StatsTotalLibraryPanels,
StatsTotalLibraryVariables,
StatsTotalDataKeys,
MStatTotalPublicDashboards,
MPublicDashboardRequestCount,
MPublicDashboardDatasourceQuerySuccess,
MStatTotalCorrelations,
MFolderIDsAPICount,
MFolderIDsServiceCount,
)
}