Prometheus ServiceMonitor

Prometheus ServiceMonitor

 

创建一个新的serviceMonitor就创建了一个prometheus的target

[root@k8s-m1 ~]# cat ServiceMonitor.yaml 
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
     k8s-app: xxx-exporter
  name: xxx
  namespace: prometheus 
spec:
  endpoints:
  - interval: 15s
    port:  xxx-exporter
  jobLabel:  xxx-exporter-monitor 
  namespaceSelector:
    matchNames:
    - monitor                #目标服务的namespaces
  selector:
    matchLabels:
      k8s-app: xx-exporter  目标服务的labels
  namespaceSelector:
    any: true   选择所有的namespace

上面ServiceMonitor是针对k8s集群内部服务监控,想监控集群外部的exporter通Endpoints实现

# 为外部 exporter 服务设置 service
kind: Service
apiVersion: v1
metadata:
  namespace: monitor
  name: service-mysql-xx
  labels:
    app: service-mysql-xx
spec:
  ports:
    - protocol: TCP
      port: 9xx
      targetPort: 9xx
  type: ClusterIP
  clusterIP: None

---
kind: Endpoints
apiVersion: v1
metadata:
  namespace: monitor
  name: service-mysql-xx
  labels:
    app: service-mysql-xx
subsets:
  - addresses:
      - ip: x.x.x.x
    ports:
      - protocol: TCP
        port: 9xxx

ServiceMonitor

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
    name: service-mysql-xx
    labels:
        app: service-mysql-xx
spec:
    selector:
        matchLabels:
            app: service-mysql-xx
        namespaceSelector:
            matchNames:
            - monitor
    endpoints:
    - port: metrics
      interval: 10s
      honorLabels: true
上一篇:常用的exporter下载


下一篇:prometheus 普罗米修斯安装