普罗米修斯无法刮擦uwsgi

时间:2019-08-14 16:47:37

标签: uwsgi prometheus

我正在尝试prometheus在端口uwsgi上刮擦7070容器

我在prometheus.yaml中有以下抓取工作

- job_name: 'kubernetes-pods'
  kubernetes_sd_configs:
    - role: pod
  relabel_configs:
    - action: labelmap
      regex: __meta_kubernetes_pod_label_(.+)
    - source_labels: [__meta_kubernetes_namespace]
      action: replace
      target_label: kubernetes_namespace
    - source_labels: [__meta_kubernetes_pod_name]
      action: replace
      target_label: kubernetes_pod_name
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
      action: keep
      regex: true
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme]
      action: replace
      target_label: __scheme__
      regex: (https?)
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
      action: replace
      target_label: __metrics_path__
      regex: (.+)
    - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
      action: replace
      target_label: __address__
      regex: ([^:]+)(?::\d+)?;(\d+)
      replacement: $1:$2

还具有uwsgi容器的注释:

  annotations:
     prometheus.io/scrape: "true"
     prometheus.io/port: "7070"

如果我从任何容器中curl http://<host_ip>:7070/metrics,它将返回json格式指标。

但是当我做curl http://<host_ip>:7070/metrics | promtool check metrics时。

我得到error while linting: text format parsing error in line 1: invalid metric name

我认为这是因为uwsgi容器以json格式公开了指标,而prometheus无法理解json

我需要怎么做才能使其被prometheus抓取?

2 个答案:

答案 0 :(得分:0)

https://www.robustperception.io/writing-json-exporters-in-python 这应该是你的答案。因此,您需要编写JSON导出器

答案 1 :(得分:0)

设法将https://github.com/timonwong/uwsgi_exporter作为随身行李容器来完成此操作。

  - name: uwsgi
    image: .....
  - name: uwsgi-exporter
    image: timonwong/uwsgi-exporter:latest
    imagePullPolicy: Always
    resources:
      requests:
        cpu: 100m
        memory: 100Mi
    ports:
    - name: uwsgi-exp-port
      containerPort: 9117
      protocol: TCP
    args:
      - --stats.uri=http://localhost:7070/metrics