Prometheus监控Nginx是否没有数据

时间:2019-07-10 01:51:40

标签: prometheus-operator

每个人。我重写了nginx的图像,并通过二进制编译添加了nginx-module-vts。通过sidecar容器nginx-vts-exporter,我从主服务容器中获取JSON数据并将其转换为指标。我成功地手动获取了数据,但是在Prometheus页面上没有找到查询索引,只有nginx_vts_exporter_build_info。有人可以给我一些解决问题的想法吗?请。谢谢

enter image description here

enter image description here

这是我针对Nginx的Yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: zx-official-website
  namespace: monitoring
spec:
  replicas: 3
  selector:
    matchLabels:
      app: zx-official-website
      function: nginx
  template:
    metadata:
      labels:
        app: zx-official-website
        function: nginx
    spec:
      containers:
      - name: zx-official-website
        image: zx-official-website:1.0.1
        imagePullPolicy: Always
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 180
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 5
          timeoutSeconds: 1
      - name: nginx-exporter
        image: sophos/nginx-vts-exporter:latest
        env:
        - name: NGINX_STATUS
          value: http://localhost/status/format/json
        - name: METRICS_ENDPOINT
          value: /metrics
        - name: METRICS_ADDR
          value: :9913
        - name: METRICS_NS
          value: monitoring
        ports:
        - containerPort: 9913
          hostPort: 9913
          name: metrics

这是我的Nginx服务的Yaml文件

apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: nginx-exporter
  name: nginx-exporter
  namespace: monitoring
spec:
  clusterIP: None
  ports:
  - name: metrics
    port: 9913
    targetPort: metrics
  selector:
    function: nginx

这是我的Nginx serviceMonitor的Yaml文件

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: nginx-exporter
  name: nginx-exporter
  namespace: monitoring
spec:
  endpoints:
  - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
    interval: 30s
    port: metrics
    scheme: http
    tlsConfig:
      insecureSkipVerify: true
  jobLabel: k8s-app
  selector:
    matchLabels:
      k8s-app: nginx-exporter

0 个答案:

没有答案