Skip to content

Commit 87e414a

Browse files
authored
Merge pull request #106 from Helene/multiple_pmsensors_configs
Add parsing for multiple pmsensors config files
2 parents 625e5fa + e5c4926 commit 87e414a

File tree

5 files changed

+284
-12
lines changed

5 files changed

+284
-12
lines changed

source/queryHandler/SensorConfig.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
pass
3030

3131
mmsdrfsFile = '/var/mmfs/gen/mmsdrfs'
32-
zimonFile = '/opt/IBM/zimon/ZIMonSensors.cfg'
32+
zimonFile = '/opt/IBM/zimon'
3333
collectorsFile = '/opt/IBM/zimon/ZIMonCollector.cfg'
3434

3535

@@ -57,36 +57,57 @@ def readSensorsConfigFromMMSDRFS(logger=None):
5757
return parseSensorsConfig(data, logger)
5858

5959

60-
def readSensorsConfig(logger=None):
60+
def readSensorsConfig(logger=None, customFile=None):
6161
'''
6262
:return: list of dictionaries with sensorsName as key and the values of the sensors in the ZimonSensors.cfg
6363
'''
6464
if not logger:
6565
logger = SysmonLogger.getLogger(__name__)
6666

67-
if not os.path.isfile(zimonFile):
67+
global zimonFile
68+
if customFile:
69+
zimonFile = rf"{customFile}"
70+
71+
sensorConfigFiles = []
72+
parsedSensors = []
73+
74+
if os.path.isfile(zimonFile):
75+
sensorConfigFiles.append(zimonFile)
76+
elif os.path.isdir(zimonFile):
77+
for root, dirs, files in os.walk(zimonFile):
78+
for file in files:
79+
if file.endswith(".cfg"):
80+
sensorConfigFiles.append(os.path.join(root, file))
81+
else:
6882
logger.details("ZiMon sensor configuration file not found (%s) ", zimonFile)
6983
print("ZiMon sensor configuration file not found")
7084
raise OSError(2, 'No such file or directory', zimonFile)
7185

7286
data = ""
7387
logger.debug("readSensorsConfig attempt to read %s", zimonFile)
74-
try:
75-
with open(zimonFile) as myfile:
76-
data = myfile.read().replace('\n', '')
77-
except (Exception, IOError) as error:
78-
logger.details("failed trying read %s with reason: %s", zimonFile, error)
79-
return []
80-
# parse config file in a list of dictionaries format
81-
return parseSensorsConfig(data, logger)
88+
for file in sensorConfigFiles:
89+
try:
90+
with open(file) as myfile:
91+
data = myfile.read().replace('\n', '')
92+
except (Exception, IOError) as error:
93+
logger.details("failed trying read %s with reason: %s", zimonFile, error)
94+
continue
95+
# parse config file in a list of dictionaries format
96+
parsedSensors.extend(parseSensorsConfig(data, logger))
97+
return parsedSensors
8298

8399

