欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > 在k8s上暴露EMQX(v4)的指标

在k8s上暴露EMQX(v4)的指标

2025/2/25 19:34:10 来源:https://blog.csdn.net/qq_32789063/article/details/144447428  浏览:    关键词:在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_prometheusselector:apps.emqx.io/instance: emqxapps.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-prometheuslabels:app: emqx
spec:ports:- name: prometheusprotocol: TCPport: 18083targetPort: 18083type: ClusterIPselector:apps.emqx.io/instance: emqxapps.emqx.io/managed-by: emqx-operator

3.创建 ServiceMonitor

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:name: emqx-monitor
spec:endpoints:- basicAuth:password:key: passwordname: emqx-basic-authusername:key: usernamename: emqx-basic-authparams:type:- prometheuspath: /api/v4/emqx_prometheusport: prometheusscheme: httpnamespaceSelector:matchNames:- mes-emqxselector: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

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词