Skip to content

Commit c9d485f

Browse files
committed
Fix load perfdata
1 parent 52c814e commit c9d485f

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

check_monit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def get_service_output(service_type, element):
9494
load1 = float(element.findall('system/load/avg01')[0].text)
9595
load5 = float(element.findall('system/load/avg05')[0].text)
9696
load15 = float(element.findall('system/load/avg15')[0].text)
97-
output.append('load={0},{1},{2}'.format(load1, load5, load15))
97+
output.append('load1={0};load5={1};load15={2}'.format(load1, load5, load15))
9898

9999
user = float(element.findall('system/cpu/user')[0].text)
100100
system = float(element.findall('system/cpu/system')[0].text)

test_check_monit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_main_xml_error(self, mock_get, mock_print):
108108
def test_main_ok(self, mock_get, mock_print):
109109
args = commandline(['-H', 'localhost', '-P', 'password', '-U', 'user'])
110110

111-
d = """<?xml version="1.0" encoding="ISO-8859-1"?><monit><server><id>e4a88a4293441301bf72d6ee07dd4af2</id><incarnation>1692607015</incarnation><version>5.33.0</version><uptime>304</uptime><poll>5</poll><startdelay>0</startdelay><localhostname>scratch</localhostname><controlfile>/root/.monitrc</controlfile><httpd><address>::1</address><port>8080</port><ssl>0</ssl></httpd></server><platform><name>Linux</name><release>5.10</release><version>#1 SMP Debian</version><machine>x86_64</machine><cpu>2</cpu><memory>2030520</memory><swap>0</swap></platform><service type="5"><name>scratch</name><collected_sec>1692607316</collected_sec><collected_usec>642649</collected_usec><status>0</status><status_hint>0</status_hint><monitor>1</monitor><monitormode>0</monitormode><onreboot>0</onreboot><pendingaction>0</pendingaction><filedescriptors><allocated>672</allocated><unused>0</unused><maximum>9223372036854775807</maximum></filedescriptors><system><load><avg01>0.00</avg01><avg05>0.00</avg05><avg15>0.00</avg15></load><cpu><user>0.1</user><system>0.1</system><nice>0.0</nice><wait>0.0</wait><hardirq>0.0</hardirq><softirq>0.4</softirq><steal>0.0</steal><guest>0.0</guest><guestnice>0.0</guestnice></cpu><memory><percent>10.6</percent><kilobyte>214704</kilobyte></memory><swap><percent>0.0</percent><kilobyte>0</kilobyte></swap></system></service></monit>"""
111+
d = """<?xml version="1.0" encoding="ISO-8859-1"?><monit><server><id>e4a88a4293441301bf72d6ee07dd4af2</id><incarnation>1692607015</incarnation><version>5.33.0</version><uptime>304</uptime><poll>5</poll><startdelay>0</startdelay><localhostname>scratch</localhostname><controlfile>/root/.monitrc</controlfile><httpd><address>::1</address><port>8080</port><ssl>0</ssl></httpd></server><platform><name>Linux</name><release>5.10</release><version>#1 SMP Debian</version><machine>x86_64</machine><cpu>2</cpu><memory>2030520</memory><swap>0</swap></platform><service type="5"><name>scratch</name><collected_sec>1692607316</collected_sec><collected_usec>642649</collected_usec><status>0</status><status_hint>0</status_hint><monitor>1</monitor><monitormode>0</monitormode><onreboot>0</onreboot><pendingaction>0</pendingaction><filedescriptors><allocated>672</allocated><unused>0</unused><maximum>9223372036854775807</maximum></filedescriptors><system><load><avg01>1.23</avg01><avg05>4.56</avg05><avg15>7.89</avg15></load><cpu><user>0.1</user><system>0.1</system><nice>0.0</nice><wait>0.0</wait><hardirq>0.0</hardirq><softirq>0.4</softirq><steal>0.0</steal><guest>0.0</guest><guestnice>0.0</guestnice></cpu><memory><percent>10.6</percent><kilobyte>214704</kilobyte></memory><swap><percent>0.0</percent><kilobyte>0</kilobyte></swap></system></service></monit>"""
112112

113113
mock_get.return_value = MockRequest(200, d)
114114

@@ -118,7 +118,7 @@ def test_main_ok(self, mock_get, mock_print):
118118

