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

1.开启prometheus 插件

部署的是 EMQX 4.4 开源版, 则需要通过 EmqxPlugin CRD 开启emqx_prometheus 插件:

bash 复制代码
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

bash 复制代码
curl -u {AppID}:{AppSecret} -X GET localhost:18083/api/v4/emqx_prometheus?type=prometheus

2.配置 EMQX 服务的 Kubernetes Service

确保 EMQX 的接口通过一个 Kubernetes Service 暴露。

yaml 复制代码
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

yaml 复制代码
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

bash 复制代码
kubectl create secret generic emqx-basic-auth \
  --from-literal=username={AppID} \
  --from-literal=password={AppSecret}

5.验证Promethues 是否已经能读取到emqx的metric

相关推荐
tonngw3 小时前
【Mac 从 0 到 1 保姆级配置教程 16】- Docker 快速安装配置、常用命令以及实际项目演示
macos·docker·容器·开源·github·docker desktop·orbstack
Chan166 小时前
【 SpringCloud | 微服务 MQ基础 】
java·spring·spring cloud·微服务·云原生·rabbitmq
2201_761199047 小时前
k8s4部署
云原生·容器·kubernetes
慌ZHANG7 小时前
云原生技术驱动 IT 架构现代化转型:企业实践与落地策略全解
云原生
小柏ぁ7 小时前
calico/node is not ready: BIRD is not ready: BGP not established with xxx
运维·docker·kubernetes
三劫散仙9 小时前
kubernetes jenkins pipeline优化拉取大仓库性能指定分支+深度
容器·kubernetes·jenkins
西京刀客9 小时前
k8s热更新-subPath 不支持热更新
云原生·容器·kubernetes·configmap·subpath
weixin_434936289 小时前
k8S 命令
linux·容器·kubernetes
nuczzz11 小时前
GPU虚拟化
docker·kubernetes·k8s·gpu·nvidia
Johny_Zhao12 小时前
2025年6月Docker镜像加速失效终极解决方案
linux·网络·网络安全·docker·信息安全·kubernetes·云计算·containerd·yum源·系统运维