forked from cloudposse/prometheus-to-cloudwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
102 lines (89 loc) · 4.23 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"flag"
"fmt"
"golang.org/x/net/context"
"log"
"os"
"strconv"
"strings"
"time"
)
var (
awsAccessKeyId = flag.String("aws_access_key_id", os.Getenv("AWS_ACCESS_KEY_ID"), "AWS access key Id with permissions to publish CloudWatch metrics")
awsSecretAccessKey = flag.String("aws_secret_access_key", os.Getenv("AWS_SECRET_ACCESS_KEY"), "AWS secret access key with permissions to publish CloudWatch metrics")
cloudWatchNamespace = flag.String("cloudwatch_namespace", os.Getenv("CLOUDWATCH_NAMESPACE"), "CloudWatch Namespace")
cloudWatchRegion = flag.String("cloudwatch_region", os.Getenv("CLOUDWATCH_REGION"), "CloudWatch Region")
cloudWatchPublishTimeout = flag.String("cloudwatch_publish_timeout", os.Getenv("CLOUDWATCH_PUBLISH_TIMEOUT"), "CloudWatch publish timeout in seconds")
prometheusScrapeInterval = flag.String("prometheus_scrape_interval", os.Getenv("PROMETHEUS_SCRAPE_INTERVAL"), "Prometheus scrape interval in seconds")
prometheusScrapeUrl = flag.String("prometheus_scrape_url", os.Getenv("PROMETHEUS_SCRAPE_URL"), "Prometheus scrape URL")
certPath = flag.String("cert_path", os.Getenv("CERT_PATH"), "Path to SSL Certificate file (when using SSL for `prometheus_scrape_url`)")
keyPath = flag.String("key_path", os.Getenv("KEY_PATH"), "Path to Key file (when using SSL for `prometheus_scrape_url`)")
skipServerCertCheck = flag.String("accept_invalid_cert", os.Getenv("ACCEPT_INVALID_CERT"), "Accept any certificate during TLS handshake. Insecure, use only for testing")
additionalDimension = flag.String("additional_dimension", os.Getenv("ADDITIONAL_DIMENSION"), "Additional dimension specified by NAME=VALUE")
)
func main() {
flag.Parse()
if *cloudWatchNamespace == "" {
flag.PrintDefaults()
log.Fatal("prometheus-to-cloudwatch: Error: -cloudwatch_namespace or CLOUDWATCH_NAMESPACE required")
}
if *cloudWatchRegion == "" {
flag.PrintDefaults()
log.Fatal("prometheus-to-cloudwatch: Error: -cloudwatch_region or CLOUDWATCH_REGION required")
}
if *prometheusScrapeUrl == "" {
flag.PrintDefaults()
log.Fatal("prometheus-to-cloudwatch: Error: -prometheus_scrape_url or PROMETHEUS_SCRAPE_URL required")
}
if (*certPath != "" && *keyPath == "") || (*certPath == "" && *keyPath != "") {
flag.PrintDefaults()
log.Fatal("prometheus-to-cloudwatch: Error: when using SSL, both -prometheus_cert_path and -prometheus_key_path are required. If not using SSL, do not provide any of them")
}
var skipCertCheck = true
var err error
if *skipServerCertCheck != "" {
if skipCertCheck, err = strconv.ParseBool(*skipServerCertCheck); err != nil {
log.Fatal("prometheus-to-cloudwatch: Error: ", err)
}
}
var additionalDimensions = map[string]string{}
if *additionalDimension != "" {
kv := strings.SplitN(*additionalDimension, "=", 2)
if len(kv) != 2 {
log.Fatal("prometheus-to-cloudwatch: Error: -additionalDimension must be formated as NAME=VALUE")
}
additionalDimensions[kv[0]] = kv[1]
}
config := &Config{
CloudWatchNamespace: *cloudWatchNamespace,
CloudWatchRegion: *cloudWatchRegion,
PrometheusScrapeUrl: *prometheusScrapeUrl,
PrometheusCertPath: *certPath,
PrometheusKeyPath: *keyPath,
PrometheusSkipServerCertCheck: skipCertCheck,
AwsAccessKeyId: *awsAccessKeyId,
AwsSecretAccessKey: *awsSecretAccessKey,
AdditionalDimensions: additionalDimensions,
}
if *prometheusScrapeInterval != "" {
interval, err := strconv.Atoi(*prometheusScrapeInterval)
if err != nil {
log.Fatal("prometheus-to-cloudwatch: error parsing 'prometheus_scrape_interval': ", err)
}
config.CloudWatchPublishInterval = time.Duration(interval) * time.Second
}
if *cloudWatchPublishTimeout != "" {
timeout, err := strconv.Atoi(*cloudWatchPublishTimeout)
if err != nil {
log.Fatal("prometheus-to-cloudwatch: error parsing 'cloudwatch_publish_timeout': ", err)
}
config.CloudWatchPublishTimeout = time.Duration(timeout) * time.Second
}
bridge, err := NewBridge(config)
if err != nil {
log.Fatal("prometheus-to-cloudwatch: Error: ", err)
}
fmt.Println("prometheus-to-cloudwatch: Starting prometheus-to-cloudwatch bridge")
bridge.Run(context.Background())
}