示例#1
0
文件: views.py 项目: HomemBravo/amon
def get_global_process_data_after(key=None, timestamp=None, check=None, enddate=None, timezone='UTC', filtered_servers=None):
    now = datetime.utcnow()
    data = []

    active_checks = ['memory', 'cpu', 'io']
    if check in active_checks and timestamp:
        data = process_model.get_global_data_after(timestamp=timestamp,
            enddate=enddate,
            key=key,
            timezone=timezone,
            check=check,
            filtered_servers=filtered_servers
    )

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local
    }

    return response
示例#2
0
文件: views.py 项目: urandu/amon
def get_global_process_data_after(key=None,
                                  timestamp=None,
                                  check=None,
                                  enddate=None,
                                  timezone='UTC',
                                  filtered_servers=None):
    now = datetime.utcnow()
    data = []

    active_checks = ['memory', 'cpu', 'io']
    if check in active_checks and timestamp:
        data = process_model.get_global_data_after(
            timestamp=timestamp,
            enddate=enddate,
            key=key,
            timezone=timezone,
            check=check,
            filtered_servers=filtered_servers)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now),
                                           tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local
    }

    return response
示例#3
0
文件: views.py 项目: urandu/amon
def get_process_data_after(process_id=None,
                           server_id=None,
                           timestamp=None,
                           check=None,
                           enddate=None,
                           timezone='UTC'):
    now = datetime.utcnow()
    server = server_model.get_by_id(server_id)
    process = process_model.get_by_id(process_id)

    data = []

    active_checks = ['memory', 'cpu', 'io']
    if check in active_checks and timestamp:
        data = process_model.get_data_after(timestamp=timestamp,
                                            enddate=enddate,
                                            server=server,
                                            timezone=timezone,
                                            process=process,
                                            check=check)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now),
                                           tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local
    }

    return response
示例#4
0
def get_plugin_data_after(plugin_id=None,
                          timestamp=None,
                          gauge_id=None,
                          enddate=None,
                          timezone='UTC'):
    now = datetime.utcnow()

    gauge = plugin_model.get_gauge_by_id(gauge_id=gauge_id)

    data = plugin_model.get_gauge_data_after(enddate=enddate,
                                             timestamp=timestamp,
                                             gauge=gauge,
                                             timezone=timezone)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now),
                                           tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local
    }

    return response
示例#5
0
def get_global_plugin_data_after(metric=None,
                                 timestamp=None,
                                 check=None,
                                 enddate=None,
                                 timezone='UTC',
                                 filtered_servers=None):
    now = datetime.utcnow()

    data = plugin_model.get_global_data_after(
        timestamp=timestamp,
        metric=metric,
        timezone=timezone,
        filtered_servers=filtered_servers)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now),
                                           tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local
    }

    return response
示例#6
0
文件: views.py 项目: zeus911/amon
def get_system_data_after(server_id=None,
                          timestamp=None,
                          check=None,
                          enddate=None,
                          timezone='UTC',
                          device_id=None):

    server = server_model.get_by_id(server_id)
    data = []
    now = datetime.utcnow()

    active_checks = [
        'memory', 'loadavg', 'cpu', 'disk', 'network.inbound',
        'network.outbound'
    ]
    if check in active_checks and timestamp:

        if check in ['network.inbound', 'network.outbound']:
            key = 'i' if check == 'network.inbound' else 'o'

            filtered_servers = [server]
            data = system_model.get_global_device_data_after(
                timestamp=timestamp,
                enddate=enddate,
                filtered_servers=filtered_servers,
                key=key,
                timezone=timezone,
                check='network')

        elif check == 'disk':
            data = system_model.get_device_data_after(timestamp=timestamp,
                                                      enddate=enddate,
                                                      server=server,
                                                      timezone=timezone,
                                                      check=check,
                                                      device_id=device_id)
        else:
            data = system_model.get_data_after(timestamp=timestamp,
                                               enddate=enddate,
                                               server=server,
                                               check=check,
                                               timezone=timezone)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now),
                                           tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local,
        'chart_type': 'line'
    }

    return response
