#!/usr/bin/python3 # Copyright (C) 2015 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 PgBouncer Exporter

PgBouncer exporter for Prometheus

This is a simple exporter for PgBouncer that makes several metrics available to Prometheus.

Metrics are exported from the SHOW LISTS, STATS, POOLS and DATABASES comand output.

View metrics

Example Configuration

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


    scrape_configs:
      - job_name: pgbouncer
        target_groups:
          - targets:
            - MACHINE_ADDRESS:9127
  

Information

Copyright (C) 2015 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