From 4a446056247e26e61a2469d2fea6e71d32c2e829 Mon Sep 17 00:00:00 2001 From: TangMing Date: Sun, 19 Apr 2020 13:58:27 +0800 Subject: [PATCH 1/2] fix node can't get monitor data --- jenkinsapi/node.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/jenkinsapi/node.py b/jenkinsapi/node.py index 95d54d21..82696fb2 100644 --- a/jenkinsapi/node.py +++ b/jenkinsapi/node.py @@ -407,61 +407,67 @@ def get_monitor(self, monitor_name, poll_monitor=True): return monitor_data[full_monitor_name] + def get_monitor_data(self, monitor_name, item): + """ + Polls the node returning one of the monitors in the monitorData branch of the + returned node api tree. + """ + monitor_data_key = 'monitorData' + monitor_data = self.poll()[monitor_data_key] + + full_monitor_name = 'hudson.node_monitors.{0}'.format(monitor_name) + if full_monitor_name not in monitor_data: + raise AssertionError('Node monitor %s not found' % monitor_name) + + return monitor_data[full_monitor_name][item] + def get_available_physical_memory(self): """ Returns the node's available physical memory in bytes. """ - monitor_data = self.get_monitor('SwapSpaceMonitor') - return monitor_data['availablePhysicalMemory'] + return self.get_monitor_data('SwapSpaceMonitor', 'availablePhysicalMemory') def get_available_swap_space(self): """ Returns the node's available swap space in bytes. """ - monitor_data = self.get_monitor('SwapSpaceMonitor') - return monitor_data['availableSwapSpace'] + return self.get_monitor_data('SwapSpaceMonitor', 'availableSwapSpace') def get_total_physical_memory(self): """ Returns the node's total physical memory in bytes. """ - monitor_data = self.get_monitor('SwapSpaceMonitor') - return monitor_data['totalPhysicalMemory'] + return self.get_monitor_data('SwapSpaceMonitor', 'totalPhysicalMemory') def get_total_swap_space(self): """ Returns the node's total swap space in bytes. """ - monitor_data = self.get_monitor('SwapSpaceMonitor') - return monitor_data['totalSwapSpace'] + return self.get_monitor_data('SwapSpaceMonitor', 'totalSwapSpace') def get_workspace_path(self): """ Returns the local path to the node's Jenkins workspace directory. """ - monitor_data = self.get_monitor('DiskSpaceMonitor') - return monitor_data['path'] + return self.get_monitor_data('DiskSpaceMonitor', 'path') def get_workspace_size(self): """ Returns the size in bytes of the node's Jenkins workspace directory. """ - monitor_data = self.get_monitor('DiskSpaceMonitor') - return monitor_data['size'] + return self.get_monitor_data('DiskSpaceMonitor', 'size') def get_temp_path(self): """ Returns the local path to the node's temp directory. """ - monitor_data = self.get_monitor('TemporarySpaceMonitor') - return monitor_data['path'] + return self.get_monitor_data('TemporarySpaceMonitor', 'path') def get_temp_size(self): """ Returns the size in bytes of the node's temp directory. """ - monitor_data = self.get_monitor('TemporarySpaceMonitor') - return monitor_data['size'] + return self.get_monitor_data('TemporarySpaceMonitor', 'size') def get_architecture(self): """ @@ -495,13 +501,11 @@ def get_response_time(self): """ Returns the node's average response time. """ - monitor_data = self.get_monitor('ResponseTimeMonitor') - return monitor_data['average'] + return self.get_monitor_data('ResponseTimeMonitor', 'average') def get_clock_difference(self): """ Returns the difference between the node's clock and the master Jenkins clock. Used to detect out of sync clocks. """ - monitor_data = self.get_monitor('ClockMonitor') - return monitor_data['diff'] + return self.get_monitor_data('ClockMonitor', 'diff') From 6944620879753c2b609be394586ec1261eee7d1a Mon Sep 17 00:00:00 2001 From: TangMing Date: Sun, 19 Apr 2020 14:06:00 +0800 Subject: [PATCH 2/2] update function describe --- jenkinsapi/node.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jenkinsapi/node.py b/jenkinsapi/node.py index 82696fb2..8aaeca06 100644 --- a/jenkinsapi/node.py +++ b/jenkinsapi/node.py @@ -409,8 +409,7 @@ def get_monitor(self, monitor_name, poll_monitor=True): def get_monitor_data(self, monitor_name, item): """ - Polls the node returning one of the monitors in the monitorData branch of the - returned node api tree. + Polls the tree returning full data to get monitor item data. """ monitor_data_key = 'monitorData' monitor_data = self.poll()[monitor_data_key]