示例#7
0
文件: app.py 项目: manasg/amon
    def get(self):

        processes = self.get_arguments('processes', None)
        date_from = self.get_argument('date_from', False)
        date_to = self.get_argument('date_to', False)

        if date_from:
            date_from = datestring_to_utc_datetime(date_from)
        # Default - 24 hours period
        else:
            day = timedelta(hours=24)
            date_from = self.now - day

        if date_to:
            date_to = datestring_to_utc_datetime(date_to)
        else:
            date_to = self.now

        date_from = datetime_to_unixtime(date_from)
        date_to = datetime_to_unixtime(date_to)


        all_processes_checks = settings.PROCESS_CHECKS

        if len(processes) > 0:
            processes_checks = processes
        else:
            processes_checks = settings.PROCESS_CHECKS

        process_data = process_model.get_process_data(processes_checks, date_from, date_to)

        # Convert the dates to local time for display
        date_from = utc_unixtime_to_localtime(date_from)
        date_to = utc_unixtime_to_localtime(date_to)

        # Get the difference between UTC and localtime - used to display 
        # the ticks in the charts
        zone_difference = localtime_utc_timedelta()

        # Get the max date - utc, converted to localtime
        max_date = utc_now_to_localtime()

        self.render('processes.html',
                current_page=self.current_page,
                all_processes_checks=all_processes_checks,
                processes_checks=processes_checks,
                processes=processes,
                process_data=process_data,
                date_from=date_from,
                date_to=date_to,
                zone_difference=zone_difference,
                max_date=max_date
                )
示例#8
0
文件: app.py 项目: marshall007/amon
    def get(self):

        processes = self.get_arguments('processes', None)
        date_from = self.get_argument('date_from', False)
        date_to = self.get_argument('date_to', False)

        if date_from:
            date_from = datestring_to_utc_datetime(date_from)
        # Default - 24 hours period
        else:
            day = timedelta(hours=24)
            date_from = self.now - day

        if date_to:
            date_to = datestring_to_utc_datetime(date_to)
        else:
            date_to = self.now

        date_from = datetime_to_unixtime(date_from)
        date_to = datetime_to_unixtime(date_to)

        all_processes_checks = settings.PROCESS_CHECKS

        if len(processes) > 0:
            processes_checks = processes
        else:
            processes_checks = settings.PROCESS_CHECKS

        process_data = process_model.get_process_data(processes_checks,
                                                      date_from, date_to)

        # Convert the dates to local time for display
        date_from = utc_unixtime_to_localtime(date_from)
        date_to = utc_unixtime_to_localtime(date_to)

        # Get the difference between UTC and localtime - used to display
        # the ticks in the charts
        zone_difference = localtime_utc_timedelta()

        # Get the max date - utc, converted to localtime
        max_date = utc_now_to_localtime()

        self.render('processes.html',
                    current_page=self.current_page,
                    all_processes_checks=all_processes_checks,
                    processes_checks=processes_checks,
                    processes=processes,
                    process_data=process_data,
                    date_from=date_from,
                    date_to=date_to,
                    zone_difference=zone_difference,
                    max_date=max_date)
示例#9
0
文件: app.py 项目: manasg/amon
    def post(self):

        date = self.get_argument('exceptions-date')
        date_utc = datestring_to_utc_datetime(date)
        date_unix = datetime_to_unixtime(date_utc)

        exception_model.delete_before_date(date_unix)

        self.redirect('/settings')
