Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.

Commit c258687

Browse files
author
Mathieu
committed
Added support for partial dim
1 parent a637260 commit c258687

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

aws.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,22 @@ func scrape(collector *cwCollector, ch chan<- prometheus.Metric) {
5454
//This map will hold dimensions name which has been already collected
5555
valueCollected := map[string]bool{}
5656

57-
//Check the special case where the user want all the values. A bit "hacky" but will do the job for now
58-
if (len(metric.ConfMetric.DimensionsSelect)==0 && len(metric.ConfMetric.DimensionsSelectRegex)==0 ){
59-
metric.ConfMetric.DimensionsSelectRegex=map[string]string{}
60-
for _,dimension := range metric.ConfMetric.Dimensions {
57+
58+
if len(metric.ConfMetric.DimensionsSelectRegex) == 0 {
59+
metric.ConfMetric.DimensionsSelectRegex = map[string]string{}
60+
}
61+
62+
//Check for dimensions who does not have either select or dimensions select_regex and make them select everything using regex
63+
for _,dimension := range metric.ConfMetric.Dimensions {
64+
_, found := metric.ConfMetric.DimensionsSelect[dimension]
65+
_, found2 := metric.ConfMetric.DimensionsSelectRegex[dimension]
66+
if !found && !found2 {
6167
metric.ConfMetric.DimensionsSelectRegex[dimension]=".*"
6268
}
6369
}
6470

6571

72+
6673
for _, stat := range metric.ConfMetric.Statistics {
6774
params.Statistics = append(params.Statistics, aws.String(stat))
6875
}
@@ -136,6 +143,10 @@ func scrape(collector *cwCollector, ch chan<- prometheus.Metric) {
136143
//Try to match each dimensions to the regex
137144
for _,dim := range met.Dimensions {
138145
dimRegex:=metric.ConfMetric.DimensionsSelectRegex[*dim.Name]
146+
if(dimRegex==""){
147+
dimRegex="\\b"+strings.Join(metric.ConfMetric.DimensionsSelect[*dim.Name],"\\b|\\b")+"\\b"
148+
}
149+
139150
match,_:=regexp.MatchString(dimRegex,*dim.Value)
140151
if match {
141152
dimensions=append(dimensions, &cloudwatch.Dimension{

config.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ tasks:
1010
aws_statistics: [Average]
1111
range_seconds: 86400
1212

13-
- name: billing-per-service
13+
- name: billing-per-service-partial-dim
14+
default_region: us-east-1
15+
metrics:
16+
- aws_namespace: "AWS/Billing"
17+
aws_dimensions: [ServiceName,Currency]
18+
aws_dimensions_select:
19+
ServiceName: [AWSDataTransfer,AWSLambda]
20+
aws_metric_name: EstimatedCharges
21+
aws_statistics: [Average]
22+
range_seconds: 86400
23+
24+
- name: billing-per-service-partial-dim-regex
1425
default_region: us-east-1
1526
metrics:
1627
- aws_namespace: "AWS/Billing"
1728
aws_dimensions: [ServiceName,Currency]
1829
aws_dimensions_select_regex:
1930
ServiceName: AWS.*
20-
Currency: .*
2131
aws_metric_name: EstimatedCharges
2232
aws_statistics: [Average]
2333
range_seconds: 86400
2434

25-
- name: billing-per-service_no_dim
35+
- name: billing-per-service-no-dim
2636
default_region: us-east-1
2737
metrics:
2838
- aws_namespace: "AWS/Billing"

0 commit comments

Comments
 (0)