Code Monkey home page Code Monkey logo

prometheus-docker-labels-discovery's Introduction

Discover docker containers to scrape based on labels

This tool aims at discovering containers running with prometheus.io/scrape=true annotations from a given docker engine, and auto-configure prometheus for scraping.

This tool is standalone and write the discovered containers (services) in a file, which is in turn passed to Prometheus file service discovery to start the scraping jobs.

overall diagram

Example via a docker-compose

The following part is giving a complete example of configuring the docker-labels discovery mechanism. It is based in three parts, namely:

  • Configure prometheus-docker-labels-discovery
  • Configure Prometheus file_sd_configs
  • Configure your services

Configure prometheus-docker-labels-discovery

  prometheus-docker-labels-discovery:
    image: sqooba/prometheus-docker-labels-discovery:v1
    restart: unless-stopped
    networks:
      - monitoring_default # make sure this network exists and is connected to prometheus
#    ports:
#      - "8080"
    security_opt:
      - no-new-privileges:true
    volumes: # Mount the JSON file that will be exchanged with prometheus
      - ./from-docker-labels.json:/tmp/from-docker-labels.json
    environment:
      - PROMETHEUS_CONFIG_FILE_PATH=/tmp/from-docker-labels.json
      - DOCKER_NETWORK_NAME=bridge
      - PROMETHEUS_COMMON_LABELS=commonlabel1=commonvalue1

Configure Prometheus

Prometheus needs to be configured using file_sd_configs scrape config.

scrape_configs:
- job_name: 'docker-labels-sd'
  file_sd_configs:
  - files:
    - 'from-docker-labels.json'

Configure your services

Any service can now be configured using docker labels. The following example shows in docker-compose style how this looks like:

services:
  test-metrics:
    image: dummy-metrics:v1
    labels:
      - "prometheus.io/scrape=true"
      - "prometheus.io/path=/metrics"
      - "prometheus.io/extra-labels=k1:v1,k2:v2"

The exhaustive list of labels to configure properly your service is provided below:

Annotation Definition Example
prometheus.io/scrape Main label to ensure this container will be scraped by Prometheus. Required value is true. Any other value will not be considered. prometheus.io/scrape=true
prometheus.io/port Specify which port to use for the scraping. In case of a single port exposed, this configuration can be omitted. prometheus.io/port=8080
prometheus.io/path Alternative path for scraping the metrics. Default from Prometheus is /. prometheus.io/path=/metrics
prometheus.io/scheme Alternative scheme for scraping thee metrics. Default from Prometheus is http. prometheus.io/scheme=https
prometheus.io/extra-labels Any extra labels to add to the metrics scraped for this container. Comma separated key:value pairs. prometheus.io/extra-labels=label1:value1,label2:value2,...

prometheus-docker-labels-discovery's People

Contributors

axelfahy avatar killerwhile avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

simono41 keia-bot

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.