Skip to content

Commit

Permalink
Added README, added extra _ between metrics prefix and name and chang…
Browse files Browse the repository at this point in the history
…ed defaults
  • Loading branch information
wcarlsen committed Feb 10, 2023
1 parent ffeb67b commit 6f6e84f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO11MODULE=on go build -mod=mod -a -o

FROM alpine:latest
COPY --from=builder /aws-subnet-exporter /aws-subnet-exporter
COPY ./scripts/run.sh .
RUN chmod +x run.sh
CMD ["./run.sh"]
CMD ["./aws-subnet-exporter"]
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# AWS subnet exporter
Fetch AWS subnet available IP count and expose it as Prometheus metrics. Why? Because AWS does not expose these in CloudWatch and you don't want to run out of available IP's in your subnets.

## Metrics exported
```
# Curl metrics example
curl http://localhost:8080/metrics
# HELP aws_subnet_exporter_available_ips Available IPs in subnets
# TYPE aws_subnet_exporter_available_ips gauge
aws_subnet_exporter_available_ips{az="eu-west-1a",cidrblock="10.103.0.0/28",name="eks_clu_eu-west-1a",subnetid="subnet-XXX",vpcid="vpc-YYY"} 10
...
# HELP aws_subnet_exporter_max_ips Max host IPs in subnet
# TYPE aws_subnet_exporter_max_ips gauge
aws_subnet_exporter_max_ips{az="eu-west-1a",cidrblock="10.103.0.0/28",name="eks_clu_eu-west-1a",subnetid="subnet-XXX",vpcid="vpc-YYY"} 14
...
```

## Assumptions
This service assumes that you subnets have a tag "Name" and that you have exported your AWS access key and secret.

## AWS policy required
You require this policy to your user/role (use roles for best practice) in order to fetch AWS subnet data.
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ec2:DescribeSubnets",
"Resource": "*"
}
]
}
```

## Running
You have to provide an AWS context and I will not cover how to do this here.

```bash
docker run -p 8080:8080 -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa ghcr.io/wcarlsen/aws-subnet-exporter:latest ./aws-subnet-exporter --port="8080" --region="eu-west-1" --filter="*" --period="60" --debug
```
6 changes: 3 additions & 3 deletions cmd/aws-subnet-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const (
)

var (
port = flag.String("port", ":8080", "The port to listen on for HTTP requests.")
port = flag.String("port", "8080", "The port to listen on for HTTP requests.")
region = flag.String("region", "eu-west-1", "AWS region")
filter = flag.String("filter", "*eks*", "Filter subnets by tag regex when calling AWS (assumes tag key is Name")
filter = flag.String("filter", "*", "Filter subnets by tag regex when calling AWS (assumes tag key is Name")
period = flag.Duration("period", 60*time.Second, "Period for calling AWS in seconds")
debug = flag.Bool("debug", false, "Enable debug logging")
)
Expand Down Expand Up @@ -63,5 +63,5 @@ func main() {

log.WithFields(log.Fields{"endpoint": endpoint, "port": port}).Info("Starting metrics web server")
http.Handle(endpoint, prom.Handler)
log.Fatal(http.ListenAndServe(*port, nil))
log.Fatal(http.ListenAndServe(":"+*port, nil))
}
2 changes: 1 addition & 1 deletion pkg/prometheus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
prefix = "aws_subnet_exporter"
prefix = "aws_subnet_exporter_"
)

var (
Expand Down
7 changes: 0 additions & 7 deletions scripts/run.sh

This file was deleted.

0 comments on commit 6f6e84f

Please sign in to comment.