安装mysqld_export
找一台服务器安装即可,按照 https://github.com/prometheus/mysqld_exporter 文档安装即可
Kubernetes配置
配置End-Pointer
apiVersion: v1
kind: Endpoints
metadata:labels:app: mysqld-exporter-metricsname: mysqld-exporter-metricsnamespace: monitoringresourceVersion: "37417798"uid: 629a0ed2-9200-4129-97ed-a77014141714
subsets:
- addresses:- ip: #Mysqld_Exporter地址ports:- name: metricsport: 9104 #指标暴露的端口protocol: TCP
配置Service
apiVersion: v1
kind: Service
metadata:labels:app: mysqld-exporter-metricsname: mysqld-exporter-metricsnamespace: monitoring
spec:internalTrafficPolicy: ClusteripFamilies:- IPv4ipFamilyPolicy: SingleStackports:- name: metricsport: 9913protocol: TCPtargetPort: 9913sessionAffinity: Nonetype: ClusterIP
配置ServiceMonitor即可
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:generation: 1labels:app: mysqld-exporter-metricsname: mysqld-exporter-metricsnamespace: monitoring
spec:endpoints:- honorLabels: trueinterval: 10spath: /metricsport: metricsscheme: httpscrapeTimeout: 10snamespaceSelector:matchNames:- monitoringsampleLimit: 0selector:matchLabels:app: external-nginx