William-Yeh.prometheus
William YehのAnsible Galaxy用Prometheus
概要
Ansible Galaxyの役割名: william-yeh.prometheus
このAnsibleの役割は、Prometheusに対して以下の機能を提供します:
- 特定のバージョンのPrometheusサーバー、Nodeエクスポーター、Alertmanagerをインストールします。
- 再起動/リロード/停止イベント用のハンドラー。
- 基本的な設定 (本当の 設定はユーザーのテンプレートファイルに任せます。下記の使用法セクションを参照してください)。
この役割はシンプルさを保つため、以下の3つのコンポーネントのみをインストールします: Prometheusサーバー、Nodeエクスポーター、Alertmanager。他のPrometheusエクスポーターをインストールしたい場合は、以下の役割を使用してください:
- Consul: william-yeh.consul_exporter
- Elasticsearch: william-yeh.es_cluster_exporter
- MongoDB: williamyeh.mongodb_exporter
Ubuntu 12.04 (Precise)およびCentOS 6のサポートは2018年11月に終了しました。
役割の変数
必須の変数
インストールするコンポーネント:
# サポートされているコンポーネント:
#
# [サーバーコンポーネント]
# - "prometheus"
# - "alertmanager"
#
# [エクスポーターコンポーネント]
# - "node_exporter"
#
prometheus_components
オプションの変数: 一般設定
ユーザー設定可能なデフォルト値:
# ユーザーとグループ
prometheus_user: prometheus
prometheus_group: prometheus
# 実行可能ファイルのディレクトリ
prometheus_install_path: /opt/prometheus
# 設定ファイルのディレクトリ
prometheus_config_path: /etc/prometheus
# ログファイルのディレクトリ
prometheus_log_path: /var/log/prometheus
# PIDファイルのディレクトリ
prometheus_pid_path: /var/run/prometheus
# 一時ファイルのディレクトリ
prometheus_download_path: /tmp
# ヘルパーユーティリティ「gosu」のバージョン
gosu_version: "1.11"
オプションの変数: systemdを使用するかどうか
Linuxディストリビューションがsystemdを装備している場合、この役割はこのメカニズムを使用します。これを無効にするには(伝統的なSysVスタイルのinitスクリプトを使用する)、以下の変数をfalse
に設定します:
prometheus_use_systemd
オプションの変数: Prometheusサーバー
ユーザー設定可能なデフォルト値:
# どのバージョン?
prometheus_version: 2.5.0
# ルールファイルのディレクトリ
prometheus_rule_path: {{ prometheus_config_path }}/rules
# file_sdファイルのディレクトリ
prometheus_file_sd_config_path: {{ prometheus_config_path }}/tgroups
# 実行時データベースのディレクトリ
prometheus_db_path: /var/lib/prometheus
ユーザーがインストールする設定ファイル(詳細はdocを参照):
# `playbook_dir`に対するメイン設定テンプレート;
# "{{ prometheus_config_path }}/prometheus.yml"にインストールされます
prometheus_conf_main
ユーザーがインストールするルールファイル(詳細はdocを参照):
# "{{ prometheus_rule_path }}"ディレクトリにインストールされるルールファイル;
# 辞書フィールド:
# - key: このルールのメモ
# - value:
# - src: `playbook_dir`に対するファイル
# - dest: `{{ prometheus_rule_path }}`に対するターゲットファイル
prometheus_rule_files
トリガーされるAlertmanager:
prometheus_alertmanager_hostport
その他のコマンドライン引数がある場合(すべての引数のフルリストを見るにはprometheus --help
を使用):
prometheus_opts
オプションの変数: Nodeエクスポーター
ユーザー設定可能なデフォルト値:
# どのバージョン?
prometheus_node_exporter_version: 0.16.0
その他のコマンドライン引数がある場合(すべての引数のフルリストを見るにはnode_exporter --help
を使用):
prometheus_node_exporter_opts
オプションの変数: Alertmanager
ユーザー設定可能なデフォルト値:
# どのバージョン?
prometheus_alertmanager_version: 0.15.3
# 実行時データベースのディレクトリ(現在は`s silences.json`用)
prometheus_alertmanager_db_path: /var/lib/alertmanager
ユーザーがインストールするalertmanager設定ファイル(詳細はdocを参照):
# `playbook_dir`に対するメイン設定テンプレート;
# "{{ prometheus_config_path }}/alertmanager.yml"にインストールされます
prometheus_alertmanager_conf
その他のコマンドライン引数がある場合(すべての引数のフルリストを見るにはalertmanager --help
を使用):
prometheus_alertmanager_opts
オプション: ソースツリーからビルド
(Credit: Robbie Trencheny)
前述のprometheus_components
について、それぞれのバージョンをgit
に設定することで、Prometheusのリポジトリのmasterブランチからダウンロード/コンパイルすることができます。
これにより、prometheus_workdir
ディレクトリ(defaults/main.yml
で定義)に一時的なGolangコンパイラがインストールされます。
例えば、すべてのコンポーネントの最新のコードを取得するには、すべての*_version
変数をgit
に設定します:
prometheus_version: git
prometheus_node_exporter_version: git
prometheus_alertmanager_version: git
毎回強制的に再ビルドしたい場合は、以下の変数を有効にします(デフォルトはfalse
):
prometheus_rebuild: true
ハンドラー
Prometheusサーバー:
restart prometheus
reload prometheus
stop prometheus
Nodeエクスポーター:
restart node_exporter
reload node_exporter
(実際には、restart
と同じ)stop node_exporter
Alertmanager:
restart alertmanager
reload alertmanager
stop alertmanager
使用法
ステップ1: 役割を追加
役割名william-yeh.prometheus
をプレイブックファイルに追加します。
ステップ2: 変数を追加
必要に応じて、プレイブックファイルに変数を設定します。
簡単な例:
---
# ファイル: simple-playbook.yml
- hosts: all
become: True
roles:
- william-yeh.prometheus
vars:
prometheus_components: [ "prometheus", "alertmanager" ]
prometheus_alertmanager_hostport: "localhost:9093"
ステップ3: ユーザーの設定ファイルをコピー(必要な場合)
より実用的な例:
---
# ファイル: complex-playbook.yml
- hosts: all
become: True
roles:
- william-yeh.prometheus
vars:
prometheus_components:
- prometheus
- node_exporter
- alertmanager
prometheus_rule_files:
this_is_rule_1_InstanceDown:
src: some/path/basic.rules
dest: basic.rules
prometheus_alertmanager_conf: some/path/alertmanager.yml.j2
ステップ4: デフォルトのPrometheusページをブラウズ
ブラウザでページを開きます:
- Prometheus -
http://HOST:9090
またはhttp://HOST:9090/consoles/node.html
- Alertmanager -
http://HOST:9093
依存関係
なし。
貢献者
- William Yeh
- Robbie Trencheny - Goソースコードからのバイナリビルドの初期版を貢献。
- Travis Truman - consul_exporterインストーラーの初期版を貢献;現在はWilliam-Yeh.consul_exporterに移動。
- Musee Ullah
ライセンス
MITライセンス。詳細はLICENSEファイルを参照してください。
ansible-galaxy install William-Yeh.prometheus