简体   繁体   English

从 etcdctl 获取 ETCD 指标

[英]Getting ETCD Metrics from etcdctl

I am trying to get ETCD metrics like the number of ETCD keys and size as well as the number of requests made to ETCD through exec (ing) into a kubernetes pod (etcdctl) and am not sure what command to use for this.我正在尝试获取 ETCD 指标,例如 ETCD 密钥的数量和大小,以及通过 exec(ing)到 kubernetes pod(etcdctl)中向 ETCD 发出的请求数量,但我不确定为此使用什么命令。

An alternative (such as cUrl) would help as well.替代方案(例如 cUrl)也会有所帮助。

Thanks for the help!谢谢您的帮助!

You need to extract the information from etcd and filter what you want.您需要从 etcd 中提取信息并过滤您想要的内容。 To illustrate, I will show you how to get the number of total keys from etcd.为了说明,我将向您展示如何从 etcd 获取总键数。

NOTE : Tested in kubernetes 1.18.2.注意:在 kubernetes 1.18.2 中测试。

# Getting etcd pod IP and set a local variable:
ADVERTISE_URL="https://$(kubectl get pods -n kube-system -l=component=etcd -o=jsonpath='{ .items[*].status.podIP }'):2379"

# Getting ectd pod name and set a variable ETCD_POD
ETCD_POD=$(kubectl get pods -n kube-system -l=component=etcd -o=jsonpath='{ .items[*].metadata.name}')

# Extracting all etcd keys/values to a file called "etcd-kv.json":
kubectl exec $ETCD_POD -n kube-system -- sh -c \
"ETCDCTL_API=3 etcdctl \
--endpoints $ADVERTISE_URL \
--cacert /etc/kubernetes/pki/etcd/ca.crt \
--key /etc/kubernetes/pki/etcd/server.key \
--cert /etc/kubernetes/pki/etcd/server.crt \
get \"\" --prefix=true -w json" > etcd-kv.json

Now you have all the keys/values pairs from etcd, you just need to filter to extract the information you need.现在你有了来自 etcd 的所有键/值对,你只需要过滤来提取你需要的信息。 For example, to list all keys you can use the command:例如,要列出所有键,您可以使用以下命令:

for k in $(cat etcd-kv.json | jq '.kvs[].key' | cut -d '"' -f2);  do echo $k | base64 --decode;  echo;  done

and to count the number of keys, just use the command wc -l on the end of this command, like:并计算键的数量,只需在此命令末尾使用命令wc -l ,例如:

for k in $(cat etcd-kv.json | jq '.kvs[].key' | cut -d '"' -f2);  do echo $k | base64 --decode; echo; done | echo "Total keys=$(wc -l)"
Total keys=308

References:参考:

A closer look at etcd: The brain of a kubernetes cluster 深入了解 etcd:kubernetes 集群的大脑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM