Exemplo n.º 1
0
    def check(self, data=None, plugin=None, server=None):
        plugin_data = data.get('gauges', None)

        rules = alerts_model.get_alerts_for_plugin(plugin=plugin)

        if len(rules) > 0:
            for rule in rules:
                alert = plugin_alerts.check(data=plugin_data, rule=rule)

                if alert:
                    alerts_model.save_occurence(alert)

        # Global alerts
        rules = alerts_model.get_alerts(type='plugin_global')
        if len(rules) > 0:
            all_plugins = plugin_model.get_for_server(server_id=server['_id'])
            for rule in rules:
                valid_rule = self.check_tags(server=server, rule=rule)

                if valid_rule:
                    plugin_name = rule.get('plugin')
                    plugin_id = None

                    # Check if this server has a plugin with this name
                    for p in all_plugins.clone():
                        if p.get('name') == plugin_name:
                            plugin_id = p.get('_id')

                    if plugin_id:
                        alert = plugin_alerts.check(data=plugin_data,
                                                    rule=rule)

                        if alert:
                            alerts_model.save_occurence(
                                alert, server_id=server['_id'])
Exemplo n.º 2
0
    def check(self, data=None, plugin=None, server=None):
        plugin_data = data.get('gauges', None)

        rules = alerts_model.get_alerts_for_plugin(plugin=plugin)

        if len(rules) > 0:
            for rule in rules:
                alert = plugin_alerts.check(data=plugin_data, rule=rule)

                if alert:
                    alerts_model.save_occurence(alert)


        # Global alerts
        rules = alerts_model.get_alerts(type='plugin_global')
        if len(rules) > 0:
            all_plugins = plugin_model.get_for_server(server_id=server['_id'])
            for rule in rules:
                valid_rule = self.check_tags(server=server, rule=rule)

                if valid_rule:
                    plugin_name = rule.get('plugin')
                    plugin_id = None

                    # Check if this server has a plugin with this name
                    for p in all_plugins.clone():
                        if p.get('name') == plugin_name:
                            plugin_id = p.get('_id')

                    if plugin_id:
                        alert = plugin_alerts.check(data=plugin_data, rule=rule)

                        if alert:
                            alerts_model.save_occurence(alert, server_id=server['_id'])
Exemplo n.º 3
0
    def get_plugins_for_server_test(self):
        self._cleanup()


        for i in range(0, 5):
            plugin_model.collection.insert({'name': 'test{0}'.format(i), 'server_id': self.server['_id'] })

        result = plugin_model.get_for_server(server_id=self.server['_id'])

        eq_(result.clone().count(), 5)

        for r in result.clone():
            valid_names = ['test0', 'test1', 'test2', 'test3', 'test4']
            assert r['name'] in valid_names
Exemplo n.º 4
0
    def get_plugins_for_server_test(self):
        self._cleanup()

        for i in range(0, 5):
            plugin_model.collection.insert({
                'name': 'test{0}'.format(i),
                'server_id': self.server['_id']
            })

        result = plugin_model.get_for_server(server_id=self.server['_id'])

        eq_(result.clone().count(), 5)

        for r in result.clone():
            valid_names = ['test0', 'test1', 'test2', 'test3', 'test4']
            assert r['name'] in valid_names
Exemplo n.º 5
0
    def get_server_metrics(self, account_id=None, server_id=None):
        data = []
        constants = ['cpu', 'memory', 'loadavg', 'network']
        process_charts = ['cpu', 'memory']

        processes = process_model.get_all_for_server(server_id)
        plugins = plugin_model.get_for_server(server_id=server_id)
        volumes = volumes_model.get_all_for_server(server_id=server_id)
        interfaces = interfaces_model.get_all_for_server(server_id=server_id)

        for v in volumes:
            name = "Disk.{0}".format(v['name'])
            _id = "server_id:{0}.check:disk.device_id:{1}".format(
                server_id, v['_id'])
            data.append([_id, name, 'System metrics'])

        for v in interfaces:
            name = "Adapter.{0}".format(v['name'])
            _id = "server_id:{0}.check:network.device_id:{1}".format(
                server_id, v['_id'])
            data.append([_id, name, 'System metrics'])

        for check in constants:
            name = "{0}".format(check.title())
            _id = "server_id:{0}.check:{1}".format(server_id, check)
            data.append([_id, name, 'System metrics'])

        for p in processes:
            for check in process_charts:
                name = "{0}.{1}".format(p['name'], check)
                _id = "server_id:{0}.process_id:{1}.check:{2}".format(
                    server_id, p['_id'], check)
                data.append([_id, name, 'Process Metrics'])

        for p in plugins:
            gauges = plugin_model.get_gauges_cursor(plugin=p)
            for g in gauges:
                name = "{0}.{1}".format(p.get('name'), g.get('name'))
                _id = "server_id:{0}.plugin_id:{1}.gauge_id:{2}.check:plugin".format(
                    server_id, p['_id'], g['_id'])
                data.append([_id, name, 'Plugin Metrics'])

        data = sorted(data, key=itemgetter(1))

        return data
Exemplo n.º 6
0
Arquivo: models.py Projeto: gisce/AMON
    def get_server_metrics(self, account_id=None, server_id=None):
        data = []
        constants = ['cpu', 'memory', 'loadavg', 'network']
        process_charts = ['cpu', 'memory']

        processes = process_model.get_all_for_server(server_id)
        plugins = plugin_model.get_for_server(server_id=server_id)
        volumes = volumes_model.get_all_for_server(server_id=server_id)
        interfaces = interfaces_model.get_all_for_server(server_id=server_id)

        for v in volumes:
            name = "Disk.{0}".format(v['name'])
            _id = "server_id:{0}.check:disk.device_id:{1}".format(server_id, v['_id'])
            data.append([_id, name, 'System metrics'])

        for v in interfaces:
            name = "Adapter.{0}".format(v['name'])
            _id = "server_id:{0}.check:network.device_id:{1}".format(server_id, v['_id'])
            data.append([_id, name, 'System metrics'])

        for check in constants:
            name = "{0}".format(check.title())
            _id = "server_id:{0}.check:{1}".format(server_id, check)
            data.append([_id, name, 'System metrics'])

        for p in processes:
            for check in process_charts:
                name = "{0}.{1}".format(p['name'], check)
                _id = "server_id:{0}.process_id:{1}.check:{2}".format(server_id, p['_id'], check)
                data.append([_id, name, 'Process Metrics'])

        for p in plugins:
            gauges = plugin_model.get_gauges_cursor(plugin=p)
            for g in gauges:
                name = "{0}.{1}".format(p.get('name'), g.get('name'))
                _id = "server_id:{0}.plugin_id:{1}.gauge_id:{2}.check:plugin".format(server_id, p['_id'], g['_id'])
                data.append([_id, name, 'Plugin Metrics'])

        data = sorted(data, key=itemgetter(1))

        return data
Exemplo n.º 7
0
def edit_server(request, server_id=None):

    server = server_model.get_by_id(server_id)
    plugins = plugin_model.get_for_server(server_id)
    form = ServerForm(server=server)

    if request.method == 'POST':
        form = ServerForm(request.POST, server=server)

        if form.is_valid():
            form.save()

            messages.add_message(request, messages.INFO, 'Server settings updated.')

            return redirect(reverse('servers'))

    return render_to_response('servers/edit.html', {
        "server": server,
        "plugins": plugins,
        'form': form,
    }, context_instance=RequestContext(request))
Exemplo n.º 8
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.º 9
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
    })