在k8s上暴露EMQX(v4)的指标
1.开启prometheus 插件
部署的是 EMQX 4.4 开源版, 则需要通过 EmqxPlugin CRD 开启emqx_prometheus 插件:
cat << "EOF" | kubectl apply -f -
apiVersion: apps.emqx.io/v1beta4
kind: EmqxPlugin
metadata:
name: emqx-prometheus
spec:
pluginName: emqx_prometheus
selector:
apps.emqx.io/instance: emqx
apps.emqx.io/managed-by: emqx-operator
获取AppID和AppSecret
curl -u {AppID}:{AppSecret} -X GET localhost:18083/api/v4/emqx_prometheus?type=prometheus
2.配置 EMQX 服务的 Kubernetes Service
确保 EMQX 的接口通过一个 Kubernetes Service 暴露。
kind: Service
apiVersion: v1
metadata:
name: emqx-prometheus
labels:
app: emqx
spec:
ports:
- name: prometheus
protocol: TCP
port: 18083
targetPort: 18083
type: ClusterIP
selector:
apps.emqx.io/instance: emqx
apps.emqx.io/managed-by: emqx-operator
3.创建 ServiceMonitor
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: emqx-monitor
spec:
endpoints:
- basicAuth:
password:
key: password
name: emqx-basic-auth
username:
key: username
name: emqx-basic-auth
params:
type:
- prometheus
path: /api/v4/emqx_prometheus
port: prometheus
scheme: http
namespaceSelector:
matchNames:
- mes-emqx
selector:
matchLabels:
app: emqx
4.创建 BasicAuth Secret
kubectl create secret generic emqx-basic-auth \
--from-literal=username={AppID} \
--from-literal=password={AppSecret}
5.验证Promethues 是否已经能读取到emqx的metric
原文地址:https://blog.csdn.net/qq_32789063/article/details/144447428
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!