示例#10
0
文件: views.py 项目: zeus911/amon
def get_global_system_data_after(timestamp=None,
                                 check=None,
                                 key=None,
                                 enddate=None,
                                 timezone='UTC',
                                 filtered_servers=None):
    data = []
    now = datetime.utcnow()

    active_checks = ['memory', 'loadavg', 'cpu', 'disk', 'network']
    if check in active_checks and timestamp:

        if check in ['disk', 'network']:
            data = system_model.get_global_device_data_after(
                timestamp=timestamp,
                enddate=enddate,
                timezone=timezone,
                check=check,
                key=key,
                filtered_servers=filtered_servers)
        else:
            data = system_model.get_global_data_after(
                timestamp=timestamp,
                enddate=enddate,
                check=check,
                key=key,
                timezone=timezone,
                filtered_servers=filtered_servers)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now),
                                           tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local,
        'chart_type': 'line',
    }

    return response
示例#11
0
文件: views.py 项目: zeus911/amon
def ajax_localtime_to_unix(request):
    

    date_to_local = request.GET.get('date_to_local', None)

    utc_datetime = datestring_to_utc_datetime(date_to_local, tz=request.timezone)
    unixtime = datetime_to_unixtime(utc_datetime)
    

    return Response({'unixtime': unixtime})
示例#12
0
文件: views.py 项目: gisce/AMON
def get_system_data_after(server_id=None, timestamp=None, check=None, enddate=None, timezone='UTC', device_id=None):

    server = server_model.get_by_id(server_id)
    data = []
    now = datetime.utcnow()

    active_checks = ['memory', 'loadavg', 'cpu', 'disk', 'network.inbound', 'network.outbound']
    if check in active_checks and timestamp:

        if check in ['network.inbound', 'network.outbound']:
            key = 'i' if check == 'network.inbound' else 'o'

            filtered_servers = [server]
            data = system_model.get_global_device_data_after(timestamp=timestamp,
                enddate=enddate,
                filtered_servers=filtered_servers,
                key=key,
                timezone=timezone,
                check='network'
            )


        elif check == 'disk':
            data = system_model.get_device_data_after(timestamp=timestamp, enddate=enddate, server=server, timezone=timezone,
            check=check, device_id=device_id)
        else:
            data = system_model.get_data_after(timestamp=timestamp, enddate=enddate, server=server, check=check, timezone=timezone)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone)
    except:
        now_local = False


    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local,
        'chart_type': 'line'
    }

    return response
示例#13
0
文件: mute.py 项目: zeus911/amon
    def save(self, data=None):
        period = int(data.get('period'))

        if period > 0:
            expire_at = datetime.utcnow() + timedelta(hours=period)

            data['expires_at_utc'] = datetime_to_unixtime(expire_at)
            data['expires_at'] = expire_at

        self.collection.insert(data)
        self.collection.ensure_index([('expires_at', 1)], expireAfterSeconds=0)
示例#14
0
文件: mute.py 项目: HomemBravo/amon
    def save(self, data=None):
        period = int(data.get('period'))

        if period > 0:
            expire_at = datetime.utcnow() + timedelta(hours=period)

            data['expires_at_utc'] = datetime_to_unixtime(expire_at)
            data['expires_at'] = expire_at 

        self.collection.insert(data)
        self.collection.ensure_index([('expires_at', 1)], expireAfterSeconds=0)
示例#15
0
文件: views.py 项目: gisce/AMON
def get_global_system_data_after(timestamp=None, check=None, key=None, enddate=None, timezone='UTC', filtered_servers=None):
    data = []
    now = datetime.utcnow()

    active_checks = ['memory', 'loadavg', 'cpu', 'disk', 'network']
    if check in active_checks and timestamp:

        if check in ['disk', 'network']:
            data = system_model.get_global_device_data_after(timestamp=timestamp,
                enddate=enddate,
                timezone=timezone,
                check=check,
                key=key,
                filtered_servers=filtered_servers
            )
        else:
            data = system_model.get_global_data_after(timestamp=timestamp,
                    enddate=enddate,
                    check=check,
                    key=key,
                    timezone=timezone,
                    filtered_servers=filtered_servers
                )

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local,
        'chart_type': 'line',
    }

    return response
