0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Grafana/Prometheus/Lokiで自宅ネットワークの監視基盤を作る

Last updated at Posted at 2022-12-31

背景・モチベーション

自宅ネットワークのサーバ数が10台を超え、ノード、コンテナの監視がしたい
datadogの無料プランを利用していたが、利用枠が不足した
このため、オンプレで稼働する監視基盤構築のためPrometheus/Grafana/Lokiを利用する

構成

  • 監視対象: Linuxサーバ(Debian/Ubuntu/CentOS) および MacMini
        一部、室温センサーなどの情報をExpoterterで取得する
  • 監視基盤: Grafana/Prometheus/Lokiのクラスタをdocker-compose上で実行

Prometheusとは

Pull型の監視用ツール
Kubernetesと関連が強く、おそらく大量のマイクロサービス化されたコンテナを対象として想定されている
いわゆるエージェント型で、監視対象(サーバ)にExporterと呼ばれる
メトリック、トレース、ログのトレース以外の部分の監視が対象
PromQLというクエリ言語でデータが取れる
Expoter側で情報にラベルを付与可能
ラベルごとにデータを集計できたりする

Grafanaとは

可視化ツール
ElasticStackのKibanaに相当する(ElastaicsearchがLoki/Prometheusに相当?)
バックエンドにElasticsearch/CloudWatchLogs/Datadogなどを設定できる
ダッシュボード作れる

Loki とは

 ログに相当するもの
 Fluent-bitのOutputで簡単に連携が可能
 CloudWachLogs/Elasticsearchのような各行データを保持する

Exporterとは

監視対象に設定するエージェントのようなもの
 Exporterは1サーバに1つではなく、監視のスコープ毎に個別に設定する
 ExporterにはPrometheusからhttpでリクエストが送信され、監視対象の情報を返す
基本的にはPlain/text形式で下記の形式で情報を返す
 Apache/Nginx/Haproxyなどは大体アドオンでExporter形式の情報を集約可能
 datadogエージェントも実は内部的にこれが動いてる?
 Gitlabのオンプレ版にはExpoterterが内蔵されていて、configで有効化可能
 サーバサイドの情報はHELP、TYPE、実際の値(下記例)で記載するとPrometheus側でデータ取得してくれる
 TPYPEにはcounter、gauge、histogram、summaryがある

# HELP temperature this is bedroom temperature
# TYPE temperature counter
temperature{room="bedroom",device="bme280"} 19.63

監視基盤構成

下記、docker-compose.ymlで設定する
 prometheus/lokiについては、データ保持をローカルストレージで行うため、ストレージ領域をVolume共有している
 ※ docker-composeの起動時にデータがリセットされないため
Grafanaについてはdashboards

docker-compose構成

docker-compose.yml
version: '3'
services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus/storage:/prometheus
    ports:
      - '9090:9090'
    dns:
      - 8.8.8.8
  loki:
    image: grafana/loki
    container_name: loki
    volumes:
      - ./loki/storage:/loki
    ports:
      - 3100:3100
    command: -config.file=/etc/loki/local-config.yaml
  grafana:
    image: grafana/grafana
    container_name: grafana
    environment:
      - GF_INSTALL_PLUGINS=marcusolsson-treemap-panel
    ports:
      - "3000:3000"
    volumes:
      - "./grafana/datasources:/etc/grafana/provisioning/datasources"
      - "./grafana/dashboards:/etc/grafana/provisioning/dashboards"

参考文献

入門 Prometheus ―インフラとアプリケーションのパフォーマンスモニタリング
 https://www.amazon.co.jp/%E5%85%A5%E9%96%80-Prometheus-%E2%80%95%E3%82%A4%E3%83%B3%E3%83%95%E3%83%A9%E3%81%A8%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E3%83%91%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3%E3%82%B9%E3%83%A2%E3%83%8B%E3%82%BF%E3%83%AA%E3%83%B3%E3%82%B0-Brian-Brazil/dp/4873118778

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?