How to use the aj.plugins.dashboard.api.Widget function in aj

To help you get started, we’ve selected a few aj examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ajenti / ajenti / plugins / dashboard / widgets / loadavg.py View on Github external
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()
github ajenti / ajenti / plugins / dashboard / views.py View on Github external
def __init__(self, context):
        self.context = context
        self.widgets = dict((x.id, x) for x in Widget.all(self.context))
github ajenti / ajenti / plugins / terminal / widget.py View on Github external
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
github ajenti / ajenti / plugins / dashboard / widgets / cpu.py View on Github external
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)]
github ajenti / ajenti / plugins / dashboard / widgets / memory.py View on Github external
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
        }
github ajenti / ajenti / plugins / terminal / widget.py View on Github external
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
github ajenti / ajenti / plugins / dashboard / widgets / hostname.py View on Github external
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()