Linux technical support - [email protected]


python flask prometheus exporter

cat /srv/http-monitoring/http-monitoring.py 
#!/usr/bin/python

import commands,os,subprocess
from flask import Flask
from flask import Response
app = Flask(__name__)

frontends = [
'domain1.com:2080',
'domain2.com:2080',
'domain3.com:2080',
'domain4.com:2080',
]


o = ""

@app.route('/')
def hello_world():
    o = ""
    for frontend in frontends:
       output = subprocess.check_output('curl -s -w "%{time_total}\n" -o /dev/null http://' + frontend, shell=True)
       output = output.replace('\n', '')
       output = repr(output)
       output = output.replace('\'', '')
       output = output.replace(',', '.')
       output = 'responce_time_http {point="' + frontend +'"} ' + output
       global o
       o = o + output + "\n"
    resp = Response(o)
    resp.headers['Content-Type'] = 'text/plain; charset=utf-8'
    resp.headers['Connection'] = 'keep-alive'
    return resp

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=26743)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>