Exemplo n.º 1
0
        conn_num = stdout.read().strip()
        #print 'dddddddddddddddd',hostname,conn_num
        s.close()
    except Exception, e:
        print 'error:%s', str(e)
    if conn_num:
        return conn_num
    else:
        conn_num = 0
        return conn_num


if __name__ == '__main__':
    modname = 'remoteline.py'
    if not os.path.exists('/home/config'):
        os.makedirs('/home/config', 0777)
    if not os.path.exists('/home/config/monitorNewlinenumber.ini'):
        get_output(
            '\cp -rf /tools/config/nsconfig/monitorlinenumber.ini /home/config/monitorNewlinenumber.ini'
        )
    writeConfigLimitNum('line')
    writeConfigLimitNum('cpumen')
    cmd = '''ps -ef |grep %s|grep -v grep|wc -l''' % modname
    num = getoutput(cmd)
    if int(num) == 1:
        line()
        cpumen()
    else:
        log(modname, 3, '进程已经存在: %s' % modname)
        sys.exit()
Exemplo n.º 2
0
    global logDir
    if not os.path.exists(logDir):
        os.mkdir(logDir, 0777)
    logger = logging.getLogger()
    logPath = os.path.join(logDir, logName + '.log')
    hdl = logging.FileHandler(logPath)
    formatter = logging.Formatter(
        '%(asctime)s %(levelname)s(funcName)s %(lineno)s %(message)s')
    hdl.setFormatter(formatter)
    logger.addHandler(hdl)
    logger.setLevel(logging.NOTSET)

    return logger


if __name__ == '__main__':
    modname = 'monitoronline.py'
    if not os.path.exists('/home/config'):
        os.makedirs('/home/config', 0777)
    if not os.path.exists('/home/config/monitoronline.ini'):
        get_output(
            '\cp -rf /tools/config/nsconfig/monitoronline.ini /home/config/monitoronline.ini'
        )
    cmd = '''ps -ef |grep %s|grep -v grep|wc -l''' % modname
    num = getoutput(cmd)
    if int(num) == 1:
        line()
    else:
        log(modname, 3, '进程已经存在: %s' % modname)
        sys.exit()
Exemplo n.º 3
0
def gethostname():
    Hostname = r''' cat /ss/tools/line.sh | grep ^server | cut -d '"' -f 2 '''
    ret, reterr = get_output(Hostname)
    ret_all, reterr_all = get_output("""hostname|sed 's/\..*//g'""")
    hs_all, hserr_all = get_output("hostname")
    return ret[:-1], ret_all.rstrip(), hs_all
Exemplo n.º 4
0
        logname = logName + '.log'
        logpath = os.path.join(sys.path[0], logname)
    hdl = logging.FileHandler(logpath)
    formatter = logging.Formatter(
        '%(asctime)s %(levelname)s %(message)s (ln:%(lineno)d)')
    hdl.setFormatter(formatter)
    logger.addHandler(hdl)
    logger.setLevel(logging.NOTSET)
    return logger


if __name__ == "__main__":

    if not os.path.exists('/home/config/collectNew.ini'):
        if not os.path.exists('/home/config'):
            os.mkdir('/home/config', 0777)
        if os.path.exists('/tools/config/nsconfig/collectNew.ini'):
            get_output(
                '\cp -rf /tools/config/nsconfig/collectNew.ini /home/config/collectNew.ini'
            )
        else:
            sys.exit()
    wm = pyinotify.WatchManager()
    mask = pyinotify.IN_CREATE | pyinotify.IN_MODIFY
    handler = EventHandler()
    notifier = pyinotify.Notifier(wm, handler)
    wdd = wm.add_watch(sys.argv[1], mask, rec=True)
    loger = getLog('/var/log/runlog', 'loginerrorNews')
    loger.info(str(wdd))
    notifier.loop()