示例#16
0
文件: views.py 项目: HomemBravo/amon
def get_process_data_after(process_id=None, server_id=None, timestamp=None, check=None, enddate=None, timezone='UTC'):
    now = datetime.utcnow()
    server = server_model.get_by_id(server_id)
    process = process_model.get_by_id(process_id)

    data = []

    active_checks = ['memory', 'cpu', 'io']
    if check in active_checks and timestamp:
        data = process_model.get_data_after(timestamp=timestamp, enddate=enddate,
            server=server, timezone=timezone, process=process,check=check)

    try:
        now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone)
    except:
        now_local = False

    response = {
        'data': data,
        'last_update': datetime_to_unixtime(now),
        'now_local': now_local
    }

    return response
示例#17
0
文件: views.py 项目: perplext/amon
def view_dashboard(request, dashboard_id):
    enddate = request.GET.get('enddate')
    duration = request.GET.get('duration', 1800)
    duration = int(duration)

    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)

    all_dashboards = dashboard_model.get_all(account_id=request.account_id)
    all_existing_server_ids = server_model.get_all_ids()
    dashboard = dashboard_model.get_by_id(dashboard_id)
    all_metrics = dashboard_metrics_model.get_all(
        account_id=request.account_id, dashboard_id=dashboard_id)

    metrics_array = _fill_metrics_arrays(all_metrics=all_metrics)

    if len(all_metrics) == 0:
        messages.add_message(request, messages.INFO,
                             'To view this dashboard add at least 1 metric')
        return redirect(
            reverse('edit_dashboard', kwargs={'dashboard_id': dashboard_id}))

    return render_to_response(
        'dashboards/view.html', {
            "all_dashboards": all_dashboards,
            "duration": duration,
            "selected_charts": metrics_array['charts'],
            "health_checks": metrics_array['health_checks'],
            "date_from": date_from,
            "date_to": date_to,
            "now": now_unix,
            "max_date": max_date,
            "dashboard": dashboard,
            "enddate": enddate,
            "all_existing_server_ids": all_existing_server_ids
        },
        context_instance=RequestContext(request))
示例#18
0
文件: views.py 项目: zeus911/amon
def public_dashboard(request, account_id, dashboard_id):
    enddate = request.GET.get('enddate')
    duration = request.GET.get('duration', 1800)
    duration = int(duration)

    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)

    dashboard = dashboard_model.get_by_id(dashboard_id)

    public = dashboard.get('shared', False)
    if public == False:
        raise Http404


    all_metrics = dashboard_metrics_model.get_all(
        dashboard_id=dashboard_id,
        public=public)

    all_existing_server_ids = server_model.get_all_ids()

    metrics_array = _fill_metrics_arrays(all_metrics=all_metrics)
    
    return render(request, 'dashboards/public.html', {
        "account_id": account_id,
        "duration": duration,
        "health_checks": metrics_array['health_checks'],
        "selected_charts": metrics_array['charts'],
        "date_from" : date_from,
        "date_to" : date_to,
        "now": now_unix,
        "max_date": max_date,
        "dashboard": dashboard,
        "enddate": enddate,
        "all_existing_server_ids": all_existing_server_ids
    })
示例#19
0
文件: views.py 项目: HomemBravo/amon
def public_dashboard(request, account_id, dashboard_id):
    enddate = request.GET.get('enddate')
    duration = request.GET.get('duration', 1800)
    duration = int(duration)

    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)

    dashboard = dashboard_model.get_by_id(dashboard_id)

    public = dashboard.get('shared', False)
    if public == False:
        raise Http404


    all_metrics = dashboard_metrics_model.get_all(
        dashboard_id=dashboard_id,
        public=public)

    all_existing_server_ids = server_model.get_all_ids()

    metrics_array = _fill_metrics_arrays(all_metrics=all_metrics)
    
    return render(request, 'dashboards/public.html', {
        "account_id": account_id,
        "duration": duration,
        "health_checks": metrics_array['health_checks'],
        "selected_charts": metrics_array['charts'],
        "date_from" : date_from,
        "date_to" : date_to,
        "now": now_unix,
        "max_date": max_date,
        "dashboard": dashboard,
        "enddate": enddate,
        "all_existing_server_ids": all_existing_server_ids
    })
