configure prometheus targets to read metrics from text file

Viewed 4475

is it possible to configure Prometheus to use text file as the source of metrics?

i tried config prometheus.yml like below but that not works.

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

does Prometheus support metrics from text file or not?

2 Answers

if you use windows, use textfile collector from wmi_exporter

and if you use linux, use textfile collector from node_exporter

Actually this seems not possible:

  static_configs:

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

But, it can be dobe by exposing metrics.txt to http and add the targets to that host:port

prometheus.yaml can be configured:

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

Example for exposing the metrics.txt to http using flask(wsgi or any other can also be used):

  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')
Related