# Copyright (C) 2016 Christopher Baines # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from prometheus_client.exposition import MetricsHandler index_page = """ Prometheus HAProxy Log Exporter

HAProxy Log exporter for Prometheus

This is a highly configurable exporter for HAProxy.

View metrics

Example Configuration

You must configure Prometheus to scrape the metrics exported here. The port is 9129, and the configuration should look something like the example below.


    scrape_configs:
      - job_name: haproxy_log
        target_groups:
          - targets:
            - MACHINE_ADDRESS:9129
  

Information

Copyright (C) 2016 Christopher Baines
View Licence

The source may be obtained from this Git repository

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

""" def create_request_handler(licence_location): class RequestHandler(MetricsHandler): def do_GET(self): if self.path == "/metrics": return super().do_GET() self.send_response(200) self.end_headers() if self.path == "/licence": with open( licence_location, 'rb', ) as licence: self.wfile.write(licence.read()) else: self.wfile.write(index_page.encode('UTF-8')) return RequestHandler