Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import multiprocessing
import os
import subprocess
from jadi import component
from aj.plugins.dashboard.api import Widget
@component(Widget)
class LoadAverageWidget(Widget):
id = 'loadavg'
name = _('Load average')
template = '/dashboard:resources/partial/widgets/loadavg.html'
def __init__(self, context):
Widget.__init__(self, context)
def get_value(self, config):
k = 1.0
if config and config.get('divide', False):
k /= multiprocessing.cpu_count()
if os.path.exists('/proc/loadavg'):
return [float(open('/proc/loadavg').read().split()[x]) * k for x in range(3)]
else:
tokens = subprocess.check_output(['uptime']).split()
def __init__(self, context):
self.context = context
self.widgets = dict((x.id, x) for x in Widget.all(self.context))
from jadi import component
from aj.plugins.dashboard.api import Widget
@component(Widget)
class ScriptWidget(Widget):
id = 'script'
name = _('Script')
template = '/terminal:resources/partial/widget.html'
config_template = '/terminal:resources/partial/widget.config.html'
def __init__(self, context):
Widget.__init__(self, context)
def get_value(self, config):
pass
import psutil
from jadi import component
from aj.plugins.dashboard.api import Widget
@component(Widget)
class CPUWidget(Widget):
id = 'cpu'
name = _('CPU usage')
template = '/dashboard:resources/partial/widgets/cpu.html'
def __init__(self, context):
Widget.__init__(self, context)
def get_value(self, config):
return [x / 100.0 for x in psutil.cpu_percent(interval=0, percpu=True)]
import psutil
from jadi import component
from aj.plugins.dashboard.api import Widget
@component(Widget)
class MemoryWidget(Widget):
id = 'memory'
name = 'Memory usage'
template = '/dashboard:resources/partial/widgets/memory.html'
def __init__(self, context):
Widget.__init__(self, context)
def get_value(self, config):
v = psutil.virtual_memory()
return {
'used': v.total - v.available,
'free': v.available,
'total': v.total
}
from jadi import component
from aj.plugins.dashboard.api import Widget
@component(Widget)
class ScriptWidget(Widget):
id = 'script'
name = _('Script')
template = '/terminal:resources/partial/widget.html'
config_template = '/terminal:resources/partial/widget.config.html'
def __init__(self, context):
Widget.__init__(self, context)
def get_value(self, config):
pass
import platform
from jadi import component
from aj.plugins.dashboard.api import Widget
@component(Widget)
class HostnameWidget(Widget):
id = 'hostname'
name = 'Hostname'
template = '/dashboard:resources/partial/widgets/hostname.html'
def __init__(self, context):
Widget.__init__(self, context)
def get_value(self, config):
return platform.node()