K&

监控etcd

 

每个etcd服务器都/metrics在其客户端端口路径下导出指标。

可以通过以下方式获取指标curl

 

本文为了安全用了证书所以

 

 

curl https://172.21.130.169:2379/metrics --cacert /var/local/etcd/ssl/ca.pem --cert /var/local/etcd/ssl/server.pem --key /var/local/etcd/ssl/server-key.pem

 

 

 

 

$ curl -L http://localhost:2379/metrics
# HELP etcd_debugging_mvcc_keys_total Total number of keys.
# TYPE etcd_debugging_mvcc_keys_total gauge
etcd_debugging_mvcc_keys_total 0
# HELP etcd_debugging_mvcc_pending_events_total Total number of pending events to be sent.
# TYPE etcd_debugging_mvcc_pending_events_total gauge
etcd_debugging_mvcc_pending_events_total 0
...

 

普罗米修斯

 

运行Prometheus监视服务是提取和记录etcd指标的最简单方法。

首先,安装Prometheus:

 

PROMETHEUS_VERSION="1.3.1"
wget https://github.com/prometheus/prometheus/releases/download/v$PROMETHEUS_VERSION/prometheus-$PROMETHEUS_VERSION.linux-amd64.tar.gz -O /tmp/prometheus-$PROMETHEUS_VERSION.linux-amd64.tar.gz
tar -xvzf /tmp/prometheus-$PROMETHEUS_VERSION.linux-amd64.tar.gz --directory /tmp/ --strip-components=1
/tmp/prometheus -version

 

将Prometheus的scraper设置为针对etcd集群端点:

 

cat > /tmp/test-etcd.yaml <<EOF
global:
scrape_interval: 10s
scrape_configs:
- job_name: test-etcd
static_configs:
- targets: ['10.240.0.32:2379','10.240.0.33:2379','10.240.0.34:2379']
EOF
cat /tmp/test-etcd.yaml

 

设置Prometheus处理程序:

 

nohup /tmp/prometheus \
-config.file /tmp/test-etcd.yaml \
-web.listen-address ":9090" \
-storage.local.path "test-etcd.data" >> /tmp/test-etcd.log 2>&1 &

 

现在,Prometheus将每10秒抓取一次etcd指标。

 

格拉法纳

 

Grafana具有内置的Prometheus支持。只需添加一个Prometheus数据源:

 

Name: test-etcd
Type: Prometheus
Url: http://localhost:9090
Access: proxy

 

然后导入默认的etcd仪表板模板并进行自定义。例如,如果Prometheus数据源名称为my-etcd,则datasourceJSON中的字段值也需要为my-etcd

 

posted on 2021-05-11 18:14  K&  阅读(835)  评论(0编辑  收藏  举报