119119
calls = [mock.call('[OK]: Monit Service Status 1/1'),
120120
mock.call(' \\_ [OK]: scratch'),
121-
mock.call(' load=0.0,0.0,0.0;user=0.1%;system=0.1%;nice=0.0%;hardirq=0.0%;memory=10.6%')]
121+
mock.call(' load1=1.23;load5=4.56;load15=7.89;user=0.1%;system=0.1%;nice=0.0%;hardirq=0.0%;memory=10.6%')]
122122

123123
mock_print.assert_has_calls(calls)
124124

@@ -127,7 +127,7 @@ def test_main_ok(self, mock_get, mock_print):
127127
def test_main_critical(self, mock_get, mock_print):
128128
args = commandline(['-H', 'localhost', '-P', 'password', '-U', 'user'])
129129

130-
d = """<?xml version="1.0" encoding="ISO-8859-1"?><monit><server><id>e4a88a4293441301bf72d6ee07dd4af2</id><incarnation>1692607015</incarnation><version>5.33.0</version><uptime>304</uptime><poll>5</poll><startdelay>0</startdelay><localhostname>scratch</localhostname><controlfile>/root/.monitrc</controlfile><httpd><address>::1</address><port>8080</port><ssl>0</ssl></httpd></server><platform><name>Linux</name><release>5.10</release><version>#1 SMP Debian</version><machine>x86_64</machine><cpu>2</cpu><memory>2030520</memory><swap>0</swap></platform><service type="5"><name>scratch</name><collected_sec>1692607316</collected_sec><collected_usec>642649</collected_usec><status>1</status><status_hint>0</status_hint><monitor>1</monitor><monitormode>0</monitormode><onreboot>0</onreboot><pendingaction>0</pendingaction><filedescriptors><allocated>672</allocated><unused>0</unused><maximum>9223372036854775807</maximum></filedescriptors><system><load><avg01>0.00</avg01><avg05>0.00</avg05><avg15>0.00</avg15></load><cpu><user>0.1</user><system>0.1</system><nice>0.0</nice><wait>0.0</wait><hardirq>0.0</hardirq><softirq>0.4</softirq><steal>0.0</steal><guest>0.0</guest><guestnice>0.0</guestnice></cpu><memory><percent>10.6</percent><kilobyte>214704</kilobyte></memory><swap><percent>0.0</percent><kilobyte>0</kilobyte></swap></system></service></monit>"""
130+
d = """<?xml version="1.0" encoding="ISO-8859-1"?><monit><server><id>e4a88a4293441301bf72d6ee07dd4af2</id><incarnation>1692607015</incarnation><version>5.33.0</version><uptime>304</uptime><poll>5</poll><startdelay>0</startdelay><localhostname>scratch</localhostname><controlfile>/root/.monitrc</controlfile><httpd><address>::1</address><port>8080</port><ssl>0</ssl></httpd></server><platform><name>Linux</name><release>5.10</release><version>#1 SMP Debian</version><machine>x86_64</machine><cpu>2</cpu><memory>2030520</memory><swap>0</swap></platform><service type="5"><name>scratch</name><collected_sec>1692607316</collected_sec><collected_usec>642649</collected_usec><status>1</status><status_hint>0</status_hint><monitor>1</monitor><monitormode>0</monitormode><onreboot>0</onreboot><pendingaction>0</pendingaction><filedescriptors><allocated>672</allocated><unused>0</unused><maximum>9223372036854775807</maximum></filedescriptors><system><load><avg01>1.23</avg01><avg05>4.56</avg05><avg15>7.89</avg15></load><cpu><user>0.1</user><system>0.1</system><nice>0.0</nice><wait>0.0</wait><hardirq>0.0</hardirq><softirq>0.4</softirq><steal>0.0</steal><guest>0.0</guest><guestnice>0.0</guestnice></cpu><memory><percent>10.6</percent><kilobyte>214704</kilobyte></memory><swap><percent>0.0</percent><kilobyte>0</kilobyte></swap></system></service></monit>"""
131131

132132
mock_get.return_value = MockRequest(200, d)
133133

@@ -137,6 +137,6 @@ def test_main_critical(self, mock_get, mock_print):
137137

138138
calls = [mock.call('[CRITICAL]: Monit Service Status 0/1'),
139139
mock.call(' \\_ [CRITICAL]: scratch'),
140-
mock.call(' load=0.0,0.0,0.0;user=0.1%;system=0.1%;nice=0.0%;hardirq=0.0%;memory=10.6%')]
140+
mock.call(' load1=1.23;load5=4.56;load15=7.89;user=0.1%;system=0.1%;nice=0.0%;hardirq=0.0%;memory=10.6%')]
141141

142142
mock_print.assert_has_calls(calls)

0 commit comments

Comments
 (0)