配置普罗米修斯目标以从文本文件中读取指标

configure prometheus targets to read metrics from text file

是否可以将 Prometheus 配置为使用文本文件作为指标来源?

我试过配置 prometheus.yml 如下所示,但没有用。

scrape_configs:
  - job_name: 'custom_job'
    static_configs:
    - targets: ['C:\CustomJobLogs\metrics.txt']

Prometheus 是否支持来自文本文件的指标?

如果您使用 windows,请使用来自 wmi_exporter

的文本文件收集器

如果您使用 linux,请使用 node_exporter

中的文本文件收集器

实际上这似乎不可能:

  static_configs:

     -targets: ['C:\CustomJobLogs\metrics.txt']

但是,可以通过将 metrics.txt 暴露给 http 并将目标添加到 host:port

prometheus.yaml可配置:

global:
    scrape_interval: 10s
scrape_configs:
    - job_name: example
    metrics_path: /metrics
    static_configs:
    - targets:
        - localhost:5000

使用 flask 将 metrics.txt 公开到 http 的示例(也可以使用 wsgi 或任何其他):

  from flask import Flask

  app = Flask(__name__)
  @app.route("/metrics", methods=['GET'])
  def getfile():
      with open("metrics.txt", "r+") as f:
          data = f.read()
      return data

  if __name__ == '__main__':
      app.run(host='localhost')