diff --git a/pkg/infra/metrics/metrics.go b/pkg/infra/metrics/metrics.go index 551d8da8f5a..8c44d8e4665 100644 --- a/pkg/infra/metrics/metrics.go +++ b/pkg/infra/metrics/metrics.go @@ -81,15 +81,6 @@ var ( // MAlertingNotificationSent is a metric counter for how many alert notifications that failed MAlertingNotificationFailed *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 @@ -397,24 +388,6 @@ func init() { Namespace: ExporterName, }, []string{"type"}) - MAwsCloudWatchGetMetricStatistics = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{ - Name: "aws_cloudwatch_get_metric_statistics_total", - Help: "counter for getting metric statistics from aws", - Namespace: ExporterName, - }) - - MAwsCloudWatchListMetrics = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{ - Name: "aws_cloudwatch_list_metrics_total", - Help: "counter for getting list of metrics from aws", - Namespace: ExporterName, - }) - - MAwsCloudWatchGetMetricData = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{ - Name: "aws_cloudwatch_get_metric_data_total", - Help: "counter for getting metric data time series from aws", - Namespace: ExporterName, - }) - MDBDataSourceQueryByID = metricutil.NewCounterStartingAtZero(prometheus.CounterOpts{ Name: "db_datasource_query_by_id_total", Help: "counter for getting datasource by id", @@ -763,9 +736,6 @@ func initMetricVars(reg prometheus.Registerer) { MAlertingResultState, MAlertingNotificationSent, MAlertingNotificationFailed, - MAwsCloudWatchGetMetricStatistics, - MAwsCloudWatchListMetrics, - MAwsCloudWatchGetMetricData, MDBDataSourceQueryByID, LDAPUsersSyncExecutionTime, MRenderingRequestTotal, diff --git a/pkg/tsdb/cloudwatch/clients/metrics.go b/pkg/tsdb/cloudwatch/clients/metrics.go index 28ad4e2bd32..b3648492a59 100644 --- a/pkg/tsdb/cloudwatch/clients/metrics.go +++ b/pkg/tsdb/cloudwatch/clients/metrics.go @@ -5,9 +5,9 @@ import ( "github.com/aws/aws-sdk-go/aws/awsutil" "github.com/aws/aws-sdk-go/service/cloudwatch" - "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/tsdb/cloudwatch/models" "github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources" + "github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils" ) // this client wraps the CloudWatch API and handles pagination and the composition of the MetricResponse DTO @@ -25,7 +25,7 @@ func (l *metricsClient) ListMetricsWithPageLimit(ctx context.Context, params *cl pageNum := 0 err := l.ListMetricsPagesWithContext(ctx, params, func(page *cloudwatch.ListMetricsOutput, lastPage bool) bool { pageNum++ - metrics.MAwsCloudWatchListMetrics.Inc() + utils.QueriesTotalCounter.WithLabelValues(utils.ListMetricsLabel).Inc() metrics, err := awsutil.ValuesAtPath(page, "Metrics") if err == nil { for idx, metric := range metrics { diff --git a/pkg/tsdb/cloudwatch/get_metric_data_executor.go b/pkg/tsdb/cloudwatch/get_metric_data_executor.go index c81688b40da..de89b89af2d 100644 --- a/pkg/tsdb/cloudwatch/get_metric_data_executor.go +++ b/pkg/tsdb/cloudwatch/get_metric_data_executor.go @@ -6,7 +6,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface" - "github.com/grafana/grafana/pkg/infra/metrics" + "github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils" ) func (e *cloudWatchExecutor) executeRequest(ctx context.Context, client cloudwatchiface.CloudWatchAPI, @@ -24,8 +24,7 @@ func (e *cloudWatchExecutor) executeRequest(ctx context.Context, client cloudwat } mdo = append(mdo, resp) - metrics.MAwsCloudWatchGetMetricData.Add(float64(len(metricDataInput.MetricDataQueries))) - + utils.QueriesTotalCounter.WithLabelValues(utils.GetMetricDataLabel).Add(float64(len(metricDataInput.MetricDataQueries))) if resp.NextToken == nil || *resp.NextToken == "" { break } diff --git a/pkg/tsdb/cloudwatch/utils/metrics.go b/pkg/tsdb/cloudwatch/utils/metrics.go new file mode 100644 index 00000000000..07d361ff2ef --- /dev/null +++ b/pkg/tsdb/cloudwatch/utils/metrics.go @@ -0,0 +1,22 @@ +package utils + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +const ( + // Labels for the metric counter query types + + ListMetricsLabel = "list_metrics" + GetMetricDataLabel = "get_metric_data" +) + +var QueriesTotalCounter = promauto.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "grafana_plugin", + Name: "aws_cloudwatch_queries_total", + Help: "Counter for AWS Queries", + }, + []string{"query_type"}, +)