下载rocketmq-exporter
通过Docker仓库下载
docker pull sawyerlan/rocketmq-exporter:latest
然后打标签,推送到自己的仓库
也可通过代码自己build镜像
git clone GitHub - apache/rocketmq-exporter: Apache RocketMQ Prometheus Exporter
然后打标签,推送到自己的仓库
准备configMap
部署export前需要有一个可用的rocketmq环境,需要提前将rocketmq的namesrvAddr准备好
将namesrvAddr存入configMap中
vi rocketmq-standalone-exporter-cm.yamlapiVersion: v1
kind: ConfigMap
metadata:name: rocketmq-standalone-exporter-cmnamespace: develop
data:namesrvAddr: "--rocketmq.config.namesrvAddr=你的nameserver:9876"
创建configMap
kubectl apply -f rocketmq-standalone-exporter-cm.yaml
部署exporter
编写service和pod部署文件,使用上面configMap中的namesrvAddr
vi deployment.yamlapiVersion: v1
kind: Service
metadata:name: rocketmq-standalone-exporter-svclabels:app: rocketmq-standalone-exporter-svcapp.kubernetes.io/component: metricsapp.kubernetes.io/instance: rocketmq-standalone-exporternamespace: develop
spec:ports:- name: http-metricsport: 5557targetPort: 5557selector:app: rocketmq-standalone-exporterapp.kubernetes.io/component: metricsapp.kubernetes.io/instance: rocketmq-standalone-exportertype: ClusterIP---
apiVersion: apps/v1
kind: Deployment
metadata:name: rocketmq-standalone-exporternamespace: develop
spec:selector:matchLabels:app: rocketmq-standalone-exporterapp.kubernetes.io/component: metricsapp.kubernetes.io/instance: rocketmq-standalone-exporterreplicas: 1revisionHistoryLimit: 10template:metadata:labels:app: rocketmq-standalone-exporterapp.kubernetes.io/component: metricsapp.kubernetes.io/instance: rocketmq-standalone-exporterspec:containers:- name: rocketmq-standalone-exporterenv:- name: INTERVALvalueFrom:configMapKeyRef:name: rocketmq-standalone-exporter-cmkey: namesrvAddrimage: 你的仓库地址/sawyerlan/rocketmq-exporter:latestimagePullPolicy: Alwaysports:- containerPort: 5557name: portprotocol: TCPargs: ["$(INTERVAL)"]##args: ## 或者直接使用参数配置##- --rocketmq.config.namesrvAddr=你的namesrvAddr:9876
开始部署 kubectl apply -f deployment.yaml
检查 pod的log日志是否有异常
curl 查看你的svc:5557/metric能否获取指标数据
创建ServiceMonitor
定时将指标数据存入到prometheus中
vi serviceMonitor-rocketmq-standalone.yamlapiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:labels:jobLabel: rocketmq-standalone-exportername: prometheus-prometheus-rocket-standalone-exporternamespace: develop
spec:endpoints:- interval: 60sport: http-metrics # 端口名称jobLabel: jobLabelnamespaceSelector: # 标签匹配 rocketmq standalone Service 所在的命名空间matchNames:- developselector: # 标签匹配 rocketmq standalone ServicematchLabels:app: rocketmq-standalone-exporter-svcapp.kubernetes.io/component: metricsapp.kubernetes.io/instance: rocketmq-standalone-exporter
创建 kubectl apply -f serviceMonitor-rocketmq-standalone.yaml
验证
查看config是否生效,等会会自动刷到配置文件中
http://你的k8s地址:9090端口对应的3xxxx端口/config
最下面是否有
job_name: serviceMonitor/develop/prometheus-prometheus-rocket-standalone-exporter/0
待出现后,过会就去检查一下target
http://你的k8s地址:9090端口对应的3xxxx端口/targets
最下面是否有
serviceMonitor/develop/prometheus-prometheus-rocket-standalone-exporter/0 (1/1 up)
查看监控grafana
导入一个模板 14612 or 10477