forked from ceph/ceph-iscsi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rbd-target-gw.py
executable file
·89 lines (63 loc) · 2.55 KB
/
rbd-target-gw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
import logging
import logging.handlers
from logging.handlers import RotatingFileHandler
from flask import Flask, Response
from ceph_iscsi_config.metrics import GatewayStats
import ceph_iscsi_config.settings as settings
# Create a flask instance
app = Flask(__name__)
@app.route("/", methods=["GET"])
def prom_root():
""" handle the '/' endpoint - just redirect point the user at /metrics"""
return '''<!DOCTYPE html>
<html>
<head><title>Ceph/iSCSI Prometheus Exporter</title></head>
<body>
<h1>Ceph/iSCSI Prometheus Exporter</h1>
<p><a href='/metrics'>Metrics</a></p>
</body>
</html>'''
@app.route("/metrics", methods=["GET"])
def prom_metrics():
""" Collect the stats and send back to the caller"""
stats = GatewayStats()
stats.collect()
return Response(stats.formatted(),
content_type="text/plain")
def main():
if settings.config.prometheus_exporter:
logger.info("Integrated Prometheus exporter is enabled")
# starting a flask instance will occupy the main thread
# Attach the werkzeug log to the handlers defined in the outer scope
log = logging.getLogger('werkzeug')
log.setLevel(logging.DEBUG)
log.addHandler(file_handler)
log.addHandler(syslog_handler)
app.run(host=settings.config.prometheus_host,
port=settings.config.prometheus_port,
debug=False,
threaded=True)
else:
logger.info("Integrated Prometheus exporter is disabled")
if __name__ == '__main__':
settings.init()
logger_level = logging.getLevelName(settings.config.logger_level)
# setup syslog handler to help diagnostics
logger = logging.getLogger('rbd-target-gw')
logger.setLevel(logging.DEBUG)
# syslog (systemctl/journalctl messages)
syslog_handler = logging.handlers.SysLogHandler(address='/dev/log')
syslog_handler.setLevel(logging.INFO)
syslog_format = logging.Formatter("%(message)s")
syslog_handler.setFormatter(syslog_format)
# file target - more verbose logging for diagnostics
file_handler = RotatingFileHandler('/var/log/rbd-target-gw/rbd-target-gw.log',
maxBytes=5242880,
backupCount=7)
file_handler.setLevel(logger_level)
file_format = logging.Formatter("%(asctime)s [%(levelname)8s] - %(message)s")
file_handler.setFormatter(file_format)
logger.addHandler(syslog_handler)
logger.addHandler(file_handler)
main()