Skip to content

Commit

Permalink
Merge pull request #21 from chaspy/separate-metric
Browse files Browse the repository at this point in the history
Export metrics for each EOL status
  • Loading branch information
chaspy authored Feb 16, 2021
2 parents aa7731d + 0d13f04 commit 360c40e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 10 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ aws_custom_rds_cluster_count{cluster_identifier="video-production-a",engine="aur
aws_custom_rds_cluster_count{cluster_identifier="video-staging-a",engine="aurora-postgresql",engine_version="9.6.17",eol_status="ok"} 1
```

|metric|description|tags|note|
|---------------------------------|-----------------------------------------------|--------------------------------------------------------------|----------|
|aws_custom_rds_eol_status_ok |Number of instances whose EOL status is ok |"cluster_identifier", "engine", "engine_version" | |
|aws_custom_rds_eol_status_alert |Number of instances whose EOL status is alert |"cluster_identifier", "engine", "engine_version" | |
|aws_custom_rds_eol_status_warning|Number of instances whose EOL status is warning|"cluster_identifier", "engine", "engine_version" | |
|aws_custom_rds_eol_status_expired|Number of instances whose EOL status is expired|"cluster_identifier", "engine", "engine_version" | |
|aws_custom_rds_cluster_count |Number of RDS |"cluster_identifier", "engine", "engine_version", "eol_status"|DEPRECATED|

## IAM Role

The following policy must be attached to the AWS role to be executed.
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.37.11 h1:W1gUQxt6jmiUsk2jkTVAlYsd3Sg8bNL2VDcWjrXmD+0=
github.com/aws/aws-sdk-go v1.37.11/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down
106 changes: 96 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type MinimumSupportedInfo struct {
ValidDate string
}

//nolint:gochecknoglobals
var (
//nolint:gochecknoglobals
// deprecated
rdsCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "aws_custom",
Subsystem: "rds",
Expand All @@ -39,6 +40,42 @@ var (
},
[]string{"cluster_identifier", "engine", "engine_version", "eol_status"},
)

okCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "aws_custom",
Subsystem: "rds",
Name: "eol_status_ok",
Help: "Number of instances whose EOL status is ok",
},
[]string{"cluster_identifier", "engine", "engine_version"},
)

warningCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "aws_custom",
Subsystem: "rds",
Name: "eol_status_warning",
Help: "Number of instances whose EOL status is warning",
},
[]string{"cluster_identifier", "engine", "engine_version"},
)

alertCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "aws_custom",
Subsystem: "rds",
Name: "eol_status_alert",
Help: "Number of instances whose EOL status is alert",
},
[]string{"cluster_identifier", "engine", "engine_version"},
)

expiredCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "aws_custom",
Subsystem: "rds",
Name: "eol_status_expired",
Help: "Number of instances whose EOL status is expired",
},
[]string{"cluster_identifier", "engine", "engine_version"},
)
)

func main() {
Expand All @@ -53,6 +90,10 @@ func main() {
}

prometheus.MustRegister(rdsCount)
prometheus.MustRegister(expiredCount)
prometheus.MustRegister(alertCount)
prometheus.MustRegister(warningCount)
prometheus.MustRegister(okCount)

http.Handle("/metrics", promhttp.Handler())

Expand All @@ -72,6 +113,10 @@ func main() {

func snapshot(minimumSupportedInfo []MinimumSupportedInfo) error {
rdsCount.Reset()
okCount.Reset()
warningCount.Reset()
alertCount.Reset()
expiredCount.Reset()

ClusterInfos, err := getRDSClusters()
if err != nil {
Expand All @@ -86,18 +131,59 @@ func snapshot(minimumSupportedInfo []MinimumSupportedInfo) error {
RDSInfos := append(ClusterInfos, InstanceInfos...)

for _, RDSInfo := range RDSInfos {
eolStatus, err := validateEOLStatus(RDSInfo, minimumSupportedInfo)
err := export(RDSInfo, minimumSupportedInfo)
if err != nil {
return fmt.Errorf("failed to validate EOL Status: %w", err)
return fmt.Errorf("failed to export metric: %w. skip rdsInfo %#v", err, RDSInfo)
}
}

labels := prometheus.Labels{
"cluster_identifier": RDSInfo.ClusterIdentifier,
"engine": RDSInfo.Engine,
"engine_version": RDSInfo.EngineVersion,
"eol_status": eolStatus,
}
rdsCount.With(labels).Set(1)
return nil
}

func export(rdsInfo RDSInfo, minimumSupportedInfo []MinimumSupportedInfo) error {
eolStatus, err := validateEOLStatus(rdsInfo, minimumSupportedInfo)
if err != nil {
return fmt.Errorf("failed to validate EOL Status: %w. skip rdsInfo %#v", err, rdsInfo)
}

// deprecated
labels := prometheus.Labels{
"cluster_identifier": rdsInfo.ClusterIdentifier,
"engine": rdsInfo.Engine,
"engine_version": rdsInfo.EngineVersion,
"eol_status": eolStatus,
}
rdsCount.With(labels).Set(1)

newLabels := prometheus.Labels{
"cluster_identifier": rdsInfo.ClusterIdentifier,
"engine": rdsInfo.Engine,
"engine_version": rdsInfo.EngineVersion,
}

switch eolStatus {
case "expired":
expiredCount.With(newLabels).Set(1)
alertCount.With(newLabels).Set(0)
warningCount.With(newLabels).Set(0)
okCount.With(newLabels).Set(0)
case "alert":
expiredCount.With(newLabels).Set(0)
alertCount.With(newLabels).Set(1)
warningCount.With(newLabels).Set(0)
okCount.With(newLabels).Set(0)
case "warning":
expiredCount.With(newLabels).Set(0)
alertCount.With(newLabels).Set(0)
warningCount.With(newLabels).Set(1)
okCount.With(newLabels).Set(0)
case "ok":
expiredCount.With(newLabels).Set(0)
alertCount.With(newLabels).Set(0)
warningCount.With(newLabels).Set(0)
okCount.With(newLabels).Set(1)
default:
log.Printf("eolStatus is not set. RDSInfo %#v skip", rdsInfo)
}

return nil
Expand Down

0 comments on commit 360c40e

Please sign in to comment.