Welcome, guest | Sign In | My Account | Store | Cart

This code snippet shows how to kich off a performance data gathering shell script with telnetlib and download the data back to a local workstation with ftplib.

Python, 44 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#automate a log grabber script with telnetlib and ftplib
# LOG_GRABBER is a shell script which will grab the logs from the production logs. 
# It may invoke other shell script, perl, shell, python etc to get its job done.
# A generic example: getAccountBalance, 500 
# this means getAccountBalance function takes about 500 ms to finish. 
# its end result is saved in LOG_OUT in any format you may import later for analysis.  

import telnetlib
from ftplib import FTP

# full path to them
LOG_GRABBER='/users/perfmon/grabLogs.sh'
LOG_OUT='logstats.txt'

prdLogBox='142.178.1.3'
uid = 'uid'
pwd = 'yourpassword'

# kick off the log grabber via telnet

tn = telnetlib.Telnet(prdLogBox)

tn.read_until("login: ")
tn.write(uid + "\n")

tn.read_until("Password:")
tn.write(pwd + "\n")

tn.write(LOG_GRABBER+"\n")

tn.write("exit\n")

tn.close()


# download the timing statistics to local via FTP 

ftp=FTP(prdLogBox)
ftp.login(uid,pwd)
#ftp.set_debuglevel(2)
logOut=open(LOG_OUT,'wb+')
ftp.retrbinary('RETR '+LOG_OUT, logOut.write)
ftp.quit()
logOut.close()

This recipe is used for performance monitoring in real procution environment. It is non-intrusive as the timing log (LOG4J actually) has been produced daily and copy to a differnt server during the non-rush hour.

Gather timing statistics in log daily from a production environment during the non rush hour, then download the results, put the results into a RDBMS, calculate the statistics such as min,max,avg,median, deviation.