Skip to content

Commit

Permalink
Enable specific network interfaces, fix encoding in processes
Browse files Browse the repository at this point in the history
  • Loading branch information
vfuse committed Jun 6, 2018
1 parent 884d6a6 commit 5a785b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
24 changes: 22 additions & 2 deletions nixstatsagent/plugins/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,28 @@
class Plugin(plugins.BasePlugin):
__name__ = 'network'

def run(self, *unused):
return psutil.net_io_counters(pernic=True)
def run(self, config):
'''
Network monitoring plugin.
To only enable certain interfaces add below [network]:
interfaces = eth1,eth3,...
'''

try:
enabled_interfaces = config.get('network', 'interfaces').split(',')
except:
enabled_interfaces = False

if enabled_interfaces is False:
return psutil.net_io_counters(pernic=True)
else:
returndata = {}
interfaces = psutil.net_io_counters(pernic=True)
for interface in interfaces:
if interface in enabled_interfaces:
returndata[interface] = interfaces[interface]
return returndata
return None


if __name__ == '__main__':
Expand Down
16 changes: 12 additions & 4 deletions nixstatsagent/plugins/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ def run(self, *unused):
'pid', 'name', 'ppid', 'exe', 'cmdline', 'username',
'cpu_percent', 'memory_percent', 'io_counters'
])
pinfo['name'].encode('utf-8')
if sys.platform != 'win32':
pinfo['username'].encode('utf-8')
pinfo['cmdline'] = ' '.join(pinfo['cmdline']).encode('utf-8').strip()

try:
pinfo['cmdline'] = ' '.join(pinfo['cmdline']).strip()
except:
pass
pinfo['cmdline'] = unicode(pinfo['cmdline'], sys.getdefaultencoding(), errors="replace").strip()
pinfo['name'] = unicode(pinfo['name'], sys.getdefaultencoding(), errors="replace")
pinfo['username'] = unicode(pinfo['username'], sys.getdefaultencoding(), errors="replace")
pinfo['exe'] = unicode(pinfo['exe'], sys.getdefaultencoding(), errors="replace")

except psutil.NoSuchProcess:
pass
except psutil.AccessDenied:
pass
except:
pass
else:
process.append(pinfo)
return process
Expand Down
14 changes: 14 additions & 0 deletions nixstatsagent/plugins/temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ def run(self, *unused):
'''
data = {}

if sys.platform == "win32":
try:
import wmi
except:
return 'wmi module not installed.'
try:
w = wmi.WMI(namespace="root\OpenHardwareMonitor")
temperature_infos = w.Sensor()
for sensor in temperature_infos:
if sensor.SensorType==u'Temperature':
data[sensor.Parent.replace('/','-').strip('-')] = sensor.Value
return data
except:
return 'Could not fetch temperature data from OpenHardwareMonitor.'
if not hasattr(psutil, "sensors_temperatures"):
return "platform not supported"

Expand Down

0 comments on commit 5a785b8

Please sign in to comment.