コード例 #1
0
ファイル: monitor.py プロジェクト: nsavelyeva/crowdbench
def get_chartdata():
    """Collect data from a slave to build a chart on the monitoring web-page."""
    callback = bottle.request.query.get('callback')
    y_axis = bottle.request.query.get('y_axis').strip()
    w_acts = [
        "action='%s'" % act
        for act in bottle.request.query.get('actions').strip().split(',')
    ]
    w_acts = 'AND (%s)' % ' OR '.join(w_acts) if w_acts else ''
    f_value = 'AVG(latency)' if y_axis.startswith(
        'avg') else 'COUNT(timestamp)'
    atomic = 1 if y_axis in ['aops', 'avgl'] else 0

    db_conn = tools.get_db_conn('%s.db' % bottle.request.query.test_run_id)
    sql = 'SELECT test_run_status, timestamp_started, timestamp_completed FROM info LIMIT 1'
    status, started, finished = tools.db_query(db_conn, sql)[1][0]
    progress = int(float(finished) - float(started)) if finished \
        else int(tools.get_timestamp() - float(started))

    sql = 'SELECT substr(timestamp, 0, 11), code, %s FROM recs ' % f_value + \
          'WHERE atomic=%s %s GROUP BY code, substr(timestamp, 0, 11) ' % (atomic, w_acts) + \
          'ORDER BY id DESC LIMIT 3600'  # last 1 hour activity

    result = tools.db_query(db_conn, sql)[1] if finished else tools.db_query(
        db_conn, sql)[1][:-1]
    result = list(reversed(result))
    results = {
        str(abs(int(item[0]) - int(float(started)))): {
            'failed': 0,
            'passed': 0,
            'incomplete': 0
        }
        for item in result
    }
    for item in result:  # item[0] - timestamp, item[1] - code (None if incomplete), item[2] - value
        timestamp = str(int(item[0]) - int(float(started)))
        value = item[2] or 0
        results[timestamp][
            'failed'] += value if item[1] and item[1] != 200 else 0
        results[timestamp]['passed'] += value if item[1] == 200 else 0
        results[timestamp]['incomplete'] += value if item[1] == None else 0
    results = [{
        'timestamp': key,
        'failed': value['failed'],
        'passed': value['passed'],
        'incomplete': value['incomplete']
    } for key, value in results.items()]
    result = {
        bottle.request.query.slave: results,
        'status': status,
        'started': started,
        'finished': finished or '(not finished)',
        'progress': progress
    }
    return '{0}({1})'.format(callback, result)
コード例 #2
0
 def start(self):
     """Create a test-run database on the slave and insert information about the test run."""
     conn = tools.get_db_conn('%s.db' % self.test_run_id)
     tools.db_init(conn)
     sql = "INSERT INTO info " + \
           "(test_run_id, slave_name, timestamp_started, total_load_info, slave_load_info) " + \
           "VALUES ('%s', '%s', '%s', '%s', '%s')"
     tools.db_query(
         conn, sql % (self.test_run_id, self.name, tools.get_timestamp(),
                      json.dumps(self.test, sort_keys=True, indent=4),
                      json.dumps(self.load, sort_keys=True, indent=4)))
コード例 #3
0
ファイル: monitor.py プロジェクト: nsavelyeva/crowdbench
def get_summary():
    """Collect summary of responses from a slave to display it on the monitoring web-page."""
    callback = bottle.request.query.get('callback')
    db_conn = tools.get_db_conn('%s.db' % bottle.request.query.test_run_id)
    sql = 'SELECT code, reason, COUNT(*) FROM recs GROUP BY reason'
    result = tools.db_query(db_conn, sql)[1]
    results = [{
        'reason': item[1] or 'Incompleted (still running or aborted)',
        'count': item[2],
        'code': str(item[0])
    } for item in result if item[2]]
    return '{0}({1})'.format(callback, results)
コード例 #4
0
if not lib_gl.is_valid_sender(sender):
    sys.exit('<<< ERROR >>> Invalid sender address.')

if '@' not in rcpt:
    sys.exit('<<< ERROR >>> Invalid recipient address.')


# Check whether sender address is a domain name.
sender_is_domain = False
sender_domain = ''
if utils.is_valid_amavisd_address(sender) in ['domain', 'subdomain']:
    sender_is_domain = True
    sender_domain = sender.split('@', 1)[-1]

# Connection cursor with web.py
conn = get_db_conn('iredapd')

# Connection cursor with SQLAlchemy
conn2 = get_db_conn2('iredapd')

gl_setting = lib_gl.get_gl_base_setting(account=rcpt, sender=sender)

# Perform the operations
if action == 'enable':
    logger.info("* Enable greylisting: {} -> {}".format(sender, rcpt))

    qr = lib_gl.enable_greylisting(conn=conn2,
                                   account=rcpt,
                                   sender=sender)
    if not qr[0]:
        logger.info(qr[1])
コード例 #5
0
ファイル: cleanup_db.py プロジェクト: trangnth/iRedAPD
import time
import web

os.environ['LC_ALL'] = 'C'

rootdir = os.path.abspath(os.path.dirname(__file__)) + '/../'
sys.path.insert(0, rootdir)

import settings
from tools import get_db_conn, cleanup_sql_table

web.config.debug = False

backend = settings.backend
now = int(time.time())
conn_iredapd = get_db_conn('iredapd')

#
# Throttling
#
cleanup_sql_table(conn=conn_iredapd,
                  sql_table='throttle_tracking',
                  sql_where='(init_time + period) < %d' % now,
                  print_left_rows=True)

#
# Greylisting tracking records.
#
cleanup_sql_table(conn=conn_iredapd,
                  sql_table='greylisting_tracking',
                  sql_where='record_expired < %d' % now,
コード例 #6
0
 def complete(self):
     """Update a local test-run database on the slave once test run is completed."""
     tools.db_query(
         tools.get_db_conn('%s.db' % self.test_run_id),
         "UPDATE info SET test_run_status = 'FINISHED', timestamp_completed = '%s'"
         % tools.get_timestamp())
コード例 #7
0
ファイル: aload.py プロジェクト: nsavelyeva/crowdbench
 def __init__(self, test_run_id, slave_load):
     self.test_run_id = test_run_id
     self.slave_load = slave_load
     self.db_conn = tools.get_db_conn(
         '%s.db' % self.test_run_id) if test_run_id else None
     self.users = tools.load_users('users.txt')