码云账号不再使用社区账号进行二次身份验证的通知 详情
私信发送成功
Watch Star Fork

灰太狼。 / LepusPython

简洁、直观、强大的开源企业级数据库监控系统,MySQL/Oracle/MongoDB/Redis一站式监控,让数据库监控更简单。支持邮件告警、短信告警、AWR性能报告、慢查询分析等专业功能。 http://www.oschina.net/p/lepus
克隆/下载
一键复制 编辑 原始数据 按行查看 历史
check_os.py 2.82 KB ruzuojun 提交于 2017-08-07 15:36 . 代码目录调整,修改readme
#!//bin/env python
#coding:utf-8
import os
import sys
import string
import time
import datetime
import MySQLdb
import logging
import logging.config
logging.config.fileConfig("etc/logger.ini")
logger = logging.getLogger("lepus")
path='./include'
sys.path.insert(0,path)
import functions as func
import thread
from multiprocessing import Process;
dbhost = func.get_config('monitor_server','host')
dbport = func.get_config('monitor_server','port')
dbuser = func.get_config('monitor_server','user')
dbpasswd = func.get_config('monitor_server','passwd')
dbname = func.get_config('monitor_server','dbname')
def check_os(ip,community,filter_os_disk,tags):
func.mysql_exec("insert into os_status_history select *, LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from os_status where ip='%s';" %(ip),'')
func.mysql_exec("insert into os_disk_history select *, LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from os_disk where ip='%s';" %(ip),'')
func.mysql_exec("insert into os_diskio_history select *, LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from os_diskio where ip='%s';" %(ip),'')
func.mysql_exec("insert into os_net_history select *, LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),12) from os_net where ip='%s';" %(ip),'')
func.mysql_exec("delete from os_status where ip='%s'" %(ip),'')
func.mysql_exec("delete from os_disk where ip='%s'" %(ip),'')
func.mysql_exec("delete from os_diskio where ip='%s'" %(ip),'')
func.mysql_exec("delete from os_net where ip='%s'" %(ip),'')
command="sh check_os.sh"
try :
os.system("%s %s %s %s %s %s %s %s %s %s"%(command,ip,dbhost,dbport,dbuser,dbpasswd,dbname,community,filter_os_disk,tags))
logger.info("%s:%s statspack complete."%(dbhost,dbport))
except Exception, e:
print e
logger.info("%s:%s statspack error: %s"%(dbhost,dbport,e))
sys.exit(1)
finally:
sys.exit(1)
def main():
#get os servers list
servers=func.mysql_query("select host,community,filter_os_disk,tags from db_servers_os where is_delete=0 and monitor=1;")
logger.info("check os controller started.")
if servers:
plist = []
for row in servers:
host=row[0]
community=row[1]
filter_os_disk=row[2]
tags=row[3]
if host <> '' :
thread.start_new_thread(check_os, (host,community,filter_os_disk,tags))
time.sleep(1)
#p = Process(target = check_os, args=(host,filter_os_disk))
#plist.append(p)
#p.start()
#for p in plist:
# p.join()
else:
logger.warning("check os: not found any servers")
logger.info("check os controller finished.")
if __name__=='__main__':
main()

评论 (0)

你可以在登录后,对此项目发表评论

2_float_left_people 2_float_left_close