diff --git a/README.md b/README.md index 010c80f..f99c9ad 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ ![indicator-sysmonitor](https://user-images.githubusercontent.com/9158844/37069705-90f272a2-21c5-11e8-806f-92b20cbf47ae.png) +![image](https://user-images.githubusercontent.com/41370460/98230824-9cfcfd80-1f81-11eb-9a68-2ac6e1c8adb9.png) + \* _Use following string to use custom preview that is shown above. (Proprietary Nvidia driver needed, must be running)_: - CPU {cpu} {cputemp} | GPU {nvgpu} {nvgputemp} | MEM {mem} | SWAP {swap} + CPU {cpu} {cputemp} | GPU {nvgpu} {nvgputemp} | MEM {mem} | SWAP {swap} | Net Speed Compact {netcomp} | Total Net Speed {totalnet} Indicator-SysMonitor - v0.8.3 =================== diff --git a/budgiesysmonitor.py b/budgiesysmonitor.py index a0b7ea9..76c8a35 100644 --- a/budgiesysmonitor.py +++ b/budgiesysmonitor.py @@ -38,6 +38,8 @@ • mem: {mem_desc} • bat%d: {bat_desc} • net: {net_desc} +• netcomp: {netcomp_desc} +• totalnet: {totalnet_desc} • upordown: {upordown_desc} • publicip: {publicip_desc} @@ -56,6 +58,10 @@ bat_desc=_("It shows the available battery which id is %d."), net_desc=_("It shows the amount of data you are downloading and uploading \ through your network."), + netcomp_desc=_("It shows the amount of data you are downloading and uploading \ + through your network in a compact way."), + totalnet_desc=("It shows the total amount of data you downloaded and uploaded \ + through your network."), upordown_desc=_("It shows whether your internet connection is up or down \ - the sensor is refreshed every 10 seconds."), publicip_desc=_("It shows your public IP address \ diff --git a/preferences.py b/preferences.py index ed6d0c1..5d58a30 100644 --- a/preferences.py +++ b/preferences.py @@ -365,9 +365,9 @@ def update_parent(self, evnt=None, data=None): self.sensor_mgr.check(sensor) try: - interval = int(self.interval_entry.get_text()) - if interval <= 0: - raise ISMError(_("Interval value is not valid.")) + interval = float(self.interval_entry.get_text()) + if interval <1: + raise ISMError(_("Interval value should be greater then or equal to 1 ")) except ValueError: raise ISMError(_("Interval value is not valid.")) diff --git a/sensors.py b/sensors.py index c9187c7..af83435 100755 --- a/sensors.py +++ b/sensors.py @@ -27,16 +27,16 @@ ps_v1_api = int(ps.__version__.split('.')[0]) <= 1 -B_UNITS = ['', 'KB', 'MB', 'GB', 'TB'] +B_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'] cpu_load = [] -def bytes_to_human(num, suffix='B'): - for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: - if abs(num) < 1024.0: - return "%3.2f %s%s" % (num, unit, suffix) - num /= 1024.0 - return "%.2f %s%s" % (num, 'Yi', suffix) +def bytes_to_human(num): + for unit in B_UNITS: + if abs(num) < 1000.0: + return "%3.2f %s" % (num, unit) + num /= 1000.0 + return "%.2f %s" % (num, 'YB') class ISMError(Exception): """General exception.""" @@ -70,6 +70,8 @@ def __init__(self): NvGPUSensor(), MemSensor(), NetSensor(), + NetCompSensor(), + TotalNetSensor(), BatSensor(), FSSensor(), SwapSensor(), @@ -404,7 +406,7 @@ def _fetch_cpu(self, percpu=False): if percpu: return cpu_load - r = 0.0; + r = 0.0 for i in cpu_load: r += i @@ -472,6 +474,48 @@ def _fetch_net(self): current[1] /= mgr.get_interval() return '↓ {:>9s}/s ↑ {:>9s}/s'.format(bytes_to_human(current[0]), bytes_to_human(current[1])) +class NetCompSensor(BaseSensor): + name = 'netcomp' + desc = _('Network activity in Compact form.') + _last_net_usage = [0, 0] # (up, down) + + def get_value(self, sensor_data): + return self._fetch_net() + + def _fetch_net(self): + """It returns the bytes sent and received in bytes/second""" + current = [0, 0] + for _, iostat in list(ps.net_io_counters(pernic=True).items()): + current[0] += iostat.bytes_recv + current[1] += iostat.bytes_sent + dummy = copy.deepcopy(current) + + current[0] -= self._last_net_usage[0] + current[1] -= self._last_net_usage[1] + self._last_net_usage = dummy + mgr = SensorManager() + current[0] /= mgr.get_interval() + current[1] /= mgr.get_interval() + return '⇵ {:>9s}/s'.format(bytes_to_human(current[0] + current[1])) + +class TotalNetSensor(BaseSensor): + name = 'totalnet' + desc = _('Total Network activity.') + + def get_value(self, sensor_data): + return self._fetch_net() + + def _fetch_net(self): + """It returns total number the bytes sent and received""" + current = [0, 0] + for _, iostat in list(ps.net_io_counters(pernic=True).items()): + current[0] += iostat.bytes_recv + current[1] += iostat.bytes_sent + + mgr = SensorManager() + current[0] /= mgr.get_interval() + current[1] /= mgr.get_interval() + return ' Σ {:>9s}'.format(bytes_to_human(current[0] + current[1])) class BatSensor(BaseSensor): name = 'bat\d*'