The server sends a command to the client, telling the client that the curl is complete and the client is the rsyslog server.
#! /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 scope (100 ):
For I in common_list:
C. setopt (C. httpheader, ["Host: Taobao", "appname: monitorcommon1", "appversion: 3", "apphash: 604", "accesskey: 2ynwm3xxlm", "secretkey: lwz24z
Success "," mcip: 1 default; 1 ::; 1 :@ default :;; "," mysqlport: 3307 "," appcookie: AKs = 4j33x1wm2n, 5020k300z0, 5m0lw4l3zl, o4550jjym3, o1n5kwmyx0, 3ozlxlo0
JY, k40z12j23x, yyl3jxzj3x, kxjyl3llyy, looz04o3my, 0oz4y4wx4k, z2wlx21240, large, 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", "access key: 0y34wm3zlz", "secretkey:
Success "," mcip: 1 default; 1 ::; 1 :@ default :;; "," mysqlport: 3307 "," appcookie: AKs = 4j33x1wm2n, 5020k300z0, 5m0lw4l3zl, o4550jjym3, o1n5kwmyx
0, 3ozlxlo0jy, k40z12j23x, yyl3jxzj3x, kxjyl3llyy, looz04o3my, Zhejiang, z2wlx21240, Zhejiang, 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
Success "," mcip: 1 default; 1 ::; 1 :@ default :;; "," mysqlport: 3307 "," appcookie: AKs = 4j33x1wm2n, 5020k300z0, 5m0lw4l3zl, o4550jjym3, o1n5kwmyx0, 3
Ozlxlo0jy, k40z12j23x, yyl3jxzj3x, kxjyl3llyy, looz04o3my, Zhejiang, z2wlx21240, Zhejiang, noyj200ml0; DEBUG = 1 "])
C. setopt (C. url, '% S/monitor.html' % III)
C. Perform ()
Time. Sleep (5)
# Work_socket ()
The client monitors the log center. Check whether the logs from the server curl already exist. If they do not exist
#! /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 = []
This article is from the "batch CT Batch Data Synchronization" blog, please be sure to keep this source http://4249964.blog.51cto.com/4239964/1557261
Rsyslog client monitoring