国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

python實(shí)現(xiàn)巡檢系統(tǒng)(solaris)示例

2020-02-23 05:16:21
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

使用python + shell 編寫(xiě),是一個(gè)簡(jiǎn)易solaris系統(tǒng)巡檢程序

代碼如下:
#!/usr/bin/python -u
#-*- coding:utf-8 -*-
'''
程序:solaris_status.py
author: gyh9711
功能:
 系統(tǒng)狀態(tài)信息獲取

語(yǔ)言: 
 sh + python

注意:
 部分調(diào)用命令需要用到root權(quán)限

測(cè)試情況:
 系統(tǒng)版本:solaris10 系統(tǒng)測(cè)試ok 
 測(cè)試服務(wù)器型號(hào):sun 6900 6800 v445 v440 M3000 M5000
內(nèi)容:

'''
import time
import sys
import os
import re
# import pprint

def getNow():
 return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())

def puts(mess,_type="print"):

 if _type == "log":
  sys.stdout.write("[%s] %s/n" % (getNow(),mess))
 else:
  sys.stdout.write("%s/n" % mess)
 #pprint.pprint(mess)

def getCommand(cmd):
 return [t.rstrip() for t in os.popen(cmd).readlines()]

#通過(guò)系統(tǒng)狀態(tài)信息:

#系統(tǒng)基本情況
puts("="*60)
puts("檢查時(shí)間 %s" % getNow())
puts("-"*60)
puts("/n系統(tǒng)基本信息")
for i in getCommand("showrev"):
 puts(i)
puts("="*60)
puts("/n")
puts("主機(jī)名稱: %s " % getCommand("hostname")[0])
puts("處理器core數(shù): %s " % getCommand("mpstat |awk 'END{print NR-1}'")[0])
puts("系統(tǒng)負(fù)載情況: %s " % getCommand("uptime")[0])
puts("系統(tǒng)進(jìn)程數(shù): %s " % getCommand("ps -ef |wc -l")[0])
puts("用戶運(yùn)行進(jìn)程情況")
psAll = getCommand('''ps -ef  |awk '{print $1}' |sort |uniq -c |grep -v "UID"''')
puts("/n%s%s" %("用戶".ljust(20),"進(jìn)程數(shù)".ljust(10)))
puts("-"*60)
for i in psAll:
 _user = re.split(r"/s+",i)[1:]
 #print _user
 puts("%s%s" %(_user[1].ljust(20),_user[0].ljust(10)))
puts("-"*60)

puts("/n")
puts("%s%s%s"%("="*30,"狀態(tài)信息","="*30))
puts("/n")
puts("處理器使用情況: %s %%" % getCommand("vmstat 1 2 |tail -1 |awk '{print 100-$22}'")[0])
puts("內(nèi)存使用情況: %s %% 總大小:%s [M]" % (getCommand('''vmstat 1 2 |tail -1 |awk '{printf("%d",$5/1024/MEMALL*100);}' MEMALL=`prtconf |grep -i "^memory" |awk '{print $3}'`''')[0],getCommand('''prtconf |grep -i "^memory" |awk '{print $3}''')[0]))
puts("swap使用情況: %s" % (getCommand("swap -s")[0]))
puts("/n")
puts("%s%s%s/n"%("="*30,"磁盤(pán)空間使用情況","="*30))

for i in getCommand('''awk '{if($3 != "") {print $3}}' /etc/vfstab |egrep -v "mount|to|-" |xargs df -h'''):
 puts(i)
puts("/n%s%s%s/n"%("="*30,"網(wǎng)絡(luò)情況","="*30))


puts("網(wǎng)絡(luò)接口狀態(tài)")
for i in getCommand('''for i in `ifconfig -a |egrep "^{hme|qfe|ge|ce|eri|bge|nge|e1000g}" |cut -d: -f1`; do /sbin/dladm show-dev $i; done'''):
 puts(i)
puts("/n網(wǎng)絡(luò)接口IP及數(shù)據(jù)進(jìn)出情況")
for i in getCommand("netstat -in"):
 puts(i)

puts("/n網(wǎng)絡(luò)接口流量情況")
for i in getCommand('''for i in `ifconfig -a |egrep "^{hme|qfe|ge|ce|eri|bge|nge|e1000g}" |cut -d: -f1`; do netstat -I $i; done'''):

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 鸡泽县| 漯河市| 汉川市| 依安县| 延吉市| 巴青县| 霍州市| 义马市| 淮南市| 平江县| 梁山县| 炉霍县| 邵东县| 麻城市| 古浪县| 靖西县| 运城市| 磐石市| 康马县| 乐清市| 武功县| 运城市| 咸丰县| 慈利县| 连州市| 台山市| 绵竹市| 武胜县| 婺源县| 瑞昌市| 乌拉特中旗| 香河县| 朔州市| 平泉县| 江津市| 怀仁县| 吉木乃县| 尤溪县| 阳西县| 千阳县| 澄迈县|