aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2016-01-16 16:34:16 +0000
committerChristopher Baines <mail@cbaines.net>2016-01-16 16:34:16 +0000
commitc60738977e42af061ef9ff7f4f275c4a72deb2ae (patch)
treedac76cd0109cfa2200e82e24b142f6af768bd40b
parent20ee0b87aa4ff59df5b409f723358487ad64b632 (diff)
downloadprometheus-pgbouncer-exporter-c60738977e42af061ef9ff7f4f275c4a72deb2ae.tar
prometheus-pgbouncer-exporter-c60738977e42af061ef9ff7f4f275c4a72deb2ae.tar.gz
Add information about the licence to the web interface
-rw-r--r--prometheus_pgbouncer_exporter/cli.py19
-rw-r--r--prometheus_pgbouncer_exporter/exposition.py49
2 files changed, 58 insertions, 10 deletions
diff --git a/prometheus_pgbouncer_exporter/cli.py b/prometheus_pgbouncer_exporter/cli.py
index 7284baa..f0807ce 100644
--- a/prometheus_pgbouncer_exporter/cli.py
+++ b/prometheus_pgbouncer_exporter/cli.py
@@ -16,13 +16,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
-from http.server import HTTPServer
-
import configargparse
+
+from os.path import join, dirname, normpath
+from http.server import HTTPServer
from prometheus_client.core import REGISTRY
from .utils import get_connection
-from .exposition import RequestHandler
+from .exposition import create_request_handler
from .collectors import StatsCollector, ListsCollector, PoolsCollector, \
DatabasesCollector
@@ -61,6 +62,13 @@ def main():
env_var='PGBOUNCER_DATABASES',
)
+ p.add(
+ '--licence-location',
+ default=join(dirname(dirname(normpath(__file__))), 'LICENSE'),
+ help="The location of the licence, linked to through the web interface",
+ env_var='LICENCE_LOCATION',
+ )
+
options = p.parse_args()
logging.basicConfig(level=logging.DEBUG)
@@ -91,7 +99,10 @@ def main():
host = '0.0.0.0'
port = 9127
- httpd = HTTPServer((host, port), RequestHandler)
+ httpd = HTTPServer(
+ (host, port),
+ create_request_handler(options.licence_location),
+ )
logging.info("Listing on port %s:%d" % (host, port))
diff --git a/prometheus_pgbouncer_exporter/exposition.py b/prometheus_pgbouncer_exporter/exposition.py
index 4396b73..6f9123a 100644
--- a/prometheus_pgbouncer_exporter/exposition.py
+++ b/prometheus_pgbouncer_exporter/exposition.py
@@ -41,16 +41,53 @@ index_page = """
</p>
<a href="/metrics">View metrics</a>
+
+ <h2>Information</h2>
+ <p>
+ Copyright (C) 2015 Christopher Baines <mail@cbaines.net><br>
+ <a href="/licence">View Licence</a>
+ </p>
+
+ <p>
+ The source may be obtained from
+ <a href="http://git.cbaines.net/prometheus-pgbouncer-exporter/">
+ this Git repository</a>
+ </p>
+
+ <p>
+ 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.
+ </p>
+
+ <p>
+ 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.
+ </p>
</body>
</html>
"""
-class RequestHandler(MetricsHandler):
- def do_GET(self):
- if self.path == "/metrics":
- return super().do_GET()
- else:
+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()
- self.wfile.write(index_page.encode('UTF-8'))
+
+ 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