Code Monkey home page Code Monkey logo

docker_stats_exporter's Introduction

Docker Stats exporter for Prometheus

This exporter uses Apocas's Dockerode library.

This exporter was created because the official Docker exporter only exports engine metrics not containers', and the alternative Google's cAdvisor uses quite a lot of resources to run.

The output essentially mirrors the CLI output of docker stats.

Usage

Arguments

--port     9487         Exporter listens on this port (default = 9487)
--interval 15           Polling interval in seconds (default = 15, minimum 3)
--hostip   127.0.0.1    Docker engine IP to connect to (if using HTTP)
--hostport 2375         Docker engine port to connect to (if using HTTP)
--collectdefault        Collect default Prometheus metrics as well (default = false)

If no hostip and hostport provided, it defaults to connect via socket to /var/run/docker.sock.

Environment Variables

The arguments can also be set as env variables instead. Useful if you're using it in a Docker container.

  1. DOCKERSTATS_PORT
  2. DOCKERSTATS_INTERVAL
  3. DOCKERSTATS_HOSTIP
  4. DOCKERSTATS_HOSTPORT
  5. DOCKERSTATS_DEFAULTMETRICS

Installation

From Source

Node.js 14 is required to run it.

git clone [email protected]:wywywywy/docker_stats_exporter.git
cd docker_stats_exporter
npm ci
npm start

With Docker

docker run -d --restart=always -p 9487:9487 -v /var/run/docker.sock:/var/run/docker.sock wywywywy/docker_stats_exporter:latest

Prometheus Config

Add this to prometheus.yml and change the IP/port if needed.

- job_name: 'docker_stats_exporter'
    metrics_path: /
    static_configs:
    - targets:
        - '127.0.0.1:9487'

Notes on Metrics

If you don't see any memory metrics, try to run docker stats to see if the memory usage ever goes above zero. If not, that means cgroup memory support is not enabled in the kernel, which is most likely the reason if you're using Raspberry Pi OS.

See this issue for instructions to have it enabled: moby/moby#18420

Notes on Performance

Because of the way docker stats works, it always takes at least 2 seconds to output the results. Basically it takes a snapshot, then after a second it takes another snapshot to compare the results.

So there is no point pooling the Docker engine more than once every 3 or so seconds.

Also because docker stats runs one process for each container to gather metrics, this exporter is not suitable for hosts that have a large number (hundreds) of containers.

TODO

  1. Block IO metrics
  2. Other useful metrics not in docker stats

Contributing

Yes, contributions are always welcome.
Fork it, clone it, submit a pull request, etc.

License

This is licensed under the Apache License 2.0.

docker_stats_exporter's People

Contributors

ianneub avatar wywywywy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

docker_stats_exporter's Issues

-v /usr/bin/docker:/usr/bin/docker not needed for docker_stats_exporter.js

When using the docker_stats_exporter from a docker container running on ubuntu 20.04, the container does not start because /usr/bin/docker is not present and the process does not have sufficient rights to create it. Looking in the code, /usr/bin/docker is referred to in Jenkinsfile, but not in docker_stats_exporter.js (only the socket). Removing the volume /usr/bin/docker:/usr/bin/docker made docker_stats_exporter.js run perfectly.

I considered creating a pull request for the README, but I do not really know what the applications of Jenkinsfile are, so I decided to just create this issue to mention it.

I use Grafana to visualize the data exported. I shared the visualization for the container stats of this exporter. Maybe it is useful for someone else as well: https://grafana.com/grafana/dashboards/13331/

BTW: thanks for this really useful exporter

Installing on Pi 3

Hi,

Trying to install on Pi 3 and getting an error:
no matching manifest for linux/arm/v7 in the manifest list entries The terminal process "/usr/bin/bash '-c', 'docker compose -f "app/docker-compose.yml" up -d --build'" terminated with exit code: 18.

I thought I had done this on a Pi 3 before with out a problem?
Should this work on buster?

dockerstats_cpu_usage_ratio 0 on centeros 7

HELP dockerstats_cpu_usage_ratio CPU usage percentage 0-100

TYPE dockerstats_cpu_usage_ratio gauge

dockerstats_cpu_usage_ratio{name="moniter_docker_stats_exporter",id="e983380987d5"} 0
dockerstats_cpu_usage_ratio{name="moniter_kafka_exporter",id="810922347b23"} 0
dockerstats_cpu_usage_ratio{name="moniter_process_exporter",id="2a1b9d670629"} 0
dockerstats_cpu_usage_ratio{name="moniter_promtail",id="2ac75dc7d7d9"} 0
dockerstats_cpu_usage_ratio{name="moniter_grafana",id="3af9d0ca30c4"} 0
dockerstats_cpu_usage_ratio{name="moniter_loki",id="c096bc80df0b"} 0
dockerstats_cpu_usage_ratio{name="moniter_prometheus",id="80a6b3d7ca80"} 0

docker_stats_exporter:
container_name: moniter_docker_stats_exporter
image: wywywywy/docker_stats_exporter:20220516
ports:
- "9487:9487"
networks:
- moniter
volumes:
- /var/run/docker.sock:/var/run/docker.sock

No data

I deployed this in a stack with Prometheus and Grafana. However, there is no data (and no error log either). I also used your Grafana dashboard template with no result.
Here is my docker-compose.yaml:

version: '3'

volumes:
  prometheus-data:
    driver: local
  grafana-data:
    driver: local

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    ports:
      - "9090:9090"
    volumes:
      - /home/sil/prometheus:/etc/prometheus
      - prometheus-data:/prometheus
    restart: unless-stopped
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3030:3000"
    volumes:
      - grafana-data:/var/lib/grafana
    restart: unless-stopped

  docker-stats:
    image: wywywywy/docker_stats_exporter:latest
    container_name: docker_stats_exporter
    ports:
      - "9487:9487"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    restart: unless-stopped

and my prometheus.yaml:

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'docker_stats_exporter'
    metrics_path: /
    static_configs:
    - targets:
        - '127.0.0.1:9487'

inaccurate metrics vs host real time

Hi,

For some hosts docker_stats_exporter metrics are not up to date compare with the current status.

Example: i have 30 containers with status=running and i do not have metrics about them

[root@host]# docker ps | wc -l
32
[root@host]#
[root@host]# curl http://localhost:9487/metrics | grep -v "#"

dockerstats_cpu_usage_ratio{name="XXX",id="4f172ac34142"} Nan

[root@host]# docker logs -f docker-exporter --tail 5
ERROR: TypeError: Value is not a valid number: undefined
ERROR: TypeError: Value is not a valid number: undefined
ERROR: TypeError: Value is not a valid number: undefined

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.