curl -L http://localhost:2379/metrics
etcdctl endpoint health --
Running a Prometheus monitoring service is the easiest way to ingest and record etcd’s metrics.
First, install Prometheus:
<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
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
</pre>
Set Prometheus’s scraper to target the etcd cluster endpoints:
<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
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
</pre>
Set up the Prometheus handler:
<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
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 &
</pre>
Now Prometheus will scrape etcd metrics every 10 seconds.
Grafana has built-in Prometheus support; just add a Prometheus data source:
<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
Name: test-etcd
Type: Prometheus
Url: http://localhost:9090
Access: proxy
</pre>
Then import the default etcd dashboard template and customize. For instance, if Prometheus data source name is my-etcd
, the datasource
field values in JSON also need to be my-etcd
.