-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 17b8c93
Showing
7 changed files
with
879 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:1.20 AS builder | ||
WORKDIR /build | ||
COPY . ./ | ||
RUN CGO_ENABLED=0 go build | ||
|
||
FROM scratch | ||
COPY --from=builder /build/docker_stats_exporter /docker_stats_exporter | ||
ENTRYPOINT ["/docker_stats_exporter"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
release: \ | ||
darwin/amd64 \ | ||
darwin/arm64 \ | ||
linux/amd64 \ | ||
linux/arm \ | ||
linux/arm64 \ | ||
windows/amd64 \ | ||
|
||
clean: | ||
$(RM) -r release | ||
|
||
NAME := $(shell go list) | ||
VERSION := $(shell git name-rev --tags --name-only HEAD) | ||
DISTS := $(shell go tool dist list) | ||
$(DISTS): GOOS = $(firstword $(subst /, ,$@)) | ||
$(DISTS): GOARCH = $(lastword $(subst /, ,$@)) | ||
$(DISTS): | ||
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="-buildid= -s -w" -trimpath -o release/$(NAME)-$(VERSION)-$(GOOS)-$(GOARCH)$(if $(filter windows,$(GOOS)),.exe,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Docker Stats Exporter | ||
|
||
Prometheus exporter for Docker containers resources usage. | ||
|
||
The values exported reflect the output of the [`docker stats` command](https://docs.docker.com/engine/reference/commandline/stats/). | ||
|
||
## Usage | ||
|
||
The exporter can be started without configuration and metrics will be exposed at http://0.0.0.0:9338/metrics. | ||
|
||
```console | ||
$ docker_stats_exporter | ||
Listening on http://:9338... | ||
``` | ||
|
||
### Docker Compose | ||
|
||
```yaml | ||
services: | ||
docker_stats_exporter: | ||
build: https://github.com/jan4843/docker_stats_exporter.git | ||
environment: | ||
LABEL_state: '{{.Container.State}}' | ||
LABEL_compose_project: '{{index .Container.Labels "com.docker.compose.project"}}' | ||
ports: | ||
- 9338:9338 | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
``` | ||
## Configuration | ||
### Docker Host | ||
By default, metrics are retrieved from the Docker socket at `/var/run/docker.sock`, but a different Docker Engine context can be configured via environmental variables such as `DOCKER_HOST` as explained in the [Docker documentation](https://docs.docker.com/desktop/faqs/general/#how-do-i-connect-to-the-remote-docker-engine-api). | ||
|
||
### Custom Metric Labels | ||
|
||
The only label exposed for all metrics is `name`, the container name. | ||
|
||
To expose additional labels, environmental variables with a `LABEL_` prefix are used. The environmental variable name (excluding the prefix) is used as the metric name, and its value [Go-templated](https://pkg.go.dev/text/template) on a [`Container` struct](https://pkg.go.dev/github.com/docker/docker/api/types#Container). | ||
|
||
See the Docker Compose example above adding the `state` and `compose_project` metric labels. | ||
|
||
## Metrics | ||
|
||
The metric `docker_container_info` is available for all containers, including non-running ones, and always has a static value of 1. | ||
|
||
```ini | ||
# TYPE docker_container_info gauge | ||
docker_container_info{name="nginx"} 1 | ||
docker_container_info{name="redis"} 1 | ||
# TYPE docker_container_cpu_seconds_total counter | ||
docker_container_cpu_seconds_total{name="nginx"} 0.138186 | ||
# TYPE docker_container_memory_usage_bytes gauge | ||
docker_container_memory_usage_bytes{name="nginx"} 4.28032e+06 | ||
# TYPE docker_container_memory_limit_bytes gauge | ||
docker_container_memory_limit_bytes{name="nginx"} 3.521634304e+09 | ||
# TYPE docker_container_network_rx_bytes_total counter | ||
docker_container_network_rx_bytes_total{name="nginx"} 6062 | ||
# TYPE docker_container_network_tx_bytes_total counter | ||
docker_container_network_tx_bytes_total{name="nginx"} 9047 | ||
# TYPE docker_container_blkio_read_bytes_total counter | ||
docker_container_blkio_read_bytes_total{name="nginx"} 77824 | ||
# TYPE docker_container_blkio_write_bytes_total counter | ||
docker_container_blkio_write_bytes_total{name="nginx"} 8192 | ||
# TYPE docker_container_pids gauge | ||
docker_container_pids{name="nginx"} 5 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module docker_stats_exporter | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/docker/docker v23.0.3+incompatible | ||
github.com/prometheus/client_golang v1.14.0 | ||
) | ||
|
||
require ( | ||
github.com/Microsoft/go-winio v0.6.0 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/docker/distribution v2.8.1+incompatible // indirect | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.0.2 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/prometheus/client_model v0.3.0 // indirect | ||
github.com/prometheus/common v0.37.0 // indirect | ||
github.com/prometheus/procfs v0.8.0 // indirect | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect | ||
golang.org/x/tools v0.1.12 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
) |
Oops, something went wrong.