The following articles are recorded by myself

Source: Internet
Author: User

Java platform port monitoring obtains a list of all user port IP addresses of the Java platform from the database every early morning. This list is transmitted to the rsync server. The Java platform server downloads this file from the rsync server.


#! /Usr/bin/Python

Import mysqldb

Import OS


Def mysql_work (IP, port, javaip ):

Print javaip

Conn = mysqldb. connect (host = STR (IP), user = *** ', passwd = ***', Port = int (port), DB = '***')

Cur = conn. cursor (cursorclass = mysqldb. cursors. dictcursor)

Cur.exe cute ("select appname, IP, port from app2ws where status = 'up ';")

Result = cur. fetchall ()

Return result


Def rsync_work (IP, PWD ):

OS. popen ('rsync-avzp/etc/SAE/jvm_port.txt % s: % s' % (IP, PWD ))



If _ name _ = '_ main __':

IP = '****'

Port = ****

B = OS. popen ('ifconfig eth1 '). read (). split ('\ n') [1]. split ('') [11]. split (':') [1]

A = mysql_work (IP, port, B)

C = open ('/etc/SAE/jvm_port.txt', 'w ')

C. truncate ()

For I in:

D = ''. join (['% s: % s,' % (K, I [k]) for K in ['IP', 'Port', 'appname'])

Converts a dictionary to a string.

C. writelines (D + '\ n ')

C. Close ()

Rsync_ip = '10. 75.7.239'

Pwd = 'sa'

Rsync_work (rsync_ip, PWD)


Java platform server script


#! /Usr/bin/Python

Import OS

Import re

Import pycurl

Import cstringio

Import urllib


Def curl_tyt (IP, Port ):

Buf = cstringio. stringio ()

Cc = pycurl. Curl ()

Cc. setopt (CC. url, 'HTTP: // % s' % IP)

Cc. setopt (CC. writefunction, Buf. Write)

Cc. setopt (CC. connecttimeout, 5)

Cc. setopt (CC. Timeout, 8)

Cc. setopt (CC. Proxy, 'HTTP: // % s: % s' % (IP, Port ))

Cc. Perform ()


Def monitor_work_1 (content ):

Dict_1 = {'service': 'javaruntime _ monitor', 'checkpoint': 'javaruntime _ monitor_log ', 'title': content, 'content': content, 'cluster ': 'public', 'grad': '2 '}

Params = urllib. urlencode (dict_1)

Urllib. urlopen ('HTTP: // ************ ', Params)



Def rsync_work (IP, PWD ):

OS. popen ('rsync-avzp % s: % S/jvm_port.txt/etc/SAE/'% (IP, PWD ))



Def buffer_line ():

Buf = open ("/etc/SAE/buffer.txt"). Read ()

Bytes = OS. popen ('wc-C/usr/local/SAE/jkdaemon/log/jkdaemon. log'). Read (). Split ("") [0]

If int (bytes) <int (BUF ):

Return 0

Else:

Return int (Re. findall ("^ \ D *", Buf) [0])


Def set_last_pos (POS ):

Open ("/etc/SAE/buffer.txt", "W"). Write (STR (POS ))



Def monitor_work ():

FH = open ('/usr/local/SAE/jkdaemon/log/jkdaemon. log', 'R ')

FH. Seek (buffer_line ())

Content = FH. Read ()

New_total_lines = Len (content) + buffer_line ()

Set_last_pos (new_total_lines)

New_lines = content. Split ("\ n ")

Return new_lines




If _ name _ = '_ main __':

B = OS. popen ('ifconfig eth1 '). read (). split ('\ n') [1]. split ('') [11]. split (':') [1]

IP = '****'

Pwd = '****'

Rsync_work (IP, PWD)

A = open ('/etc/SAE/jvm_port.txt', 'R'). readlines ()

Add_jkdaemon_log = monitor_work ()

For I in:

II = I. Split (',')

If B = II [0]. Split (':') [1]:

Port = II [1]. Split (':') [1]

Try:

Print '++'

Curl_tyt (B, Port)

Failed t pycurl. error, E:

Print 'error', Port

Appname = II [2]. Split (':') [1]

For KK in add_jkdaemon_log:

If KK. Find (port)> = 0:

If KK. Find ('start')> = 0:

If KK:

Monitor_work_1 ('javaruntime _ appname _ '+ appname +' _ IP _ '+ B +' _ port _ '+ port + 'drop ')



This article is from the "batch CT Batch Data Synchronization" blog and will not be reproduced!

The following articles are recorded by myself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.