Skip to content

Commit

Permalink
Making host_exporter a Flask app that runs via mod_wsgi
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNeto committed Aug 13, 2024
1 parent 04e9da9 commit 754de72
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<IfModule proxy_module>
ProxyRequests Off
<Proxy *>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
<IfVersion < 2.4>
Order deny,allow
Allow from all
</IfVersion>
</Proxy>
# WSGI settings
WSGIDaemonProcess host_exporter display-name=host_exporter user=perfsonar group=perfsonar threads=5
WSGIScriptAlias /perfsonar_host_exporter /var/www/html/perfsonar/host_exporter/host_exporter.wsgi
WSGIApplicationGroup %{GLOBAL}

ProxyPass /perfsonar_host_exporter http://localhost:11284 status=+I
ProxyPassReverse /perfsonar_host_exporter http://localhost:11284 status=+I
ProxyPreserveHost On
</IfModule>
<Directory /var/www/html/perfsonar/host_exporter>

SSLRequireSSL

WSGIProcessGroup host_exporter
WSGIApplicationGroup host_exporter

Require all granted

</Directory>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# WSGI File for host_exporter
#
import sys

sys.path.insert(0, '/var/www/html/perfsonar/host_exporter')

from host_exporter.perfsonar_host_exporter import app as application

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import subprocess
from psconfig.utilities.metrics import PSConfigMetricCalculator
from psconfig.utilities.cli import PSCONFIG_CLI_AGENTS
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from flask import Flask, Response

class PSMetricsWebHandler(BaseHTTPRequestHandler):
app = Flask(__name__)

class PSMetricsWebHandler:
LS_BASE_URL = "http://35.223.142.206:8090/lookup/records"

def _read_one_liner(self, filename):
Expand Down Expand Up @@ -111,31 +113,24 @@ def lookup_svc_metrics(self):
ps_metric_output += 'perfsonar_host_registered{{uuid="{}"}} {}\n'.format(uuid, self._is_registered(uuid))

return ps_metric_output

def do_GET(self):
def gather_metrics(self):
ps_metric_output = ""

##
# toolkit/bundle metrics
ps_metric_output += self.bundle_metrics()

##
ps_metric_output += self.bundle_metrics()
# pScheduler metrics
ps_metric_output += self.pscheduler_metrics()

##
# pSConfig Metrics
ps_metric_output += self.psconfig_metrics()

##
# LS client uuid
ps_metric_output += self.lookup_svc_metrics()

self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.end_headers()
self.wfile.write(ps_metric_output.encode("utf-8"))
return ps_metric_output

@app.route("/")
def metrics():
handler = PSMetricsWebHandler()
metrics_data = handler.gather_metrics()
return Response(metrics_data, status=200, mimetype="text/plain")

if __name__ == "__main__":
##
Expand All @@ -147,7 +142,5 @@ def do_GET(self):
parser.add_argument('--host', dest='host', action='store', default='localhost', help='The host to listen for connections. 0.0.0.0 means all interfaces.')
parser.add_argument('--port', dest='port', action='store', type=int, default=11284, help='The port on which to listen for connections.')
args = parser.parse_args()

#Build server
server = ThreadingHTTPServer((args.host, args.port), PSMetricsWebHandler)
server.serve_forever()

app.run(host=args.host, port=args.port)

0 comments on commit 754de72

Please sign in to comment.