Public Dashboards: count public dashboards view requests (#52419)

This commit is contained in:
Ezequiel Victorero 2022-07-19 11:50:37 -03:00 committed by GitHub
parent 0300b1c674
commit e0a58300ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -113,7 +113,7 @@ func (hs *HTTPServer) registerRoutes() {
}
if hs.Features.IsEnabled(featuremgmt.FlagPublicDashboards) {
r.Get("/public-dashboards/:accessToken", publicdashboardsapi.SetPublicDashboardFlag(), hs.Index)
r.Get("/public-dashboards/:accessToken", publicdashboardsapi.SetPublicDashboardFlag(), publicdashboardsapi.CountPublicDashboardRequest(), hs.Index)
}
r.Get("/explore", authorize(func(c *models.ReqContext) {

View File

@ -101,6 +101,9 @@ var (
// MAccessEvaluationCount is a metric gauge for total number of evaluation requests
MAccessEvaluationCount prometheus.Counter
// MPublicDashboardRequestCount is a metric counter for public dashboards requests
MPublicDashboardRequestCount prometheus.Counter
)
// Timers
@ -410,6 +413,12 @@ func init() {
Namespace: ExporterName,
})
MPublicDashboardRequestCount = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "public_dashboard_request_count",
Help: "counter for public dashboards requests",
Namespace: ExporterName,
})
MStatTotalDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_dashboard",
Help: "total amount of dashboards",
@ -654,5 +663,6 @@ func initMetricVars() {
StatsTotalLibraryVariables,
StatsTotalDataKeys,
MStatTotalPublicDashboards,
MPublicDashboardRequestCount,
)
}

View File

@ -1,9 +1,18 @@
package api
import "github.com/grafana/grafana/pkg/models"
import (
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/models"
)
func SetPublicDashboardFlag() func(c *models.ReqContext) {
return func(c *models.ReqContext) {
c.IsPublicDashboardView = true
}
}
func CountPublicDashboardRequest() func(c *models.ReqContext) {
return func(c *models.ReqContext) {
metrics.MPublicDashboardRequestCount.Inc()
}
}