Skip to content

Commit 8d9a650

Browse files
authored
Merge pull request #142 from Helene/prometheus
Prometheus exporter initial version
2 parents c3f838e + f528dda commit 8d9a650

12 files changed

+504
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Grafana Bridge is a standalone Python application. It translates the IBM Storage
2020
* [Run the grafana bridge in a docker container](https://github.com/IBM/ibm-spectrum-scale-bridge-for-grafana/wiki/Running-the-IBM-Spectrum-Scale-Performance-Monitoring-Bridge-in-a-docker-container)
2121
* [Setup a Grafana environment for monitoring performance data of a CNSA cluster in a k8s OCP environment](https://github.com/IBM/ibm-spectrum-scale-bridge-for-grafana/wiki/Setup-Grafana-for-monitoring-a-CNSA-cluster--in-a-k8s-OCP-environment)
2222

23-
The ***latest article***:
23+
The ***latest*** article:
2424
* [How to setup Grafana instance to monitor multiple IBM Storage Scale clusters running in a cloud or mixed environment](https://github.com/IBM/ibm-spectrum-scale-bridge-for-grafana/wiki/How-to-setup-Grafana-instance-to-monitor-multiple-IBM-Storage-Scale-clusters-running-in-a-cloud-or-mixed-environment)
2525

2626
Find more helpful information about the bridge usage in the project [Wiki](https://github.com/IBM/ibm-spectrum-scale-bridge-for-grafana/wiki)

docs/AvailableDashboards.PNG

-140 KB
Binary file not shown.

docs/bridge_connect_grafana_ocp.png

-102 KB
Binary file not shown.

docs/grafana_bridge_overview.png

-152 KB
Binary file not shown.
120 KB
Loading
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# my global config
2+
global:
3+
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
4+
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
5+
# scrape_timeout is set to the global default (10s).
6+
query_log_file: /var/log/prometheus/query.log
7+
8+
# Alertmanager configuration
9+
alerting:
10+
alertmanagers:
11+
- static_configs:
12+
- targets:
13+
# - alertmanager:9093
14+
15+
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
16+
rule_files:
17+
# - "first_rules.yml"
18+
# - "second_rules.yml"
19+
20+
# A scrape configuration containing exactly one endpoint to scrape:
21+
# Here it's Prometheus itself.
22+
scrape_configs:
23+
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
24+
- job_name: 'prometheus'
25+
26+
# metrics_path defaults to '/metrics'
27+
# scheme defaults to 'http'.
28+
29+
static_configs:
30+
- targets: ["<prometheus_server_ip>:9090"]
31+
32+
- job_name: 'CPU'
33+
scrape_interval: 1s
34+
honor_timestamps: true
35+
metrics_path: '/metrics_cpu'
36+
scheme: https
37+
tls_config:
38+
cert_file: /etc/prometheus/certs/cert.pem
39+
key_file: /etc/prometheus/certs/privkey.pem
40+
insecure_skip_verify: true
41+
static_configs:
42+
- targets: ['<grafana_bridge_ip>:9250']
43+
44+
- job_name: 'Load'
45+
scrape_interval: 1s
46+
honor_timestamps: true
47+
metrics_path: '/metrics_load'
48+
scheme: https
49+
tls_config:
50+
cert_file: /etc/prometheus/certs/cert.pem
51+
key_file: /etc/prometheus/certs/privkey.pem
52+
insecure_skip_verify: true
53+
static_configs:
54+
- targets: ['<grafana_bridge_ip>:9250']
55+
56+
- job_name: 'Memory'
57+
scrape_interval: 1s
58+
honor_timestamps: true
59+
metrics_path: '/metrics_memory'
60+
scheme: https
61+
tls_config:
62+
cert_file: /etc/prometheus/certs/cert.pem
63+
key_file: /etc/prometheus/certs/privkey.pem
64+
insecure_skip_verify: true
65+
static_configs:
66+
- targets: ['<grafana_bridge_ip>:9250']
67+
68+
- job_name: 'Network'
69+
scrape_interval: 1s
70+
honor_timestamps: true
71+
metrics_path: '/metrics_network'
72+
scheme: https
73+
tls_config:
74+
cert_file: /etc/prometheus/certs/cert.pem
75+
key_file: /etc/prometheus/certs/privkey.pem
76+
insecure_skip_verify: true
77+
static_configs:
78+
- targets: ['<grafana_bridge_ip>:9250']
79+
80+
- job_name: 'Netstat'
81+
scrape_interval: 1s
82+
honor_timestamps: true
83+
metrics_path: '/metrics_netstat'
84+
scheme: https
85+
tls_config:
86+
cert_file: /etc/prometheus/certs/cert.pem
87+
key_file: /etc/prometheus/certs/privkey.pem
88+
insecure_skip_verify: true
89+
static_configs:
90+
- targets: ['<grafana_bridge_ip>:9250']
91+
92+
- job_name: 'DiskFree'
93+
scrape_interval: 600s
94+
honor_timestamps: true
95+
metrics_path: '/metrics_diskfree'
96+
scheme: https
97+
tls_config:
98+
cert_file: /etc/prometheus/certs/cert.pem
99+
key_file: /etc/prometheus/certs/privkey.pem
100+
insecure_skip_verify: true
101+
static_configs:
102+
- targets: ['<grafana_bridge_ip>:9250']
103+
104+
- job_name: 'GPFSFileset'
105+
scrape_interval: 300s
106+
honor_timestamps: true
107+
metrics_path: '/metrics_gpfs_fileset'
108+
scheme: https
109+
tls_config:
110+
cert_file: /etc/prometheus/certs/cert.pem
111+
key_file: /etc/prometheus/certs/privkey.pem
112+
insecure_skip_verify: true
113+
static_configs:
114+
- targets: ['<grafana_bridge_ip>:9250']
115+
116+
- job_name: 'GPFSPool'
117+
scrape_interval: 300s
118+
honor_timestamps: true
119+
metrics_path: '/metrics_gpfs_pool'
120+
scheme: https
121+
tls_config:
122+
cert_file: /etc/prometheus/certs/cert.pem
123+
key_file: /etc/prometheus/certs/privkey.pem
124+
insecure_skip_verify: true
125+
static_configs:
126+
- targets: ['<grafana_bridge_ip>:9250']

source/confParser.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import argparse
2424
import os
2525
from messages import MSG
26+
from metaclasses import Singleton
2627
import configparser
2728
import getpass
2829

@@ -35,18 +36,28 @@ def checkFileExists(path, filename):
3536

3637

3738
def checkTLSsettings(args):
38-
if args.get('protocol') == "https" and (not args.get('tlsKeyPath') or not args.get('tlsKeyFile') or not args.get('tlsCertFile')):
39+
if args.get('prometheus') and (not args.get('tlsKeyPath') or not
40+
args.get('tlsKeyFile') or not
41+
args.get('tlsCertFile')):
42+
return False, MSG['MissingSSLCert']
43+
elif args.get('protocol') == "https" and (not args.get('tlsKeyPath') or not
44+
args.get('tlsKeyFile') or not
45+
args.get('tlsCertFile')
46+
):
3947
return False, MSG['MissingParm']
4048
elif args.get('protocol') == "https" and not os.path.exists(args.get('tlsKeyPath')):
4149
return False, MSG['KeyPathError']
4250
elif args.get('protocol') == "https":
43-
if (not checkFileExists(args.get('tlsKeyPath'), args.get('tlsCertFile'))) or (not checkFileExists(args.get('tlsKeyPath'), args.get('tlsKeyFile'))):
51+
if (not checkFileExists(
52+
args.get('tlsKeyPath'), args.get('tlsCertFile'))
53+
) or (not checkFileExists(
54+
args.get('tlsKeyPath'), args.get('tlsKeyFile'))):
4455
return False, MSG['CertError']
4556
return True, ''
4657

4758

4859
def checkApplicationPort(args):
49-
if not args.get('port') or not args.get('apiKeyValue'):
60+
if not args.get('port', None) and not args.get('prometheus', None):
5061
return False, MSG['MissingParm']
5162
return True, ''
5263

@@ -107,15 +118,6 @@ def merge_defaults_and_args(defaults, args):
107118
return brConfig
108119

109120

110-
class Singleton(type):
111-
_inst = {}
112-
113-
def __call__(clazz, *args, **kwargs):
114-
if clazz not in clazz._inst:
115-
clazz._inst[clazz] = super(Singleton, clazz).__call__(*args, **kwargs)
116-
return clazz._inst[clazz]
117-
118-
119121
class ConfigManager(object, metaclass=Singleton):
120122
''' A singleton class managing the application configuration defaults '''
121123

source/config.ini

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
##################### Grafana Connection Defaults ############################
1+
##################### OpenTSDB API Connection Defaults ########################
22
[connection]
3-
# port number the bridge listening on for Grafana data requests
3+
# Port number the bridge listening on for Grafana data requests over
4+
# OpentTSDB plugin
5+
#
46
# 4242 - for HTTP connections
57
# 8443 - for HTTPS connections
68
# (Default: 4242)
@@ -9,7 +11,13 @@ port = 4242
911
# Protocol (http, https)
1012
protocol = http
1113

12-
#################################### Grafana Generic OAuth ####################
14+
##################### Prometheus Exporter API Connection Defaults #############
15+
# Port number the bridge listening on for Prometheus server https requests;
16+
# ssl cert and key configuration required
17+
18+
# prometheus = 9250
19+
20+
#################################### API SSL OAuth ############################
1321
[tls]
1422
# Directory path of tls key and cert file location
1523
#tlsKeyPath = /etc/bridge_cert/certs
@@ -20,6 +28,8 @@ protocol = http
2028
# Name of tls certificate file
2129
#tlsCertFile = cert.pem
2230

31+
32+
2333
#################################### GPFS Server ##############################
2434
[server]
2535
# The ip address to bind to, empty will bind to all interfaces
@@ -59,7 +69,8 @@ includeDiskData = no
5969
# Directory where the bridge can store logs
6070
logPath = /var/log/ibm_bridge_for_grafana
6171

62-
# log level 10 (DEBUG), 15 (MOREINFO), 20 (INFO), 30 (WARN), 40 (ERROR) (Default: 15)
72+
# log level 5 (TRACE) 10 (DEBUG), 15 (MOREINFO), 20 (INFO), 30 (WARN),
73+
# 40 (ERROR) (Default: 15)
6374
logLevel = 15
6475

6576
# Log file name (Default: zserver.log)

source/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
MSG = {'IntError': 'Server internal error occurred. Reason: {}',
2929
'sysStart': 'Initial cherryPy server engine start have been invoked. Python version: {}, cherryPy version: {}.',
3030
'MissingParm': 'Missing mandatory parameters, quitting',
31+
'MissingSSLCert': 'Missing ssl key and certificate configuration, quitting',
3132
'KeyPathError': 'KeyPath directory not found, quitting',
32-
'CertError': 'Missing certificates in tht specified keyPath directory, quitting',
33+
'CertError': 'Missing certificates in the specified keyPath directory, quitting',
3334
'CollectorErr': 'Failed to initialize connection to pmcollector: {}, quitting',
3435
'MetaError': 'Metadata could not be retrieved. Check log file for more details, quitting',
3536
'MetaSuccess': 'Successfully retrieved MetaData',

source/opentsdb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
class OpenTsdbApi(object):
3333
exposed = True
3434

35-
def __init__(self, logger, mdHandler):
35+
def __init__(self, logger, mdHandler, port):
3636
self.logger = logger
3737
self.__md = mdHandler
38+
self.port = port
3839

3940
@property
4041
def md(self):
@@ -273,6 +274,10 @@ def GET(self, **params):
273274
"""
274275
resp = []
275276

277+
conn = cherrypy.request.headers.get('Host').split(':')
278+
if int(conn[1]) != int(self.port):
279+
raise cherrypy.HTTPError(400, MSG[400])
280+
276281
# /api/suggest
277282
if 'suggest' in cherrypy.request.script_name:
278283
resp = self.suggest(params)

0 commit comments

Comments
 (0)