示例#20
0
文件: views.py 项目: HomemBravo/amon
def view_dashboard(request, dashboard_id):
    enddate = request.GET.get('enddate')
    duration = request.GET.get('duration', 1800)
    duration = int(duration)

    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)

    all_dashboards = dashboard_model.get_all(account_id=request.account_id)
    all_existing_server_ids = server_model.get_all_ids()
    dashboard = dashboard_model.get_by_id(dashboard_id)
    all_metrics = dashboard_metrics_model.get_all(account_id=request.account_id, dashboard_id=dashboard_id)


    metrics_array = _fill_metrics_arrays(all_metrics=all_metrics)


    if len(all_metrics) == 0:
        messages.add_message(request, messages.INFO, 'To view this dashboard add at least 1 metric')
        return redirect(reverse('edit_dashboard', kwargs={'dashboard_id': dashboard_id}))

    return render(request, 'dashboards/view.html', {
        "all_dashboards": all_dashboards,
        "duration": duration,
        "selected_charts": metrics_array['charts'],
        "health_checks": metrics_array['health_checks'],
        "date_from" : date_from,
        "date_to" : date_to,
        "now": now_unix,
        "max_date": max_date,
        "dashboard": dashboard,
        "enddate": enddate,
        "all_existing_server_ids": all_existing_server_ids
    })
示例#21
0
文件: views.py 项目: urandu/amon
def view_process(request, server_id):

    enddate = request.GET.get('enddate')
    process_id = request.GET.get('process', None)

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

    first_check_date = process_model.get_first_check_date(server)

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

    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)

    process = process_model.get_by_id(process_id)

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

    data_url = reverse('ajax_get_process_data_after')
    data_url = "{0}?server_id={1}&process={2}".format(data_url,
                                                      server.get('_id'),
                                                      process_id)

    selected_charts = [{
        'id': 'cpu',
        'check': 'cpu',
        'name': 'CPU',
        'url': data_url
    }, {
        'id': 'memory',
        'check': 'memory',
        'name': 'Memory',
        'url': data_url
    }, {
        'id': 'io',
        'check': 'io',
        'name': 'I/O',
        'url': data_url
    }]

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

    return render(
        request, 'processes/view.html', {
            "selected_charts": selected_charts,
            "enddate": enddate,
            "duration": duration,
            "all_plugins": all_plugins,
            "all_processes": all_processes,
            "now": now_unix,
            "first_check_date": first_check_date,
            "process": process,
            "date_from": date_from,
            "date_to": date_to,
            "server": server,
            "max_date": max_date,
            "breadcrumb_url": breadcrumb_url
        })
示例#22
0
文件: views.py 项目: HomemBravo/amon
def view_process(request, server_id):

    enddate = request.GET.get('enddate')
    process_id = request.GET.get('process', None)

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

    first_check_date = process_model.get_first_check_date(server)

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


    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)


    process = process_model.get_by_id(process_id)

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


    data_url = reverse('ajax_get_process_data_after')
    data_url = "{0}?server_id={1}&process={2}".format(data_url, server.get('_id'), process_id)

    selected_charts = [
        {'id': 'cpu', 'check': 'cpu', 'name': 'CPU', 'url': data_url},
        {'id': 'memory', 'check': 'memory', 'name': 'Memory', 'url': data_url},
        {'id': 'io', 'check': 'io', 'name': 'I/O', 'url': data_url}
    ]


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

    return render(request, 'processes/view.html', {
        "selected_charts": selected_charts,
        "enddate": enddate,
        "duration": duration,
        "all_plugins": all_plugins,
        "all_processes":all_processes,
        "now": now_unix,
        "first_check_date": first_check_date,
        "process":process,
        "date_from":date_from,
        "date_to":date_to,
        "server":server,
        "max_date":max_date,
        "breadcrumb_url": breadcrumb_url
    })
