Esempio n. 1
0
def store(now, data):
    node_id = data.get('node_id')
    if node_id:
        loc = path.join(DATADIR, '{}.json'.format(node_id))

        node = readjson(loc)
        if not node:
            node = {'log': {}}
        clients = data.get('clients', {})
        traffic = data.get('traffic', {})

        node['hostname'] = data.get('hostname')

        node['log'][now] = {}
        node['log'][now]['load_avg'] = data.get('loadavg')
        node['log'][now]['clients_total'] = clients.get('total')
        node['log'][now]['clients_wifi'] = clients.get('wifi')
        node['log'][now]['traffic_rx'] = traffic.get('rx', {}).get('bytes')
        node['log'][now]['traffic_tx'] = traffic.get('tx', {}).get('bytes')
        node['log'][now]['traffic_forward'] = traffic.get('forward',
                                                          {}).get('bytes')
        node['log'][now]['traffic_mgmt_rx'] = traffic.get('mgmt_tx',
                                                          {}).get('bytes')
        node['log'][now]['traffic_mgmt_tx'] = traffic.get('mgmt_tx',
                                                          {}).get('bytes')

        return writejson(loc, node)
Esempio n. 2
0
def store(now, data):
    node_id = data.get('node_id')
    if node_id:
        loc = path.join(DATADIR, '{}.json'.format(node_id))

        node = readjson(loc)
        if not node:
            node = {'log': {}}
        clients = data.get('clients', {})
        traffic = data.get('traffic', {})

        node['hostname'] = data.get('hostname')

        node['log'][now] = {}
        node['log'][now]['load_avg'] = data.get('loadavg')
        node['log'][now]['clients_total'] = clients.get('total')
        node['log'][now]['clients_wifi'] = clients.get('wifi')
        node['log'][now]['traffic_rx'] = traffic.get('rx', {}).get('bytes')
        node['log'][now]['traffic_tx'] = traffic.get('tx', {}).get('bytes')
        node['log'][now][
            'traffic_forward'
        ] = traffic.get('forward', {}).get('bytes')
        node['log'][now][
            'traffic_mgmt_rx'
        ] = traffic.get('mgmt_tx', {}).get('bytes')
        node['log'][now][
            'traffic_mgmt_tx'
        ] = traffic.get('mgmt_tx', {}).get('bytes')

        return writejson(loc, node)
Esempio n. 3
0
def load():
    conf = readjson(CONFIG)
    if not conf:
        conf = {}
    if not conf.get('connection'):
        conf['connection'] = gen_connection()
    if not conf.get('targets'):
        conf['targets'] = gen_targets()
    if not conf.get('upload'):
        conf['upload'] = gen_upload()

    writejson(CONFIG, conf)
    return conf
Esempio n. 4
0
def load():
    conf = readjson(CONFIG)
    if not conf:
        conf = {}
    if not conf.get("connection"):
        conf["connection"] = gen_connection()
    if not conf.get("targets"):
        conf["targets"] = gen_targets()
    if not conf.get("upload"):
        conf["upload"] = gen_upload()

    writejson(CONFIG, conf)
    return conf
Esempio n. 5
0
def _load():
    sdata = {'log': {}, 'hostname': 'Summary'}

    for jf in listdir(DATADIR):
        if fnmatch(jf, '*.json'):
            data = readjson(path.join(DATADIR, jf))
            yield PlotNode(data)

            for ts in data['log']:

                sdata['log'][ts] = sdata['log'].get(ts, {})
                for field in data['log'][ts]:
                    dt = data['log'][ts][field]
                    sdata['log'][ts][field] = sdata['log'][ts].get(field, 0)
                    if dt is not None:
                        sdata['log'][ts][field] += dt

    sum_node = PlotNode(sdata)
    save('_sum', sum_node.clients(), 'clients')
    save('_sum', sum_node.traffic(), 'traffic')
    save('_sum', sum_node.traffic_full(), 'traffic_full')
Esempio n. 6
0
def _load():
    sdata = {
        'log': {},
        'hostname': 'Summary'
    }

    for jf in listdir(DATADIR):
        if fnmatch(jf, '*.json'):
            data = readjson(path.join(DATADIR, jf))
            yield PlotNode(data)

            for ts in data['log']:

                sdata['log'][ts] = sdata['log'].get(ts, {})
                for field in data['log'][ts]:
                    dt = data['log'][ts][field]
                    sdata['log'][ts][field] = sdata['log'][ts].get(field, 0)
                    if dt is not None:
                        sdata['log'][ts][field] += dt

    sum_node = PlotNode(sdata)
    save('_sum', sum_node.clients(), 'clients')
    save('_sum', sum_node.traffic(), 'traffic')
    save('_sum', sum_node.traffic_full(), 'traffic_full')