-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
57 lines (48 loc) · 2.07 KB
/
update.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
package exporter
import (
"context"
"github.com/prometheus/client_golang/prometheus"
)
// Metrics is a slice of prometheus metrics specific to the scraping process such API call counters
var Metrics = []prometheus.Collector{cloudwatchAPICounter, cloudwatchAPIErrorCounter, cloudwatchGetMetricDataAPICounter, cloudwatchGetMetricStatisticsAPICounter, resourceGroupTaggingAPICounter, autoScalingAPICounter, targetGroupsAPICounter, apiGatewayAPICounter, ec2APICounter, dmsAPICounter, storagegatewayAPICounter}
type LabelSet map[string]struct{}
// 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 ScrapeConf,
registry *prometheus.Registry,
metricsPerQuery int,
labelsSnakeCase bool,
cloudwatchSemaphore, tagSemaphore chan struct{},
cache SessionCache,
observedMetricLabels map[string]LabelSet,
logger Logger,
) {
tagsData, cloudwatchData := scrapeAwsData(
ctx,
config,
metricsPerQuery,
cloudwatchSemaphore,
tagSemaphore,
cache,
logger,
)
metrics, observedMetricLabels, err := migrateCloudwatchToPrometheus(cloudwatchData, labelsSnakeCase, observedMetricLabels)
if err != nil {
logger.Error(err, "Error migrating cloudwatch metrics to prometheus metrics")
return
}
metrics = ensureLabelConsistencyForMetrics(metrics, observedMetricLabels)
metrics = append(metrics, migrateTagsToPrometheus(tagsData, labelsSnakeCase)...)
registry.MustRegister(NewPrometheusCollector(metrics))
}
type Logger interface {
Info(message string, keyvals ...interface{})
Debug(message string, keyvals ...interface{})
Error(err error, message string, keyvals ...interface{})
Warn(message string, keyvals ...interface{})
With(keyvals ...interface{}) Logger
IsDebugEnabled() bool
}