Skip to content

Add Max Allocated Storage metric for RDS #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM quay.io/app-sre/golang:1.18.5 as builder
FROM public.ecr.aws/docker/library/golang:1.18 as builder
WORKDIR /build
COPY . .
RUN make build

FROM registry.access.redhat.com/ubi8-minimal
FROM public.ecr.aws/amazonlinux/amazonlinux:latest
COPY --from=builder /build/aws-resource-exporter /bin/aws-resource-exporter

EXPOSE 9115
Expand Down
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ This was made as a complement to [CloudWatch Exporter](https://github.com/promet

## Included metadata & metrics

| Service | Metric | Description |
|---------|-----------------------------|-----------------------------------------------------|
| RDS | allocatedstorage | The amount of allocated storage in GB |
| RDS | dbinstanceclass | The DB instance class (type) |
| RDS | dbinstancestatus | The instance status |
| RDS | engineversion | The DB engine type and version |
| RDS | pendingmaintenanceactions | The pending maintenance actions for a RDS instance |
| RDS | logs_amount | The amount of log files present in the RDS Instance |
| RDS | logsstorage_size_bytes | The amount of storage used by the log files nstance |
| VPC | vpcsperregion | Quota and usage of the VPCs per region |
| VPC | subnetspervpc | Quota and usage of subnets per VPC |
| VPC | interfacevpcendpointspervpc | Quota and usage of interface endpoints per VPC |
| VPC | routetablespervpc | Quota and usage of routetables per VPC |
| VPC | routesperroutetable | Quota and usage of the routes per routetable |
| VPC | ipv4blockspervpc | Quota and usage of ipv4 blocks per VPC |
| EC2 | transitgatewaysperregion | Quota and usage of transitgateways per region |
| Route53 | recordsperhostedzone | Quota and usage of resource records per Hosted Zone |
| Service | Metric | Description |
|---------|-----------------------------|---------------------------------------------------------------------------|
| RDS | allocatedstorage | The amount of allocated storage in GB |
| RDS | maxallocatedstorage | The amount of max allocated storage for RDS storage autoscaling in bytes. |
| RDS | dbinstanceclass | The DB instance class (type) |
| RDS | dbinstancestatus | The instance status |
| RDS | engineversion | The DB engine type and version |
| RDS | pendingmaintenanceactions | The pending maintenance actions for a RDS instance |
| RDS | logs_amount | The amount of log files present in the RDS Instance |
| RDS | logsstorage_size_bytes | The amount of storage used by the log files nstance |
| VPC | vpcsperregion | Quota and usage of the VPCs per region |
| VPC | subnetspervpc | Quota and usage of subnets per VPC |
| VPC | interfacevpcendpointspervpc | Quota and usage of interface endpoints per VPC |
| VPC | routetablespervpc | Quota and usage of routetables per VPC |
| VPC | routesperroutetable | Quota and usage of the routes per routetable |
| VPC | ipv4blockspervpc | Quota and usage of ipv4 blocks per VPC |
| EC2 | transitgatewaysperregion | Quota and usage of transitgateways per region |
| Route53 | recordsperhostedzone | Quota and usage of resource records per Hosted Zone |


## Running this software
Expand Down
23 changes: 23 additions & 0 deletions pkg/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ var DBMaxConnections = map[string]map[string]int64{
"default.postgres13": 5000,
"default.postgres14": 5000,
},
"db.m5d.large": map[string]int64{
"default": 830,
"default.postgres10": 830,
"default.postgres11": 830,
"default.postgres12": 830,
"default.postgres13": 830,
"default.postgres14": 830,
"default.postgres15": 830,
},
"db.r4.large": map[string]int64{
"default": 1301,
"default.mysql5.7": 1301,
Expand Down Expand Up @@ -264,6 +273,12 @@ var AllocatedStorage *prometheus.Desc = prometheus.NewDesc(
[]string{"aws_region", "dbinstance_identifier"},
nil,
)
var MaxAllocatedStorage *prometheus.Desc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "rds_maxallocatedstorage"),
"The amount of max allocated storage for RDS storage autoscaling in bytes.",
[]string{"aws_region", "dbinstance_identifier"},
nil,
)
var DBInstanceClass *prometheus.Desc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "rds_dbinstanceclass"),
"The DB instance class (type).",
Expand Down Expand Up @@ -495,10 +510,17 @@ func (e *RDSExporter) addAllInstanceMetrics(sessionIndex int, instances []*rds.D
if instance.LatestRestorableTime != nil {
restoreTime = float64(instance.LatestRestorableTime.Unix())
}

var maxAllocatedStorageValue = 0.0
if instance.MaxAllocatedStorage != nil {
maxAllocatedStorageValue = float64(*instance.MaxAllocatedStorage*1024*1024*1024)
}

e.cache.AddMetric(prometheus.MustNewConstMetric(LatestRestorableTime, prometheus.CounterValue, restoreTime, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))

e.cache.AddMetric(prometheus.MustNewConstMetric(MaxConnections, prometheus.GaugeValue, float64(maxConnections), e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
e.cache.AddMetric(prometheus.MustNewConstMetric(AllocatedStorage, prometheus.GaugeValue, float64(*instance.AllocatedStorage*1024*1024*1024), e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
e.cache.AddMetric(prometheus.MustNewConstMetric(MaxAllocatedStorage, prometheus.GaugeValue, maxAllocatedStorageValue, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier))
e.cache.AddMetric(prometheus.MustNewConstMetric(DBInstanceStatus, prometheus.GaugeValue, 1, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier, *instance.DBInstanceStatus))
e.cache.AddMetric(prometheus.MustNewConstMetric(EngineVersion, prometheus.GaugeValue, 1, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier, *instance.Engine, *instance.EngineVersion))
e.cache.AddMetric(prometheus.MustNewConstMetric(DBInstanceClass, prometheus.GaugeValue, 1, e.getRegion(sessionIndex), *instance.DBInstanceIdentifier, *instance.DBInstanceClass))
Expand Down Expand Up @@ -551,6 +573,7 @@ func (e *RDSExporter) addAllPendingMaintenancesMetrics(ctx context.Context, sess
// Describe is used by the Prometheus client to return a description of the metrics
func (e *RDSExporter) Describe(ch chan<- *prometheus.Desc) {
ch <- AllocatedStorage
ch <- MaxAllocatedStorage
ch <- DBInstanceClass
ch <- DBInstanceStatus
ch <- EngineVersion
Expand Down
3 changes: 2 additions & 1 deletion pkg/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func createTestDBInstances() []*rds.DBInstance {
PubliclyAccessible: aws.Bool(false),
StorageEncrypted: aws.Bool(false),
AllocatedStorage: aws.Int64(1024),
MaxAllocatedStorage: aws.Int64(1024),
DBInstanceStatus: aws.String("on fire"),
Engine: aws.String("SQL"),
EngineVersion: aws.String("1000"),
Expand Down Expand Up @@ -87,7 +88,7 @@ func TestAddAllInstanceMetrics(t *testing.T) {
assert.Len(t, x.cache.GetAllMetrics(), 0)

x.addAllInstanceMetrics(0, createTestDBInstances())
assert.Len(t, x.cache.GetAllMetrics(), 9)
assert.Len(t, x.cache.GetAllMetrics(), 10)
}

func TestAddAllPendingMaintenancesMetrics(t *testing.T) {
Expand Down