APIkeys: Add metrics for apikey endpoints (#66732)

add metrics for apikey endpoints
This commit is contained in:
Eric Leijonmarck 2023-04-18 11:12:19 +01:00 committed by GitHub
parent bf3ac0ff18
commit c505d26430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/components/apikeygen" "github.com/grafana/grafana/pkg/components/apikeygen"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/services/apikey" "github.com/grafana/grafana/pkg/services/apikey"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/web" "github.com/grafana/grafana/pkg/web"
@ -64,6 +65,7 @@ func (hs *HTTPServer) GetAPIKeys(c *contextmodel.ReqContext) response.Response {
} }
} }
metrics.MApiAPIkeysGet.Inc()
return response.JSON(http.StatusOK, result) return response.JSON(http.StatusOK, result)
} }
@ -99,6 +101,7 @@ func (hs *HTTPServer) DeleteAPIKey(c *contextmodel.ReqContext) response.Response
return response.Error(status, "Failed to delete API key", err) return response.Error(status, "Failed to delete API key", err)
} }
metrics.MApiAPIkeysDelete.Inc()
return response.Success("API key deleted") return response.Success("API key deleted")
} }
@ -166,6 +169,7 @@ func (hs *HTTPServer) AddAPIKey(c *contextmodel.ReqContext) response.Response {
Key: newKeyInfo.ClientSecret, Key: newKeyInfo.ClientSecret,
} }
metrics.MApiAPIkeysCreate.Inc()
return response.JSON(http.StatusOK, result) return response.JSON(http.StatusOK, result)
} }

View File

@ -109,6 +109,12 @@ var (
// MPublicDashboardDatasourceQuerySuccess is a metric counter for successful queries labelled by datasource // MPublicDashboardDatasourceQuerySuccess is a metric counter for successful queries labelled by datasource
MPublicDashboardDatasourceQuerySuccess *prometheus.CounterVec MPublicDashboardDatasourceQuerySuccess *prometheus.CounterVec
MApiAPIkeysGet prometheus.Counter
MApiAPIkeysCreate prometheus.Counter
MApiAPIkeysDelete prometheus.Counter
) )
// Timers // Timers
@ -446,6 +452,24 @@ func init() {
Namespace: ExporterName, Namespace: ExporterName,
}, []string{"datasource", "status"}, map[string][]string{"status": pubdash.QueryResultStatuses}) }, []string{"datasource", "status"}, map[string][]string{"status": pubdash.QueryResultStatuses})
MApiAPIkeysGet = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_api_keys_get_total",
Help: "counter for getting api keys",
Namespace: ExporterName,
})
MApiAPIkeysCreate = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_api_keys_create_total",
Help: "counter for creating api keys",
Namespace: ExporterName,
})
MApiAPIkeysDelete = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{
Name: "api_api_keys_delete_total",
Help: "counter for deleting api keys",
Namespace: ExporterName,
})
MStatTotalDashboards = prometheus.NewGauge(prometheus.GaugeOpts{ MStatTotalDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_dashboard", Name: "stat_totals_dashboard",
Help: "total amount of dashboards", Help: "total amount of dashboards",
@ -715,5 +739,8 @@ func initMetricVars() {
MPublicDashboardRequestCount, MPublicDashboardRequestCount,
MPublicDashboardDatasourceQuerySuccess, MPublicDashboardDatasourceQuerySuccess,
MStatTotalCorrelations, MStatTotalCorrelations,
MApiAPIkeysGet,
MApiAPIkeysCreate,
MApiAPIkeysDelete,
) )
} }