def bwmonitor(interface):
    client_id = util.get_client_id()

    MAX_32UINT = (2**32) - 1
    STATS_PATH = "/sys/class/net/{}/statistics".format(interface)

    try:
        rx_bytes_file = open("{}/rx_bytes".format(STATS_PATH))
    except:
        sys.exit(2)
    try:
        tx_bytes_file = open("{}/tx_bytes".format(STATS_PATH))
    except:
        sys.exit(2)

    last_rx_bytes = None
    last_tx_bytes = None
    last_time = None
    dbq = db_queue()
    while True:
        loop_start_time = time.time()
        rx_bytes_file.seek(0)
        rx_bytes = long(rx_bytes_file.read().strip())
        tx_bytes_file.seek(0)
        tx_bytes = long(tx_bytes_file.read().strip())
        if last_time is not None:
            if last_rx_bytes > rx_bytes:
                # rollover occurred
                rx_bytes_delta = rx_bytes + (MAX_32UINT - last_rx_bytes)
            else:
                rx_bytes_delta = rx_bytes - last_rx_bytes
            if last_tx_bytes > tx_bytes:
                # rollover occurred
                tx_bytes_delta = tx_bytes + (MAX_32UINT - last_tx_bytes)
            else:
                tx_bytes_delta = tx_bytes - last_tx_bytes
            time_delta = loop_start_time - last_time
            rx_bps = float(rx_bytes_delta * 8) / time_delta
            tx_bps = float(tx_bytes_delta * 8) / time_delta
            bw_data = { "type" : "bandwidth", \
                         "data" : {  "client_id" : client_id, \
                                   "timestamp" : loop_start_time, \
                                   "rx_bytes" : rx_bytes_delta, \
                                   "tx_bytes" : tx_bytes_delta, \
                                   "rx_bps" : rx_bps, \
                                   "tx_bps" : tx_bps}
                     }
            dbq.write(bw_data)

        last_time = loop_start_time
        last_rx_bytes = rx_bytes
        last_tx_bytes = tx_bytes

        # sleep off remaining time
        sleeptime = 1.0 - (time.time() - loop_start_time)
        if (sleeptime > 0):
            try:
                time.sleep(sleeptime)
            except:
                pass
Esempio n. 2
0
	def get_report_path(self):
		if "data_root" in self.settings_json:
			client_id = util.get_client_id()
			report_path = "{}/{}/reports".format(self.settings_json["data_root"].rstrip("/"),client_id)
			return report_path
		else:
			return None
Esempio n. 3
0
	def get_db_path(self):
		if "data_root" in self.settings_json:
			client_id = util.get_client_id()
			db_path = "{}/{}/database".format(self.settings_json["data_root"].rstrip("/"),client_id)
			return db_path
		else:
			return None
Esempio n. 4
0
	def get_db_filename(self):
		if "data_root" in self.settings_json:
			client_id = util.get_client_id()
			db_filename = "{}/{}/database/{}.db".format(self.settings_json["data_root"].rstrip("/"),client_id,client_id)
			return db_filename
		else:
			return None
Esempio n. 5
0
def bwmonitor(interface):
	client_id = util.get_client_id()
	os_word_size = 64 if sys.maxsize > 2**32 else 32
	MAXUINT = (2 ** os_word_size) - 1
	STATS_PATH="/sys/class/net/{}/statistics".format(interface)
	try:
		rx_bytes_file = open("{}/rx_bytes".format(STATS_PATH))
	except:
		sys.exit(2)
	try:
		tx_bytes_file = open("{}/tx_bytes".format(STATS_PATH))
	except:
		sys.exit(2)
	last_rx_bytes = None
	last_tx_bytes = None
	last_time = None
	dbq = db_queue()
	while True:
		loop_start_time = time.time()
		rx_bytes_file.seek(0)
		rx_bytes = int(rx_bytes_file.read().strip())
		tx_bytes_file.seek(0)
		tx_bytes = int(tx_bytes_file.read().strip())
		if last_time is not None:
			rx_bytes_delta = rx_bytes - last_rx_bytes if rx_bytes >= last_rx_bytes else MAXUINT - last_rx_bytes + rx_bytes + 1
			tx_bytes_delta = tx_bytes - last_tx_bytes if tx_bytes >= last_tx_bytes else MAXUINT - last_tx_bytes + tx_bytes + 1
			time_delta = loop_start_time - last_time
			rx_bps = float(rx_bytes_delta * 8) / time_delta
			tx_bps = float(tx_bytes_delta * 8) / time_delta
			bw_data = { "type" : "bandwidth", \
						"data" : {  "client_id" : client_id, \
						"timestamp" : loop_start_time, \
						"rx_bytes" : rx_bytes_delta, \
						"tx_bytes" : tx_bytes_delta, \
						"rx_bps" : rx_bps, \
						"tx_bps" : tx_bps}
			}
			dbq.write(bw_data)
		last_time = loop_start_time
		last_rx_bytes = rx_bytes
		last_tx_bytes = tx_bytes

		# sleep off remaining time
		sleeptime = 1.0 - (time.time() - loop_start_time)
		if (sleeptime > 0):
			try:
				time.sleep (sleeptime)
			except:
				pass
 def get(self):
   """Display the index page."""
   approval_prompt = 'auto'
   button_display = 'none'
   if self.request.get('approvalPrompt') == 'force':
     approval_prompt = 'force'
     button_display = 'block'
   template_data = {
       'approvalPrompt': approval_prompt,
       'buttonDisplay': button_display,
       'clientId': util.get_client_id(),
       'scope': ' '.join(util.SCOPES),
   }
   template = JINJA_ENVIRONMENT.get_template('index.html')
   self.response.write(template.render(template_data))
