Monitoring Server Status
Get System Performance Information
1, CPU information:
The Linux operating system uses several parts of the CPU:
User time; SystemTime; Wait Io;idle
Psutil.cpu_times ()
Psutil.cpu_times (). User
Psutil.cpu_count ()
2 , Memory information
psutil.virtual_memory () # View memory Full information
psutil.swap_memory () # View Swap Partition Information
3 , disk information
psutil.disk_io_counters () # get the hard drive IO Total
psutil.disk_usage ('/') # get the usage of a partition
psutil.disk_io_counters (perdisk=true) # gets a single partition of the IO number
4 , Network information
Psutil.net_io_counters # View the total network IO number
5 , other information
psutil.users () # View currently working with users
psutil.boot_time () # View current boot time
Datetime.datetime.fromtimestamp (Psutil.boot_time ()). Strftime ("%y-%m-%d%h:%m:%s") # Use datetime module Format time stamp
System Process Management methods:
1. Process Information
p = psutil. Process ID # instantiates a process object,
p.name () # Process Name
P.exe () # Process bin Path
p.cwd () # absolute path to the process directory
p.status () # process Status
p.create_time () # Process creation Time
p.uids () # Process UID Information
p.gids () # Process GID Information
2 , address processing module IPy
through version () method distinguishes IP address is IP4 or IP6 type
Example: IP (' 8.8.8.8 '). Version ()
outputs all of the network segments IP Address:
Ip=ip (' 192.168.118.0/24 ')
For x in IP:
Print (x)
customizing network segments for different output types , Output Type is string
Ip=ip (' 192.168.118.0/24 ')
ip.strnormal (0) no return, as 192.168.118.0
ip.strnormal (1) Prefix format, such as 192.168.118.0/24 ;
Ip.strnormal (2), Decimalnetmaskt format, such as 192.168.118.0/255.255.255.0
Ip.strnormal (3), Lastip format, such as 192.168.1.0-192.168.118.255
Network Information detection method:
judging the input IP or subnet back to network, mask, broadcast, ECHO resolution, number of subnets, and IP types and other information
#!/bin/env python From IPy import IP Ips=input (' Please input IP address\n ') Ip=ip (IPS) if (Ip.len () >1): Print (' Net:%s '% ip.net ()); Print (' netmask:%s '% ip.netmask ()) Print (' Broadcast:%s '% ip.broadcast ()) Print (' Reverse address%s '% ip.reversenames () [0]) Print (' Subnet:%s '% Ip.len ()) Else Print (' Reverse address%s '% ip.reversenames ()); Print (' heaxdemical:%s '% Ip.strhex ()); Print (' Binary IP:%s '% ip.strbin ()); Print (' Iptype:%s '% ip.iptype ()); |
Dnspython module resolution domain name
A Record
#!/usr/bin/env python From DNS import resolver domain=input (' Please input your domain name:\n ') # Please enter the domain name address a=resolver.query (domain, ' A ') # Specifies the type of A Record For I in A.response.answer: For J in I.items: Print (j.address) |
MX Record
#!/usr/bin/env python from dns Import Resolver domain = input (' Please input domain name: ') MX = resolver.query (domain, ' MX ') for i in MX: print (' MX preference: ', i.preference, ' Mail exchange: ', I.exchange) |
NS Record
#!/usr/bin/env python From DNS import resolver Domain = input (' pelase input you domain name: ') NS = resolver.query (domain, ' NS ') For I in NS.response.answer: For J in I.items: Print (J.to_text ()) |
CNAME Record
#!/usr/bin/env python From DNS import resolver Domain = input (' pelase input you domain name: ') NS = resolver.query (domain, ' NS ') For I in NS.response.answer: For J in I.items: Print (J.to_text ()) |
This article is from "Linux system Operations" blog, please make sure to keep this source http://mbb97.blog.51cto.com/13129388/1983859
1. Python Script-Monitor server status