示例#23
0
文件: app.py 项目: marshall007/amon
    def get(self):
        date_from = self.get_argument('date_from', False)
        date_to = self.get_argument('date_to', False)
        charts = self.get_arguments('charts', None)

        if date_from:
            date_from = datestring_to_utc_datetime(date_from)
        # Default - 24 hours period
        else:
            day = timedelta(hours=24)
            date_from = self.now - day

        if date_to:
            date_to = datestring_to_utc_datetime(date_to)
        else:
            date_to = self.now

        date_from = datetime_to_unixtime(date_from)
        date_to = datetime_to_unixtime(date_to)

        if len(charts) > 0:
            active_checks = charts
        else:
            active_checks = settings.SYSTEM_CHECKS

        checks = system_model.get_system_data(active_checks, date_from,
                                              date_to)
        first_check_date = system_model.get_first_check_date()

        # Convert the dates to local time for display
        first_check_date = utc_unixtime_to_localtime(first_check_date)
        date_from = utc_unixtime_to_localtime(date_from)
        date_to = utc_unixtime_to_localtime(date_to)

        # Get the difference between UTC and localtime - used to display
        # the ticks in the charts
        zone_difference = localtime_utc_timedelta()

        # Get the max date - utc, converted to localtime
        max_date = utc_now_to_localtime()

        if checks != False:
            network = []
            network_interfaces = []

            disk = []
            volumes = []

            # Add network adapters
            if 'network' in active_checks:
                for check in checks['network']:
                    network.append(check)

                _interfaces = get_network_interfaces()
                for interface in _interfaces:
                    if interface not in network_interfaces:
                        network_interfaces.append(interface)

            # Add disk volumes
            if 'disk' in active_checks:
                for check in checks['disk']:
                    disk.append(check)

                _volumes = get_disk_volumes()
                for volume in _volumes:
                    if volume not in volumes:
                        volumes.append(volume)

            self.render('system.html',
                        current_page='system',
                        active_checks=active_checks,
                        charts=charts,
                        checks=checks,
                        network=network,
                        network_interfaces=network_interfaces,
                        volumes=volumes,
                        disk=disk,
                        date_from=date_from,
                        date_to=date_to,
                        first_check_date=first_check_date,
                        zone_difference=zone_difference,
                        max_date=max_date)
