Loading README.md 0 → 100644 +31 −0 Original line number Diff line number Diff line # Prometheus ## Adding services dynamically Set `JOBS` environment variable with a string of service scrape definitions, separated by `,`. Single scrape definition follow this syntax: ``` <serviceName>:<port>[<metricsPath>][;[<scrapeInterval>][;[<scrapeTimeout>]]] ``` Each service scrape definition can contains 5 parameters (**bold** ones are mandatory): * **serviceName**: Used as scrape job name and hostname (with `tasks.` prefix) of service to scrape. * **port**: The service port to scrape metrics from. * metricsPath: The HTTP resource path on which to fetch metrics from target. Default is `/metrics`. * scrapeInterval: How frequently to scrape target. Default is `15s`. * scrapeTimeout: Per-scrape timeout when scraping target. Default is `10s`. ### Example Consider 3 services to scrape: ``` JOBS=service1:8080,service2:8000/metrics-path;60;30,service3:3000;;20 ``` * `service1` uses port `8080` (other params use default values). * `service2` uses port `8000`, path `/metrics-path`, interval `60s` and timeout `30s`. * `service3` uses port `3000` and timeout `20s` (other params use default values). deploy/.env +0 −1 Original line number Diff line number Diff line JOBS=dockerd-exporter:9323,cadvisor:8080,node-exporter:9100,pushgateway:9091,zookeeper-1:9998,zookeeper-2:9998,zookeeper-3:9998,kafka-1:9998,kafka-2:9998,kafka-3:9998,vernemq:8888,traefik:8080,elasticsearch-exporter:9114,kafka-exporter:9308,web:3050,api:8080/api/actuator/prometheus,oauth:8081/api/oauth/actuator/prometheus,user:8082/api/user/actuator/prometheus,socket:8089/api/socket/actuator/prometheus,tasks:8088/api/tasks/actuator/prometheus,ais:8090/api/ais/actuator/prometheus,vessels-commands:8091/api/vessels/commands/actuator/prometheus,vessels-view:8092/api/vessels/view/actuator/prometheus,time-series:8096/api/time-series/view/actuator/prometheus STORAGE_TSDB_RETENTION_TIME=30d STORAGE_TSDB_RETENTION_SIZE=8GB deploy/conf/entrypoint.sh +16 −12 Original line number Diff line number Diff line Loading @@ -2,27 +2,31 @@ cat /etc/prometheus/prometheus-conf.yml > /tmp/prometheus.yml if [ ${JOBS+x} ] if [ ${JOBS:+x} ] then for job in $(echo "${JOBS}" | tr ',' ' ') do echo "adding job $job" echo "adding job ${job}" params_job=$(echo "${job}" | sed -r 's/(.*):([[:digit:]]+)((\/.*)*)$/\1 \2 \3/') jobParams=$(echo "${job}" | sed -r 's/(.*):([[:digit:]]+)(\/[^;]*)?(;([[:digit:]]+)?)?(;([[:digit:]]+)?)?$/\1 \2 \3 \5 \7/') SERVICE=$(echo "${params_job}" | cut -d " " -f1) PORT=$(echo "${params_job}" | cut -d " " -f2) METRIC_PATH=$(echo "${params_job}" | cut -d " " -f3) serviceName=$(echo "${jobParams}" | cut -d " " -f1) port=$(echo "${jobParams}" | cut -d " " -f2) metricsPath=$(echo "${jobParams}" | cut -d " " -f3) scrapeInterval=$(echo "${jobParams}" | cut -d " " -f4) scrapeTimeout=$(echo "${jobParams}" | cut -d " " -f5) cat >>/tmp/prometheus.yml <<EOF - job_name: '${SERVICE}' metrics_path: '${METRIC_PATH:-/metrics}' - job_name: '${serviceName}' ${scrapeInterval:+scrape_interval: ${scrapeInterval}s} ${scrapeTimeout:+scrape_timeout: ${scrapeTimeout}s} ${metricsPath:+metrics_path: '${metricsPath}'} dns_sd_configs: - names: - 'tasks.${SERVICE}' - 'tasks.${serviceName}' type: 'A' port: ${PORT} port: ${port} EOF done fi Loading deploy/conf/prometheus.yml +2 −1 Original line number Diff line number Diff line global: scrape_interval: 15s evaluation_interval: 15s scrape_timeout: 10s evaluation_interval: 30s external_labels: monitor: 'promswarm' Loading Loading
README.md 0 → 100644 +31 −0 Original line number Diff line number Diff line # Prometheus ## Adding services dynamically Set `JOBS` environment variable with a string of service scrape definitions, separated by `,`. Single scrape definition follow this syntax: ``` <serviceName>:<port>[<metricsPath>][;[<scrapeInterval>][;[<scrapeTimeout>]]] ``` Each service scrape definition can contains 5 parameters (**bold** ones are mandatory): * **serviceName**: Used as scrape job name and hostname (with `tasks.` prefix) of service to scrape. * **port**: The service port to scrape metrics from. * metricsPath: The HTTP resource path on which to fetch metrics from target. Default is `/metrics`. * scrapeInterval: How frequently to scrape target. Default is `15s`. * scrapeTimeout: Per-scrape timeout when scraping target. Default is `10s`. ### Example Consider 3 services to scrape: ``` JOBS=service1:8080,service2:8000/metrics-path;60;30,service3:3000;;20 ``` * `service1` uses port `8080` (other params use default values). * `service2` uses port `8000`, path `/metrics-path`, interval `60s` and timeout `30s`. * `service3` uses port `3000` and timeout `20s` (other params use default values).
deploy/.env +0 −1 Original line number Diff line number Diff line JOBS=dockerd-exporter:9323,cadvisor:8080,node-exporter:9100,pushgateway:9091,zookeeper-1:9998,zookeeper-2:9998,zookeeper-3:9998,kafka-1:9998,kafka-2:9998,kafka-3:9998,vernemq:8888,traefik:8080,elasticsearch-exporter:9114,kafka-exporter:9308,web:3050,api:8080/api/actuator/prometheus,oauth:8081/api/oauth/actuator/prometheus,user:8082/api/user/actuator/prometheus,socket:8089/api/socket/actuator/prometheus,tasks:8088/api/tasks/actuator/prometheus,ais:8090/api/ais/actuator/prometheus,vessels-commands:8091/api/vessels/commands/actuator/prometheus,vessels-view:8092/api/vessels/view/actuator/prometheus,time-series:8096/api/time-series/view/actuator/prometheus STORAGE_TSDB_RETENTION_TIME=30d STORAGE_TSDB_RETENTION_SIZE=8GB
deploy/conf/entrypoint.sh +16 −12 Original line number Diff line number Diff line Loading @@ -2,27 +2,31 @@ cat /etc/prometheus/prometheus-conf.yml > /tmp/prometheus.yml if [ ${JOBS+x} ] if [ ${JOBS:+x} ] then for job in $(echo "${JOBS}" | tr ',' ' ') do echo "adding job $job" echo "adding job ${job}" params_job=$(echo "${job}" | sed -r 's/(.*):([[:digit:]]+)((\/.*)*)$/\1 \2 \3/') jobParams=$(echo "${job}" | sed -r 's/(.*):([[:digit:]]+)(\/[^;]*)?(;([[:digit:]]+)?)?(;([[:digit:]]+)?)?$/\1 \2 \3 \5 \7/') SERVICE=$(echo "${params_job}" | cut -d " " -f1) PORT=$(echo "${params_job}" | cut -d " " -f2) METRIC_PATH=$(echo "${params_job}" | cut -d " " -f3) serviceName=$(echo "${jobParams}" | cut -d " " -f1) port=$(echo "${jobParams}" | cut -d " " -f2) metricsPath=$(echo "${jobParams}" | cut -d " " -f3) scrapeInterval=$(echo "${jobParams}" | cut -d " " -f4) scrapeTimeout=$(echo "${jobParams}" | cut -d " " -f5) cat >>/tmp/prometheus.yml <<EOF - job_name: '${SERVICE}' metrics_path: '${METRIC_PATH:-/metrics}' - job_name: '${serviceName}' ${scrapeInterval:+scrape_interval: ${scrapeInterval}s} ${scrapeTimeout:+scrape_timeout: ${scrapeTimeout}s} ${metricsPath:+metrics_path: '${metricsPath}'} dns_sd_configs: - names: - 'tasks.${SERVICE}' - 'tasks.${serviceName}' type: 'A' port: ${PORT} port: ${port} EOF done fi Loading
deploy/conf/prometheus.yml +2 −1 Original line number Diff line number Diff line global: scrape_interval: 15s evaluation_interval: 15s scrape_timeout: 10s evaluation_interval: 30s external_labels: monitor: 'promswarm' Loading