84100
def parseSensorsConfig(sensorsConfig, logger):
85101
""" Returns a list of dicts, describing definitions of sensors """
86102
logger.debug("invoke parseSensorsConfig")
87103
try:
88104
sensors = []
89-
sensorsStr = sensorsConfig[sensorsConfig.find("sensors"):sensorsConfig.find("smbstat")]
105+
sensorsStr = ""
106+
if sensorsConfig.find("smbstat") != -1:
107+
sensorsStr = sensorsConfig[sensorsConfig.find("sensors"):sensorsConfig.find("smbstat")]
108+
else:
109+
end = None
110+
sensorsStr = sensorsConfig[sensorsConfig.find("sensors"):end]
90111
sensorsList = re.findall('(?P<sensor>{.*?})(?:,|$)', sensorsStr)
91112
for sensorString in sensorsList:
92113
sensorAttr = re.findall(r'(?P<name>\w+) = (?P<value>\"\S*\"|\d+)', sensorString)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
colCandidates = "ibm-spectrum-scale-pmcollector-0.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local", "ibm-spectrum-scale-pmcollector-1.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local"
2+
colRedundancy = 2
3+
collectors = {
4+
host = "ibm-spectrum-scale-pmcollector-0.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local"
5+
port = "4739"
6+
}, {
7+
host = "ibm-spectrum-scale-pmcollector-1.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local"
8+
port = "4739"
9+
}
10+
#config = "/opt/IBM/zimon/ZIMonSensors.cfg"
11+
daemonize = T
12+
delay_initial_poll = T
13+
#hostname = ""
14+
#ipfixinterface = "0.0.0.0"
15+
#logfile = "/var/log/zimon/ZIMonSensors.log"
16+
#logfile = "stdout"
17+
loglevel = "info"
18+
piddir = "/var/run"
19+
release = "5.1.4-0"
20+
sensors = {
21+
name = "NFSIO"
22+
period = 10
23+
type = "Generic"
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
colCandidates = "ibm-spectrum-scale-pmcollector-0.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local", "ibm-spectrum-scale-pmcollector-1.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local"
2+
colRedundancy = 2
3+
collectors = {
4+
host = "ibm-spectrum-scale-pmcollector-0.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local"
5+
port = "4739"
6+
}, {
7+
host = "ibm-spectrum-scale-pmcollector-1.ibm-spectrum-scale-pmcollector.ibm-spectrum-scale.svc.cluster.local"
8+
port = "4739"
9+
}
10+
#config = "/opt/IBM/zimon/ZIMonSensors.cfg"
11+
daemonize = T
12+
delay_initial_poll = T
13+
#hostname = ""
14+
#ipfixinterface = "0.0.0.0"
15+
#logfile = "/var/log/zimon/ZIMonSensors.log"
16+
#logfile = "stdout"
17+
loglevel = "info"
18+
piddir = "/var/run"
19+
release = "5.1.4-0"
20+
sensors = {
21+
name = "NFSIO"
22+
period = 10
23+
type = "Generic"
24+
}
25+
smbstat = ""

tests/test_data/ZIMonSensors.cfg

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
cephMon = "/opt/IBM/zimon/CephMonProxy"
2+
cephRados = "/opt/IBM/zimon/CephRadosProxy"
3+
colCandidates = "c699gpfs01-ib0.c699.net"
4+
colRedundancy = 1
5+
collectors = {
6+
host = "c699gpfs01-ib0.c699.net"
7+
port = "4739"
8+
}
9+
config = "/opt/IBM/zimon/ZIMonSensors.cfg"
10+
ctdbstat = ""
11+
daemonize = T
12+
hostname = ""
13+
ipfixinterface = "0.0.0.0"
14+
logfile = "/var/log/zimon/ZIMonSensors.log"
15+
loglevel = "info"
16+
mmcmd = "/opt/IBM/zimon/MMCmdProxy"
17+
mmdfcmd = "/opt/IBM/zimon/MMDFProxy"
18+
mmpmon = "/opt/IBM/zimon/MmpmonSockProxy"
19+
piddir = "/var/run"
20+
release = "5.0.0-1"
21+
sensors = {
22+
name = "CPU"
23+
period = 1
24+
},
25+
{
26+
name = "Load"
27+
period = 1
28+
},
29+
{
30+
name = "Memory"
31+
period = 1
32+
},
33+
{
34+
name = "Network"
35+
period = 1
36+
},
37+
{
38+
name = "Netstat"
39+
period = 10
40+
},
41+
{
42+
name = "Diskstat"
43+
period = 0
44+
},
45+
{
46+
name = "DiskFree"
47+
period = 600
48+
},
49+
{
50+
name = "Infiniband"
51+
period = 1
52+
},
53+
{
54+
name = "GPFSDisk"
55+
period = 0
56+
},
57+
{
58+
name = "GPFSFilesystem"
59+
period = 0
60+
},
61+
{
62+
name = "GPFSNSDDisk"
63+
period = 0
64+
restrict = "nsdNodes"
65+
},
66+
{
67+
name = "GPFSPoolIO"
68+
period = 10
69+
},
70+
{
71+
name = "GPFSVFS"
72+
period = 10
73+
},
74+
{
75+
name = "GPFSIOC"
76+
period = 10
77+
},
78+
{
79+
name = "GPFSVIO64"
80+
period = 0
81+
},
82+
{
83+
name = "GPFSPDDisk"
84+
period = 0
85+
restrict = "nsdNodes"
86+
},
87+
{
88+
name = "GPFSvFLUSH"
89+
period = 0
90+
},
91+
{
92+
name = "GPFSNode"
93+
period = 10
94+
},
95+
{
96+
name = "GPFSNodeAPI"
97+
period = 10
98+
},
99+
{
100+
name = "GPFSFilesystemAPI"
101+
period = 0
102+
},
103+
{
104+
name = "GPFSLROC"
105+
period = 0
106+
},
107+
{
108+
name = "GPFSCHMS"
109+
period = 10
110+
},
111+
{
112+
name = "GPFSAFM"
113+
period = 0
114+
},
115+
{
116+
name = "GPFSAFMFS"
117+
period = 0
118+
},
119+
{
120+
name = "GPFSAFMFSET"
121+
period = 0
122+
},
123+
{
124+
name = "GPFSRPCS"
125+
period = 10
126+
},
127+
{
128+
name = "GPFSWaiters"
129+
period = 10
130+
},
131+
{
132+
name = "GPFSFilesetQuota"
133+
period = 0
134+
},
135+
{
136+
name = "GPFSFileset"
137+
period = 0
138+
restrict = "c699gpfs01-ib0.c699.net"
139+
},
140+
{
141+
name = "GPFSPool"
142+
period = 0
143+
restrict = "c699gpfs01-ib0.c699.net"
144+
},
145+
{
146+
name = "GPFSDiskCap"
147+
period = 0
148+
},
149+
{
150+
name = "GPFSLWEKafkaProducers"
151+
period = 0
152+
}
153+
smbstat = ""

tests/test_zimon_config_parser.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
from source.queryHandler.SensorConfig import readSensorsConfig
3+
from source.bridgeLogger import configureLogging
4+
from nose2.tools.such import helper as assert_helper
5+
from nose2.tools.decorators import with_setup
6+
7+
8+
def my_setup():
9+
global path, logger, mainSensorsConfig, wrongSensorsConfig, zimonFile, sensorsCount
10+
path = os.getcwd()
11+
logger = configureLogging(path, None)
12+
mainSensorsConfig = 'ZIMonSensors.cfg'
13+
wrongSensorsConfig = 'ZIMonSensors-protocols-wrong.cfg'
14+
sensorsCount = 0
15+
16+
17+
@with_setup(my_setup)
18+
def test_case01():
19+
with assert_helper.assertRaises(OSError):
20+
readSensorsConfig(logger)
21+
22+
23+
@with_setup(my_setup)
24+
def test_case02():
25+
zimonFile = os.path.join(path, "tests", "test_data", mainSensorsConfig)
26+
sensorsList = readSensorsConfig(logger, zimonFile)
27+
assert isinstance(sensorsList, list)
28+
assert len(sensorsList) > 0
29+
30+
31+
@with_setup(my_setup)
32+
def test_case03():
33+
zimonFile = os.path.join(path, "tests", "test_data", wrongSensorsConfig)
34+
sensorsList = readSensorsConfig(logger, zimonFile)
35+
assert isinstance(sensorsList, list)
36+
assert len(sensorsList) > 0
37+
38+
39+
@with_setup(my_setup)
40+
def test_case04():
41+
zimonFile = os.path.join(path, "tests", "test_data", mainSensorsConfig)
42+
sensorsList = readSensorsConfig(logger, zimonFile)
43+
sensorsCount = len(sensorsList)
44+
assert sensorsCount == 32
45+
46+
zimonFile = os.path.join(path, "tests", "test_data")
47+
sensorsList1 = readSensorsConfig(logger, zimonFile)
48+
assert isinstance(sensorsList1, list)
49+
assert len(sensorsList1) > len(sensorsList)

0 commit comments

Comments
 (0)