示例#24
0
def view_plugins(request, server_id):
    plugin_id = request.GET.get('plugin')
    enddate = request.GET.get('enddate')

    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

    plugin = plugin_model.get_by_id(plugin_id)

    selected_charts = []
    custom_metrics = {}
    include_template = False
    gauges = None
    counters = None
    nodata = False
    first_check_date = False

    if plugin:

        name = plugin.get('name')
        first_check_date = plugin_model.get_first_check(server=server,
                                                        plugin=plugin)
        gauges = plugin_model.get_gauges_cursor(plugin=plugin)
        counters = plugin_model.get_counters(plugin=plugin, server=server)

        plugin_model.get_table_data(plugin=plugin,
                                    server=server,
                                    table_name='slow_queries')

        if name in [
                'postgres', 'postgresql', 'mongo', 'mysql', 'nginx', 'apache'
        ]:
            include_template = name

            table_metrics = [
                'slow_queries', 'tables_size', 'index_hit_rate', 'not_found',
                'requests'
            ]
            for metric in table_metrics:
                additional_ignore_keys = [
                    'unique_hash'
                ] if metric == 'slow_queries' else []
                additional_ignore_keys = [
                    'full_name'
                ] if metric == 'tables_size' else additional_ignore_keys  # Mysql

                custom_metrics[metric] = plugin_model.get_table_data(
                    plugin=plugin,
                    server=server,
                    table_name=metric,
                    additional_ignore_keys=additional_ignore_keys)

        # Display no data for selected plugin message, list - meaning no cursor object
        if isinstance(gauges, list) and counters == None:
            nodata = True

        else:
            data_url = reverse('ajax_get_gauge_data_after')

            for g in gauges:
                gauge_name = g.get('name')
                gauge_id = g.get('_id')

                gauge_url = "{0}?gauge={1}".format(data_url, gauge_id)

                gauge_data = {
                    'id': gauge_id,
                    'check': gauge_name,
                    'name': gauge_name,
                    'url': gauge_url
                }
                selected_charts.append(gauge_data)

    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)

    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('view_plugins',
                             kwargs={'server_id': server['_id']})
    breadcrumb_url = "{0}?plugin={1}".format(breadcrumb_url, plugin_id)

    return render(
        request,
        'plugins/view.html',
        {
            "custom_metrics": custom_metrics,  # containers, slow queries, etc
            "include_template": include_template,
            "enddate": enddate,
            "duration": duration,
            "date_from": date_from,
            "date_to": date_to,
            "nodata": nodata,
            "server": server,
            "plugin": plugin,
            "selected_charts": selected_charts,
            "counters": counters,
            "all_plugins": all_plugins,
            "all_processes": all_processes,
            "now": now_unix,
            "max_date": max_date,
            "first_check_date": first_check_date,
            "breadcrumb_url": breadcrumb_url
        })
示例#25
0
文件: app.py 项目: manasg/amon
    def get(self):
        date_from = self.get_argument('date_from', False)
        date_to = self.get_argument('date_to', False)
        charts = self.get_arguments('charts', None)

        if date_from:
            date_from = datestring_to_utc_datetime(date_from)
        # Default - 24 hours period
        else:
            day = timedelta(hours=24)
            date_from = self.now - day

        if date_to:
            date_to = datestring_to_utc_datetime(date_to)
        else:
            date_to = self.now

        date_from = datetime_to_unixtime(date_from)
        date_to = datetime_to_unixtime(date_to)

        if len(charts) > 0:
            active_checks = charts
        else:
            active_checks = settings.SYSTEM_CHECKS

        checks = system_model.get_system_data(active_checks, date_from, date_to)
        first_check_date = system_model.get_first_check_date()

        # Convert the dates to local time for display
        first_check_date = utc_unixtime_to_localtime(first_check_date)
        date_from = utc_unixtime_to_localtime(date_from)
        date_to = utc_unixtime_to_localtime(date_to)

        # Get the difference between UTC and localtime - used to display 
        # the ticks in the charts
        zone_difference = localtime_utc_timedelta()

        # Get the max date - utc, converted to localtime
        max_date = utc_now_to_localtime()

        if checks != False:
            network = []
            network_interfaces = []

            disk = []
            volumes = []

            # Add network adapters 
            if 'network' in active_checks:
                for check in checks['network']:
                    network.append(check)   

                _interfaces = get_network_interfaces()
                for interface in _interfaces:
                    if interface not in network_interfaces:
                        network_interfaces.append(interface)

            # Add disk volumes
            if 'disk' in active_checks:
                for check in checks['disk']:
                    disk.append(check)

                _volumes = get_disk_volumes()
                for volume in _volumes:
                    if volume not in volumes:
                        volumes.append(volume)

            self.render('system.html',
                    current_page='system',
                    active_checks=active_checks,
                    charts=charts,
                    checks=checks,
                    network=network,
                    network_interfaces=network_interfaces,
                    volumes=volumes,
                    disk=disk,
                    date_from=date_from,
                    date_to=date_to,
                    first_check_date=first_check_date,
                    zone_difference=zone_difference,
                    max_date=max_date
                    )
示例#26
0
文件: views.py 项目: 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
    })
示例#27
0
文件: views.py 项目: zeus911/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
        })