Prometheus容器reload config
5489 ワード
Prometheus容器reload config
以前の記事に従ってkubernetes環境でprometheusを導入した後、プロセスが正常に動作していることを監視します.問題が発生しました:prometheusの構成内容はconfigmapで構成されています.configmapを更新した後、prometheusプロセスに構成内容を再ロードするにはどうすればいいですか?
1、ConfigMapの熱更新
kubernetesクラスタ内で、ConfigMapがpod内にvolume形式でマウントされると、ConfigMapが更新され、kubernetesはpod内にマウントされたファイルの内容を自動的に同期します.ただし、次のマウント方式では、ファイルの内容が自動的に同期されません.
正しい書き方:
ConfigMapが修正されても、すぐには有効になりません.30秒以内にファイルの内容の同期が完了します~~
2、Peometheusロードプロファイル
公式サイトの説明によると、Prometheusは2つのプロファイルを再ロードする方法を提供します. prometheusへの信号送信
この方法はまず容器の内部に入り、peometheusを見つけて番号を行い、kill-Hopを実行する必要がある.
自動実行が必要な場合は、shellスクリプトを作成してミラーに追加し、ファイルが変更されたかどうかをタイミング的に監視できます. prometheusへHTTP要求 を送信する.
//-/reloadはPOSTリクエストのみを受信し、prometheusプロセスを開始するときに
3、Dockerfile
Dockerfileを共有します.これは公式に提供されたDockerfileに基づいて修正されました.デフォルトのpeometheusはnobodyユーザーで起動され、volumnをマウントする際に不便で、同僚は
ミラーを作成する前に、GitHubでコンパイルしたReleaseをダウンロードし、解凍し、Dockerfileを解凍パスに入れて実行します.
4、補足:静的目標の自動認識
Prometheus提供file_sd_configは静的ターゲットを自動的に識別するために用いられ、〜〜〜を参照する.
以前の記事に従ってkubernetes環境でprometheusを導入した後、プロセスが正常に動作していることを監視します.問題が発生しました:prometheusの構成内容はconfigmapで構成されています.configmapを更新した後、prometheusプロセスに構成内容を再ロードするにはどうすればいいですか?
1、ConfigMapの熱更新
kubernetesクラスタ内で、ConfigMapがpod内にvolume形式でマウントされると、ConfigMapが更新され、kubernetesはpod内にマウントされたファイルの内容を自動的に同期します.ただし、次のマウント方式では、ファイルの内容が自動的に同期されません.
volumeMounts:
- mountPath: /etc/prometheus/prometheus.yml
name: prometheus-conf-volume
subPath: prometheus.yml
volumes:
- name: prometheus-conf-volume
configMap:
name: prometheus-conf
正しい書き方:
volumeMounts:
- mountPath: /etc/prometheus
name: prometheus-conf-volume
volumes:
- name: prometheus-conf-volume
configMap:
name: prometheus-conf
ConfigMapが修正されても、すぐには有効になりません.30秒以内にファイルの内容の同期が完了します~~
2、Peometheusロードプロファイル
公式サイトの説明によると、Prometheusは2つのプロファイルを再ロードする方法を提供します.
/prometheus # ps -ef | grep prometheus
1 root 0:14 /bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.enable-lifecycle --web.console.templates=/usr/share/prometheus/consoles
/prometheus # kill -HUP 1
この方法はまず容器の内部に入り、peometheusを見つけて番号を行い、kill-Hopを実行する必要がある.
自動実行が必要な場合は、shellスクリプトを作成してミラーに追加し、ファイルが変更されたかどうかをタイミング的に監視できます.
LiondeMacBook-Pro:~ lion$ curl -XPOST http://prometheus.chenlei.com/-/reload
//-/reloadはPOSTリクエストのみを受信し、prometheusプロセスを開始するときに
--web.enable-lifecycle
を指定する必要があります.デフォルトでは指定されていないので、ミラーを変更する必要があります.3、Dockerfile
Dockerfileを共有します.これは公式に提供されたDockerfileに基づいて修正されました.デフォルトのpeometheusはnobodyユーザーで起動され、volumnをマウントする際に不便で、同僚は
--web.enable-lifecycle
増加しました.FROM quay.io/prometheus/busybox:latest
LABEL maintainer "The Prometheus Authors , Custom by "
COPY prometheus /bin/prometheus
COPY promtool /bin/promtool
COPY prometheus.yml /etc/prometheus/prometheus.yml
COPY console_libraries/ /usr/share/prometheus/console_libraries/
COPY consoles/ /usr/share/prometheus/consoles/
RUN ln -s /usr/share/prometheus/console_libraries /usr/share/prometheus/consoles/ /etc/prometheus/
RUN mkdir -p /prometheus
EXPOSE 9090
VOLUME [ "/prometheus" ]
WORKDIR /prometheus
ENTRYPOINT [ "/bin/prometheus" ]
CMD [ "--config.file=/etc/prometheus/prometheus.yml", \
"--storage.tsdb.path=/prometheus", \
"--web.console.libraries=/usr/share/prometheus/console_libraries", \
"--web.enable-lifecycle", \
"--web.console.templates=/usr/share/prometheus/consoles" ]
ミラーを作成する前に、GitHubでコンパイルしたReleaseをダウンロードし、解凍し、Dockerfileを解凍パスに入れて実行します.
root@master-1:~/kubernetes/prometheus/prometheus-2.2.1.linux-amd64# docker build -t 192.168.101.88:5000/prom/prometheus-c:v2.2.2 .
4、補足:静的目標の自動認識
Prometheus提供file_sd_configは静的ターゲットを自動的に識別するために用いられ、〜〜〜を参照する.