LoginSignup
2
0

More than 1 year has passed since last update.

[Prometheus] exporter_proxyを使って各exporterのポートを1つにまとめる

Last updated at Posted at 2021-06-13

目次

概要

Prometheusの各exporterはそれぞれポートが異なる。exporterごとにポートの開放/閉鎖などの管理が面倒な場合は、exporter_proxyを利用することでポートを一つにまとめることができる。その名の通りこれがproxyの役割をし、各exporterの各ポートへの通信を仲介してくれる。

exporter_proxy

以下を利用する。
https://github.com/rrreeeyyy/exporter_proxy

環境

  • exporter_proxy v0.4.1

前提条件

以下の手順でPrometheus環境を構築していることを前提とする。
https://qiita.com/Esfahan/items/0feaedfd771f49ac7ee4

また、同じdocker-network上に、各exporterが起動していることを前提とする。

ディレクトリ構成

├── config
│   └── config.yaml
└── docker-compose.yaml
$ mkdir config

config.yaml

urlで指定しているホスト名は、各exporterのDockerコンテナのホスト名。
各exporterをDockerで構築していない場合は、http://localhostにするなど適宜変更すること。

config.yaml
listen: "0.0.0.0:9099"

exporters:
  node_exporter:
    path: "/node_exporter/metrics"
    url: "http://node-exporter:9100/metrics"
  mysqld_exporter:
    path: "/mysqld_exporter/metrics"
    url: "http://mysqld-exporter:9104/metrics"
  postgres_exporter:
    path: "/postgres_exporter/metrics"
    url: "http://postgres-exporter:9187/metrics"
  mtail:
    path: "/mtail/metrics"
    url: "http://mtail:3903/metrics"

Docker

mysqld_exporterや、postgres_exporterなど、他のexporterをDockerで構築している場合は、それぞれexporter_proxyと同じdocker-network上に構築すること。

docker-compose.yaml
version: '3'
services:
  exporter_proxy:
    image: rrreeeyyy/exporter_proxy
    container_name: exporter_proxy
    volumes:
      - ./config:/config
    ports:
      - 9099:9099
    entrypoint: ['/exporter_proxy', '-config', '/config/config.yaml']
    networks:
      - sample-network

networks:
    sample-network:
        external: true
$ sudo docker-compose up -d --build

Prometheusサーバーの設定

こちらの記事で構築したPrometheus環境の設定ファイルを編集する。

監視対象を追加

以下のようにprometheus.yamlの各exporterの定義を、ポートを全て9099に変更し、metrics_pathも変更する。

prometheus/prometheus.yaml
# 前略
scrape_configs:
+  - job_name: node
+    metrics_path: /node_exporter/metrics
+    static_configs:
+      - targets:
+        - example.com:9099
+        labels:
+          env: development
+  - job_name: mysqld
+    metrics_path: /mysqld_exporter/metrics
+    static_configs:
+      - targets:
+        - example.com:9099
+        labels:
+          env: development
+  - job_name: postgres
+    metrics_path: /postgres_exporter/metrics
+    static_configs:
+      - targets:
+        - example.com:9099
+        labels:
+          env: development
+  - job_name: mtail
+    metrics_path: /mtail_exporter/metrics
+    static_configs:
+      - targets:
+        - example.com:9099
+        labels:
+          env: development

設定を反映

$ sudo docker-compose restart prometheus

PrometheusのUI

これで9099ポートで全てのexporterと通信ができるようになる。
http://your_prometeus.com:9090/graph
Screen Shot 2021-06-13 at 16.50.11.png

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0