Ejemplo n.º 1
0
#!/usr/bin/env python

from core.psql import DB
from core.acedb import AceDB
import time
from core.util import parse_config, is_ark_fork, get_dbname

atomic = 100000000

if __name__ == '__main__':

    #ark_fork = ['ark','dark','kapu', 'dkapu', 'persona-t']
    # get config data
    network, coin = parse_config()

    # initialize db connection
    #check for special usernames needed for lisk forks
    username = get_dbname(coin)
    db = DB(network[coin['channel']['channel']]['db'], username,
            network[coin['channel']['channel']]['db_pw'])

    # connect to contracts database and get last row of tx
    acesdb = AceDB(coin['channel']['dbusername'])

    check_start = acesdb.getRows().fetchall()

    if check_start:
        #this means we have a starting row
        for r in check_start:
            r_start = r[0]
        #set starting row for processing
Ejemplo n.º 2
0
def _run(options):

    ######## file lock ########
    file_lock = util.FileLock("var/run/monitor.lock")
    if not file_lock.lock():
        print "Monitor is running"
        sys.exit(1)

    pattern = util.build_pattern(sfg.LOG_FORMAT)
    config_file = options.config_file
    alert_status_config_file, response_range_config_file, response_ratio_config_file, request_ratio_config_file = util.parse_config(
        config_file)

    while True:
        count = 0
        sys.stdout.flush()
        if not options.continue_read and not options.loop_run:
            fp = open(options.access_log, "r")
        else:
            fp = pygtail.Pygtail(options.access_log,
                                 offset_file="var/run/access_log.offset")

        if fp is not None:
            for line in fp:
                try:
                    count = count + 1
                    record = util.parse_log(line, pattern)
                    if record is None:
                        continue
                    util.alert_status(record, alert_status_config_file)
                    util.alert_response_time_range(record,
                                                   response_range_config_file)
                    util.alert_response_time_ratio(record,
                                                   response_ratio_config_file)
                    util.alert_request_time_ratio(record,
                                                  request_ratio_config_file)
                except Exception, ex:
                    logging.error("monitor exception: %s" %
                                  traceback.format_exc())
        if not options.loop_run:
            break
        if count < 1000:
            time.sleep(1)
        elif count < 10:
            time.sleep(5)