Skip to content

Commit fec8219

Browse files
committed
prometheus ssl connection
Signed-off-by: hwassman <[email protected]>
1 parent 17f0060 commit fec8219

File tree

5 files changed

+164
-22
lines changed

5 files changed

+164
-22
lines changed
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: 19 additions & 8 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,12 +36,22 @@ 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

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

109120

110-
class Singleton(type):
111-
_inst = {}
121+
#class Singleton(type):
122+
# _inst = {}
112123

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]
124+
# def __call__(clazz, *args, **kwargs):
125+
# if clazz not in clazz._inst:
126+
# clazz._inst[clazz] = super(Singleton, clazz).__call__(*args, **kwargs)
127+
# return clazz._inst[clazz]
117128

118129

119130
class ConfigManager(object, metaclass=Singleton):

source/config.ini

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
##################### 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-
#################################### OpenTSDB API SSL 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,8 +28,7 @@ protocol = http
2028
# Name of tls certificate file
2129
#tlsCertFile = cert.pem
2230

23-
##################### Prometheus Connection Defaults ##########################
24-
# prometheus = 9250
31+
2532

2633
#################################### GPFS Server ##############################
2734
[server]
@@ -62,7 +69,8 @@ includeDiskData = no
6269
# Directory where the bridge can store logs
6370
logPath = /var/log/ibm_bridge_for_grafana
6471

65-
# 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)
6674
logLevel = 15
6775

6876
# 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/zimonGrafanaIntf.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,12 @@ def bind_prometheus_server(args):
109109
prometheus_server = cherrypy._cpserver.Server()
110110
prometheus_server.socket_port = args.get('prometheus')
111111
prometheus_server._socket_host = '0.0.0.0'
112-
prometheus_server.subscribe()
113-
114-
115-
def updateCherrypySslConf(args):
116112
certPath = os.path.join(args.get('tlsKeyPath'), args.get('tlsCertFile'))
117113
keyPath = os.path.join(args.get('tlsKeyPath'), args.get('tlsKeyFile'))
118-
sslConfig = {'global': {'server.ssl_module': 'builtin',
119-
'server.ssl_certificate': certPath,
120-
'server.ssl_private_key': keyPath}}
121-
cherrypy.config.update(sslConfig)
114+
prometheus_server.ssl_module = 'builtin'
115+
prometheus_server.ssl_certificate = certPath
116+
prometheus_server.ssl_private_key = keyPath
117+
prometheus_server.subscribe()
122118

123119

124120
def resolveAPIKeyValue(storedKey):

0 commit comments

Comments
 (0)