Skip to content

Commit 16aee0f

Browse files
Merge pull request #2188 from openvstorage/retrieve_graphite_config
Added a method to easily fetch the graphite config
2 parents f1d4842 + fa8961b commit 16aee0f

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

ovs/extensions/generic/graphiteclient.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# Open vStorage is distributed in the hope that it will be useful,
1515
# but WITHOUT ANY WARRANTY of any kind.
1616

17-
import time
18-
import socket
1917
from ovs.extensions.generic.configuration import Configuration
2018
from ovs_extensions.generic.configuration.exceptions import ConfigurationNotFoundException as NotFoundException
2119
from ovs_extensions.generic.graphiteclient import GraphiteClient as _graphite_client
@@ -39,14 +37,14 @@ def __init__(self, ip=None, port=None, database=None):
3937
:param database: name of the database
4038
:type database: str
4139
"""
40+
graphite_data = {}
4241
if all(p is None for p in [ip, port]):
4342
# Nothing specified
44-
try:
45-
graphite_data = Configuration.get(self.CONFIG_PATH)
46-
except NotFoundException:
43+
graphite_data = self.get_graphite_config()
44+
if not graphite_data:
4745
raise RuntimeError('No graphite data found in config path `{0}`'.format(self.CONFIG_PATH))
4846

49-
ip = ip or graphite_data['host']
47+
ip = ip or graphite_data['ip']
5048
port = port or graphite_data.get('port', 2003)
5149

5250
ExtensionsToolbox.verify_required_params(verify_keys=True,
@@ -86,3 +84,17 @@ def send_statsmonkey_data(self, sm_data, function_name):
8684
for fieldkey, fieldvalue in datapointset['fields'].items():
8785
tmp_path = '{0}.{1}'.format(path, fieldkey)
8886
self.send(tmp_path, fieldvalue)
87+
88+
@classmethod
89+
def get_graphite_config(cls):
90+
# type: () -> Dict[str, Union[str, int]]
91+
"""
92+
Retrieve the graphite config (if any)
93+
:return:
94+
"""
95+
try:
96+
graphite_data = Configuration.get(cls.CONFIG_PATH)
97+
return {'ip': graphite_data['host'],
98+
'port': graphite_data.get('port', 2003)}
99+
except NotFoundException:
100+
return {}

0 commit comments

Comments
 (0)