Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add float for intervals + Add NetSpeed Compact and TotalNetSpeed #100

Merged
merged 8 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
===================
Expand Down
6 changes: 6 additions & 0 deletions budgiesysmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
• mem: {mem_desc}
• bat<i>%d</i>: {bat_desc}
• net: {net_desc}
• netcomp: {netcomp_desc}
• totalnet: {totalnet_desc}
• upordown: {upordown_desc}
• publicip: {publicip_desc}

Expand All @@ -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 \
Expand Down
6 changes: 3 additions & 3 deletions preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
Expand Down
60 changes: 52 additions & 8 deletions sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -70,6 +70,8 @@ def __init__(self):
NvGPUSensor(),
MemSensor(),
NetSensor(),
NetCompSensor(),
TotalNetSensor(),
BatSensor(),
FSSensor(),
SwapSensor(),
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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*'
Expand Down