码迷,mamicode.com
首页 > 其他好文 > 详细

rsyslog 客户端监控

时间:2014-09-23 13:22:14      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:服务端   监控   客户端   

服务端去给客户端发指令,告诉客户端我curl完了,客户端也就是rsyslog服务端

#!/usr/bin/python

import pycurl

import socket

import time


def work_socket():

    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    s.bind((‘10.67.15.96‘,9999))

    s.listen(10)

    s.setblocking(0)

    s.settimeout(10)

    conn,addr=s.accept()

    conn.send(‘10.67.15.96‘)




if __name__ == ‘__main__‘:

        common_list=[‘10.67.15.22‘,‘10.67.15.24‘,‘10.67.15.25‘,‘10.67.15.48‘]

        bigapp_list=[‘10.67.15.39‘,‘10.67.15.65‘,‘10.67.15.66‘,‘10.67.15.27‘]

        ent_list=[‘10.67.15.23‘,‘10.67.15.42‘,‘10.67.15.43‘,‘10.67.15.67‘,‘10.67.15.68‘,‘10.67.15.69‘]

        c=pycurl.Curl()

        for ia in range(100):

            for i in common_list:

                c.setopt(c.HTTPHEADER,["Host:monitorcommon1.sinaapp.com","Appname:monitorcommon1","AppVersion:3","AppHash:604","AccessKey:2ynwm3xxlm","SecretKey: lwz24z

32mm3lz0ji225x4ykwhk1x5mwkj33x1wwy","McIP: 1default;1::;1:@default:;;","MysqlPort: 3307","AppCookie: aks=4j33x1wm2n,5020k300z0,5m0lw4l3zl,o4550jjym3,o1n5kwmyx0,3ozlxlo0

jy,k40z12j23x,yyl3jxzj3x,kxjyl3llyy,,,,looz04o3my,,0oz4y4wx4k,z2wlx21240,o4lj5jl5nl,noyj200ml0;debug=1"])

                c.setopt(c.URL,‘%s/monitor.html‘%i)

                c.perform()

            for ii in bigapp_list:

                c.setopt(c.HTTPHEADER,["Host: monitorbigapp1.sinaapp.com","Appname: monitorbigapp1","AppVersion:3", "AppHash: 953", "AccessKey: 0y34wm3zlz", "SecretKey:

 0z3mh2jwmz45mjkzkii3iw5zwyylk5mw0x500xzl", "McIP: 1default;1::;1:@default:;;", "MysqlPort: 3307", "AppCookie: aks=4j33x1wm2n,5020k300z0,5m0lw4l3zl,o4550jjym3,o1n5kwmyx

0,3ozlxlo0jy,k40z12j23x,yyl3jxzj3x,kxjyl3llyy,,,,looz04o3my,,0oz4y4wx4k,z2wlx21240,o4lj5jl5nl,noyj200ml0;debug=1"])

                c.setopt(c.URL,‘%s/monitor.html‘%ii)

                c.perform()

            for iii in ent_list:

                c.setopt(c.HTTPHEADER,["Host: monitorent1.sinaapp.com", "Appname: monitorent1", "AppVersion: 3", "AppHash: 156", "AccessKey: 3lyw2wky00", "SecretKey: l1

llk425x3zi0lyzllil00lh1j23z54wz11z4yiw", "McIP: 1default;1::;1:@default:;;", "MysqlPort: 3307", "AppCookie: aks=4j33x1wm2n,5020k300z0,5m0lw4l3zl,o4550jjym3,o1n5kwmyx0,3

ozlxlo0jy,k40z12j23x,yyl3jxzj3x,kxjyl3llyy,,,,looz04o3my,,0oz4y4wx4k,z2wlx21240,o4lj5jl5nl,noyj200ml0;debug=1"])

                c.setopt(c.URL,‘%s/monitor.html‘%iii)

                c.perform()

            time.sleep(5)

    #work_socket()


客户端,客户端监控日志中心,刚才服务端curl过来的日志,是否已经存在,如果不存在得出来

#!/usr/bin/python

import socket

import os

import time

import re




def buffer_line(monitor_log,buffer_log):

        buf = open("/home/yanchao/%s"%buffer_log).read()

        bytes=os.popen(‘wc -c %s‘%monitor_log).read().split(" ")[0]

        if int(bytes) < int(buf):

                return 0

        else:

                return int(re.findall("^\d*", buf)[0])


def set_last_pos(pos,buffer_log):

        open("/home/yanchao/%s"%buffer_log, "w").write(str(pos))



def monitor_work(monitor_log,buffer_log):

        fh=open(monitor_log,‘r‘)

        fh.seek(buffer_line(monitor_log,buffer_log))

        content=fh.read()

        new_total_lines=len(content)+buffer_line(monitor_log,buffer_log)

        set_last_pos(new_total_lines,buffer_log)

        new_lines=content.split("\n")

        return new_lines



if __name__ == ‘__main__‘:

    time.sleep(5)

    com_ip_list={‘common‘:[‘yq48‘,‘yq22‘,‘yq24‘,‘yq25‘],‘bigapp‘:[‘yq27‘,‘yq39‘,‘yq65‘,‘yq66‘],‘ent‘:[‘yq23‘,‘yq42‘,‘yq43‘,‘yq67‘,‘yq68‘,‘yq69‘]}

    com_now_list=[]

    com_hh_list=[]

    now_time=time.strftime(‘%Y-%m-%d‘,time.localtime(time.time()))

    common_log=‘/data1/saelog/‘+now_time+‘/access/604/monitorcommon1-3-access_log‘

    bigapp_log=‘/data1/saelog/‘+now_time+‘/access/953/monitorbigapp1-3-access_log‘

    ent_log=‘/data1/saelog/‘+now_time+‘/access/156/monitorent1-3-access_log‘

    dict_list={‘common‘:common_log,‘bigapp‘:bigapp_log,‘ent‘:ent_log}

    c=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

    c.connect((‘10.67.15.96‘,9999))

    rec=c.recv(1024)

    if rec == ‘10.67.15.96‘:

        for iiii in dict_list.keys():

            lines=monitor_work(dict_list[iiii],iiii)

            for ii in lines:

                if ii:

                  com_hh_list.append(ii)

            print iiii,len(com_hh_list),len(com_ip_list[iiii])

            if len(com_hh_list) < len(com_ip_list[iiii]):

                for i in com_hh_list:

                    com_now_list.append(i.split(" ")[-1])

                print com_now_list

                aa=set(com_ip_list[iiii]) ^ set(com_now_list)

                for iii in list(aa):

                    if iii:

                        print iii

            com_hh_list=[]

            com_now_list=[]


本文出自 “expect批量同步数据” 博客,请务必保留此出处http://4249964.blog.51cto.com/4239964/1557261

rsyslog 客户端监控

标签:服务端   监控   客户端   

原文地址:http://4249964.blog.51cto.com/4239964/1557261

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!