Exemplo n.º 1
0
    def get_first_check_date_test(self):
        self._cleanup()

        collection = system_model.data_collection

        for i in range(11, 100):
            collection.insert({'time': i, 'server_id': self.server['_id']})

        result = system_model.get_first_check_date(server=self.server)

        eq_(result, 11)
Exemplo n.º 2
0
def system_view(request, server_id):
    enddate = request.GET.get('enddate')
    charts = request.GET.get('charts', 'all')

    duration = request.GET.get('duration', 10800)
    duration = int(duration)

    server = server_model.get_by_id(server_id)
    tags = server_model.get_tags(server=server)
    if tags:
        server['tags'] = tags

    first_check_date = system_model.get_first_check_date(server)

    now_unix = datetime_to_unixtime(request.now)
    max_date = now_unix * 1000

    if enddate:
        date_to = int(enddate)
    else:
        date_to = now_unix

    date_from = date_to - int(duration)

    data_url = reverse('ajax_get_data_after')
    data_url = "{0}?server_id={1}".format(data_url, server.get('_id'))

    charts_metadata = {
        'cpu': {
            'id': 'cpu',
            'check': 'cpu',
            'name': 'CPU',
            'url': data_url,
        },
        'loadavg': {
            'id': 'loadavg',
            'check': 'loadavg',
            'name': 'Load Average',
            'url': data_url
        },
        'memory': {
            'id': 'memory',
            'check': 'memory',
            'name': 'Memory',
            'url': data_url,
            'type': 'area'
        },
        'network': [{
            'id': 'network.inbound',
            'check': 'network.inbound',
            'name': 'Network - KB/s Received',
            'url': data_url,
            'unit': 'kb/s'
        }, {
            'id': 'network.outbound',
            'check': 'network.outbound',
            'name': 'Network - KB/s Sent',
            'url': data_url,
            'unit': 'kb/s'
        }]
    }

    if charts == 'all':
        active_checks = ['cpu', 'memory', 'loadavg', 'disk', 'network']
    else:
        active_checks = [charts]

    selected_charts = []
    for check in active_checks:
        if check in ['network']:
            chart_meta = charts_metadata.get(check)
            for i in chart_meta:
                selected_charts.append(i)
        elif check != 'disk':
            chart_meta = charts_metadata.get(check)
            selected_charts.append(chart_meta)

    volumes = volumes_model.get_all_for_server(server_id)
    if 'disk' in active_checks:

        unit = get_disk_unit(server)

        for device in volumes.clone():
            device_id, name = device.get('_id'), device.get('name')
            url = "{0}&device_id={1}".format(data_url, device_id)
            meta = {
                'id': device_id,
                'check': 'disk',
                'name': name,
                'url': url,
                'unit': unit
            }

            last_update = device.get('last_update')
            if last_update > date_from:
                selected_charts.append(meta)

    all_plugins = plugin_model.get_for_server(server_id=server['_id'],
                                              last_check_after=date_from)
    all_processes = process_model.get_all_for_server(
        server_id, last_check_after=date_from)

    breadcrumb_url = reverse('server_system',
                             kwargs={'server_id': server['_id']})
    breadcrumb_url = "{0}?charts={1}".format(breadcrumb_url, charts)

    return render(
        request, 'system/view.html', {
            "enddate": enddate,
            "duration": duration,
            "all_processes": all_processes,
            "all_plugins": all_plugins,
            "now": now_unix,
            "charts": charts,
            "selected_charts": selected_charts,
            "date_from": date_from,
            "date_to": date_to,
            "first_check_date": first_check_date,
            "server": server,
            "max_date": max_date,
            "server_id": server_id,
            "breadcrumb_url": breadcrumb_url
        })
Exemplo n.º 3
0
Arquivo: views.py Projeto: gisce/AMON
def system_view(request, server_id):
    enddate = request.GET.get('enddate')
    charts = request.GET.get('charts', 'all')

    duration = request.GET.get('duration', 10800)
    duration = int(duration)

    server = server_model.get_by_id(server_id)
    tags = server_model.get_tags(server=server)
    if tags:
        server['tags'] = tags

    first_check_date = system_model.get_first_check_date(server)


    now_unix = datetime_to_unixtime(request.now)
    max_date = now_unix * 1000

    if enddate:
        date_to = int(enddate)
    else:
        date_to = now_unix

    date_from = date_to - int(duration)

    data_url = reverse('ajax_get_data_after')
    data_url = "{0}?server_id={1}".format(data_url, server.get('_id'))

    charts_metadata = {
        'cpu': {'id': 'cpu', 'check': 'cpu', 'name': 'CPU', 'url': data_url, },
        'loadavg': {'id': 'loadavg', 'check': 'loadavg', 'name': 'Load Average','url': data_url},
        'memory': {'id': 'memory', 'check': 'memory', 'name': 'Memory', 'url': data_url, 'type': 'area'},
        'network': [
            {'id': 'network.inbound', 'check': 'network.inbound', 'name': 'Network - KB/s Received', 'url': data_url, 'unit': 'kb/s'},
            {'id': 'network.outbound', 'check': 'network.outbound', 'name': 'Network - KB/s Sent', 'url': data_url, 'unit': 'kb/s'}
        ]
    }

    if charts == 'all':
        active_checks = ['cpu', 'memory', 'loadavg', 'disk', 'network']
    else:
        active_checks = [charts]

    selected_charts = []
    for check in active_checks:
        if check in ['network']:
            chart_meta = charts_metadata.get(check)
            for i in chart_meta:
                selected_charts.append(i)
        elif check != 'disk':
            chart_meta = charts_metadata.get(check)
            selected_charts.append(chart_meta)


    volumes = volumes_model.get_all_for_server(server_id)
    if 'disk' in active_checks:

        unit = get_disk_unit(server)

        for device in volumes.clone():
            device_id, name = device.get('_id'), device.get('name')
            url = "{0}&device_id={1}".format(data_url, device_id)
            meta = {'id': device_id, 'check': 'disk', 'name': name, 'url': url , 'unit': unit}

            last_update = device.get('last_update')
            if last_update > date_from:
                selected_charts.append(meta)


    all_plugins = plugin_model.get_for_server(server_id=server['_id'], last_check_after=date_from)
    all_processes = process_model.get_all_for_server(server_id, last_check_after=date_from)

    breadcrumb_url = reverse('server_system', kwargs={'server_id': server['_id']})
    breadcrumb_url = "{0}?charts={1}".format(breadcrumb_url, charts)

    return render(request, 'system/view.html', {
        "enddate": enddate,
        "duration": duration,
        "all_processes": all_processes,
        "all_plugins": all_plugins,
        "now": now_unix,
        "charts":charts,
        "selected_charts" : selected_charts,
        "date_from" : date_from,
        "date_to" : date_to,
        "first_check_date" : first_check_date,
        "server" : server,
        "max_date" : max_date,
        "server_id": server_id,
        "breadcrumb_url": breadcrumb_url
    })