-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtg2prom.go
48 lines (38 loc) · 1.52 KB
/
tg2prom.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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
// Command-line flags
targetGroupARN := flag.String("target-group-arn", "", "The ARN of the target group (required)")
awsProfile := flag.String("aws-profile", "", "AWS profile to use for credentials and configuration (default is used if not provided)")
awsAccessKeyID := flag.String("aws-access-key-id", "", "AWS Access Key ID")
awsSecretAccessKey := flag.String("aws-secret-access-key", "", "AWS Secret Access Key")
listeningPort := flag.Int("listening-port", 0, "The listening port for scraping the metrics (required)")
jobName := flag.String("job-name", "", "The desired name of the job label (required)")
outputFileName := flag.String("output", "", "The desired output file name (required)")
// Custom usage message for the --help flag
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if *targetGroupARN == "" || *listeningPort == 0 || *jobName == "" || *outputFileName == "" {
fmt.Println("Error: All parameters are required.")
flag.Usage()
os.Exit(1)
}
list, err := getPublicIPsFromTargetGroup(*targetGroupARN, *awsProfile, *awsAccessKeyID, *awsSecretAccessKey)
if err != nil {
fmt.Printf("Error: %v\n", err.Error())
os.Exit(1)
}
err = generatePrometheusConfig(list, *jobName, *listeningPort, *outputFileName)
if err != nil {
fmt.Printf("Error: %v\n", err.Error())
os.Exit(1)
}
fmt.Printf("Successfully generated Prometheus targets configuration at '%s'.\n", *outputFileName)
}