diff --git a/pkg/api/api.go b/pkg/api/api.go index 8eac11dac35..58789b610ba 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -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) { diff --git a/pkg/infra/metrics/metrics.go b/pkg/infra/metrics/metrics.go index 788e9702c59..c3dfce10fcc 100644 --- a/pkg/infra/metrics/metrics.go +++ b/pkg/infra/metrics/metrics.go @@ -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, ) } diff --git a/pkg/services/publicdashboards/api/middleware.go b/pkg/services/publicdashboards/api/middleware.go index f7ba59d587a..e31a461d2b3 100644 --- a/pkg/services/publicdashboards/api/middleware.go +++ b/pkg/services/publicdashboards/api/middleware.go @@ -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() + } +}