Esempio n. 7
0
 def get(self):
     """Display the index page."""
     approval_prompt = 'auto'
     button_display = 'none'
     if self.request.get('approvalPrompt') == 'force':
         approval_prompt = 'force'
         button_display = 'block'
     template_data = {
         'approvalPrompt': approval_prompt,
         'buttonDisplay': button_display,
         'clientId': util.get_client_id(),
         'scope': ' '.join(util.SCOPES),
     }
     template = JINJA_ENVIRONMENT.get_template('index.html')
     self.response.write(template.render(template_data))
Esempio n. 8
0
# This file is part of the Network Performance Monitor which is released under the GNU General Public License v3.0
# See the file LICENSE for full license details.

import datetime
import time
import sqlite3
import json
from sqlite3 import Error
import posix_ipc
import sys
import util
import logging
import os
from netperf_settings import netperf_settings

client_id = util.get_client_id()

NETPERF_SETTINGS = netperf_settings()

DATA_PATH = NETPERF_SETTINGS.get_db_path()
NETPERF_DB = NETPERF_SETTINGS.get_db_filename()

DB_WRITE_QUEUE = NETPERF_SETTINGS.get_db_write_queue_name()
LOG_PATH = NETPERF_SETTINGS.get_log_path()
LOG_FILE = NETPERF_SETTINGS.get_log_filename()

if not os.path.isdir(DATA_PATH):
    os.makedirs(DATA_PATH)

if not os.path.isdir(LOG_PATH):
    os.makedirs(LOG_PATH)
#!/usr/bin/env python
# This file is part of the Network Performance Monitor which is released under the GNU General Public License v3.0
# See the file LICENSE for full license details.

import sys
import util
from datetime import datetime, timedelta
from netperf_db import db_queue
from util import get_client_id

client_id = get_client_id()

dbq = db_queue()

message = { "type" : "data_usage_reset",\
     "data" : { "client_id" : client_id } }
dbq.write(message)
Esempio n. 10
0
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.dates as md
import numpy as np
import re
import util
from netperf_db import netperf_db
from netperf_settings import netperf_settings
import pprint
import logging
from time_bins import time_bins

NETPERF_SETTINGS = netperf_settings()
CLIENT_ID = util.get_client_id()
DATA_ROOT="{}/{}".format(NETPERF_SETTINGS.get_data_root(),CLIENT_ID)
NETPERF_DB=NETPERF_SETTINGS.get_db_filename()
REPORT_TEMPLATE_PATH="/opt/netperf/templates"
REPORT_TEMPLATE_FILENAME="netperf_report_template.tex"
REPORTS_PATH="{}/reports".format(DATA_ROOT)
TMP_PATH="{}/tmp".format(REPORTS_PATH)

if not os.path.isdir(REPORTS_PATH):
	os.makedirs(REPORTS_PATH)

if not os.path.isdir(TMP_PATH):
	os.makedirs(TMP_PATH)

logging.basicConfig(filename=NETPERF_SETTINGS.get_log_filename(), format=NETPERF_SETTINGS.get_logger_format())
report_log = logging.getLogger("daily report")