下载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.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: rocketmq-standalone-exporter-cm
namespace: develop
data:
namesrvAddr: "--rocketmq.config.namesrvAddr=你的nameserver:9876"
创建configMap
kubectl apply -f rocketmq-standalone-exporter-cm.yaml
部署exporter
编写service和pod部署文件,使用上面configMap中的namesrvAddr
vi deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: rocketmq-standalone-exporter-svc
labels:
app: rocketmq-standalone-exporter-svc
app.kubernetes.io/component: metrics
app.kubernetes.io/instance: rocketmq-standalone-exporter
namespace: develop
spec:
ports:
- name: http-metrics
port: 5557
targetPort: 5557
selector:
app: rocketmq-standalone-exporter
app.kubernetes.io/component: metrics
app.kubernetes.io/instance: rocketmq-standalone-exporter
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rocketmq-standalone-exporter
namespace: develop
spec:
selector:
matchLabels:
app: rocketmq-standalone-exporter
app.kubernetes.io/component: metrics
app.kubernetes.io/instance: rocketmq-standalone-exporter
replicas: 1
revisionHistoryLimit: 10
template:
metadata:
labels:
app: rocketmq-standalone-exporter
app.kubernetes.io/component: metrics
app.kubernetes.io/instance: rocketmq-standalone-exporter
spec:
containers:
- name: rocketmq-standalone-exporter
env:
- name: INTERVAL
valueFrom:
configMapKeyRef:
name: rocketmq-standalone-exporter-cm
key: namesrvAddr
image: 你的仓库地址/sawyerlan/rocketmq-exporter:latest
imagePullPolicy: Always
ports:
- containerPort: 5557
name: port
protocol: TCP
args: ["$(INTERVAL)"]
##args: ## 或者直接使用参数配置
##- --rocketmq.config.namesrvAddr=你的namesrvAddr:9876
开始部署 kubectl apply -f deployment.yaml
检查 pod的log日志是否有异常
curl 查看你的svc:5557/metric能否获取指标数据
创建ServiceMonitor
定时将指标数据存入到prometheus中
vi serviceMonitor-rocketmq-standalone.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
jobLabel: rocketmq-standalone-exporter
name: prometheus-prometheus-rocket-standalone-exporter
namespace: develop
spec:
endpoints:
- interval: 60s
port: http-metrics # 端口名称
jobLabel: jobLabel
namespaceSelector: # 标签匹配 rocketmq standalone Service 所在的命名空间
matchNames:
- develop
selector: # 标签匹配 rocketmq standalone Service
matchLabels:
app: rocketmq-standalone-exporter-svc
app.kubernetes.io/component: metrics
app.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