Exemple #1
0
#!/usr/bin/python
#-*- coding: utf-8 -*-

from ua.common.rrdtool import updater, grapher, fetcher
from ua.common.utils import current_dir, get_log
from ua.common.daemon import Daemon
from ua.common.ua_conf import ua_conf, ua_path

import os
import time
import threading

imgs_dir = os.path.join(ua_path, ua_conf.rrd_imgs_dir)
rrdtool_log = get_log('rrdtool', ua_conf.rrd_log)


def work():
    while True:
        updater.update(rrds_dir=ua_conf.rrd_rrds_dir, imgs_dir=imgs_dir)
        time.sleep(ua_conf.moni_interval)


class ThreadRrdtool(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        work()


class ThreadRrdtoolDaemon(Daemon):
Exemple #2
0
#!/usr/bin/python
#-*- coding: utf-8 -*-

import httplib

from ua.common.utils import get_log
from ua.common.ua_conf import *

request_log = get_log('request', conf_request_log)


def request(host, method, url, headers, params, port=80):
    msg = ""
    for i in [host, method, url, headers, params, port]:
        msg = msg + str(i) + ";"
    try:
        conn = httplib.HTTPConnection(host, port)
        conn.request(method=method, url=url, body=params, headers=headers)
        resp = conn.getresponse()
        data = resp.read()
        conn.close()
        msg = msg + ";" + "finished"
    except:
        msg = msg + ";" + "Bad response from :%s" % (host)
        raise Exception('Bad response from : %s' % host)
    request_log.info(msg)
    return data
Exemple #3
0
    'Login',
    '/stat',
    'Stat',
    '/async_events',
    'Async_events',
)

render = render_jinja(
    'webapps/ear/templates',
    encoding='utf-8',
)
app = web.application(urls, locals())

if not os.path.isdir(os.path.dirname(ear_log_path)):
    os.makedirs(os.path.dirname(ear_log_path))
ear_log = get_log("ear", ear_log_path)

alert_db = LocalSqliteDB('alert', db_dir, sql_dir)
alert_db = os.path.join(db_dir, 'alert.db')

ASYNC_EVENTS_LOG_PATH = os.path.join(ua_data_path,
                                     'store/log/async_events.log')
async_events_log_dir = os.path.dirname(ASYNC_EVENTS_LOG_PATH)

if not os.path.exists(async_events_log_dir):
    mkdirs(async_events_log_dir)


def get_async_log():
    my_logger = logging.getLogger("async_log")
    my_logger.setLevel(logging.DEBUG)
Exemple #4
0
import commands
import logging
import logging.handlers

urls = (
        '/login', 'Login',
        '/stat', 'Stat',
        '/async_events', 'Async_events',
        )

render = render_jinja('webapps/ear/templates', encoding='utf-8',)
app = web.application(urls, locals())

if not os.path.isdir(os.path.dirname(ear_log_path)):
    os.makedirs(os.path.dirname(ear_log_path))
ear_log = get_log("ear", ear_log_path)

alert_db = LocalSqliteDB('alert', db_dir, sql_dir)
alert_db = os.path.join(db_dir, 'alert.db')

ASYNC_EVENTS_LOG_PATH = os.path.join(ua_data_path, 'store/log/async_events.log')
async_events_log_dir = os.path.dirname(ASYNC_EVENTS_LOG_PATH)

if not os.path.exists(async_events_log_dir):
    mkdirs(async_events_log_dir)

def get_async_log():
    my_logger = logging.getLogger("async_log")
    my_logger.setLevel(logging.DEBUG)
    i = 10 #单位是一兆。
    handler = logging.handlers.RotatingFileHandler(
Exemple #5
0
#!/usr/bin/python
#-*- coding: utf-8 -*-

import httplib

from ua.common.utils import get_log
from ua.common.ua_conf import *

request_log = get_log('request', conf_request_log)

def request(host, method, url, headers, params, port=80):
    msg = ""
    for i in [host, method, url, headers, params, port]:
        msg = msg + str(i) + ";"
    try:
        conn = httplib.HTTPConnection(host, port)
        conn.request(method=method, url=url, body=params, headers=headers)
        resp = conn.getresponse()
        data = resp.read()
        conn.close()
        msg = msg + ";" + "finished"
    except:
        msg = msg + ";" + "Bad response from :%s"%(host)
        raise Exception('Bad response from : %s'% host)
    request_log.info(msg)
    return data
Exemple #6
0
#!/usr/bin/python
#-*- coding: utf-8 -*-

from ua.common.rrdtool import updater, grapher, fetcher
from ua.common.utils import current_dir, get_log
from ua.common.daemon import Daemon
from ua.common.ua_conf import ua_conf, ua_path

import os
import time
import threading

imgs_dir = os.path.join(ua_path, ua_conf.rrd_imgs_dir)
rrdtool_log = get_log('rrdtool', ua_conf.rrd_log)

def work():
    while True:
        updater.update(rrds_dir=ua_conf.rrd_rrds_dir, imgs_dir=imgs_dir)
        time.sleep(ua_conf.moni_interval)

class ThreadRrdtool(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        work()

class ThreadRrdtoolDaemon(Daemon):
    def __init__(self):
        rundir = os.path.dirname(ua_conf.rrd_pid_file)
        if not os.path.exists(rundir):
            os.makedirs(rundir)