-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporter.go
66 lines (58 loc) · 2.41 KB
/
exporter.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
package exporter
import (
"context"
"github.com/prometheus/client_golang/prometheus"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/config"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/job"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/logging"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/promutil"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/services"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/session"
)
// Metrics is a slice of prometheus metrics specific to the scraping process such API call counters
var Metrics = []prometheus.Collector{
promutil.CloudwatchAPICounter,
promutil.CloudwatchAPIErrorCounter,
promutil.CloudwatchGetMetricDataAPICounter,
promutil.CloudwatchGetMetricStatisticsAPICounter,
promutil.ResourceGroupTaggingAPICounter,
promutil.AutoScalingAPICounter,
promutil.TargetGroupsAPICounter,
promutil.APIGatewayAPICounter,
promutil.Ec2APICounter,
promutil.DmsAPICounter,
promutil.StoragegatewayAPICounter,
}
// UpdateMetrics can be used to scrape metrics from AWS on demand using the provided parameters. Scraped metrics will be added to the provided registry and
// any labels discovered during the scrape will be added to observedMetricLabels with their metric name as the key. Any errors encountered are not returned but
// will be logged and will either fail the scrape or a partial metric result will be added to the registry.
func UpdateMetrics(
ctx context.Context,
config config.ScrapeConf,
registry *prometheus.Registry,
metricsPerQuery int,
labelsSnakeCase bool,
cloudwatchSemaphore, tagSemaphore chan struct{},
cache session.SessionCache,
observedMetricLabels map[string]model.LabelSet,
logger logging.Logger,
) {
tagsData, cloudwatchData := job.ScrapeAwsData(
ctx,
config,
metricsPerQuery,
cloudwatchSemaphore,
tagSemaphore,
cache,
logger,
)
metrics, observedMetricLabels, err := job.MigrateCloudwatchToPrometheus(cloudwatchData, labelsSnakeCase, observedMetricLabels, logger)
if err != nil {
logger.Error(err, "Error migrating cloudwatch metrics to prometheus metrics")
return
}
metrics = job.EnsureLabelConsistencyForMetrics(metrics, observedMetricLabels)
metrics = append(metrics, services.MigrateTagsToPrometheus(tagsData, labelsSnakeCase, logger)...)
registry.MustRegister(promutil.NewPrometheusCollector(metrics))
}