使用python + shell 编写,是一个简易solaris系统巡检程序
#!/usr/bin/python -u
#-*- coding:utf-8 -*-
'''
程序:solaris_status.py
author: gyh9711
功能:
系统状态信息获取
语言:
sh + python
注意:
部分调用命令需要用到root权限
测试情况:
系统版本:solaris10 系统测试ok
测试服务器型号:sun 6900 6800 v445 v440 M3000 M5000
内容:
'''
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()]
#通过系统状态信息:
#系统基本情况
puts("="*60)
puts("检查时间 %s" % getNow())
puts("-"*60)
puts("\n系统基本信息")
for i in getCommand("showrev"):
puts(i)
puts("="*60)
puts("\n")
puts("主机名称: %s " % getCommand("hostname")[0])
puts("处理器core数: %s " % getCommand("mpstat |awk 'END{print NR-1}'")[0])
puts("系统负载情况: %s " % getCommand("uptime")[0])
puts("系统进程数: %s " % getCommand("ps -ef |wc -l")[0])
puts("用户运行进程情况")
psAll = getCommand('''ps -ef |awk '{print $1}' |sort |uniq -c |grep -v "UID"''')
puts("\n%s%s" %("用户".ljust(20),"进程数".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,"状态信息","="*30))
puts("\n")
puts("处理器使用情况: %s %%" % getCommand("vmstat 1 2 |tail -1 |awk '{print 100-$22}'")[0])
puts("内存使用情况: %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,"磁盘空间使用情况","="*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,"网络情况","="*30))
puts("网络接口状态")
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网络接口IP及数据进出情况")
for i in getCommand("netstat -in"):
puts(i)
puts("\n网络接口流量情况")
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'''):
puts(i)
puts("\n 网络ARP缓存信息")
for i in getCommand("netstat -anp"):
puts(i)
puts("\n")
puts("\n 路由表情况")
for i in getCommand("netstat -rn"):
puts(i)
puts("\n")
puts("\n%s%s%s\n"%("="*30,"系统主要服务及状态[svcs]","="*30))
for i in getCommand('''svcs'''):
puts(i)
puts("\n%s%s%s\n"%("="*30,"服务硬件状态[prtdiag]","="*30))
for i in getCommand('''prtdiag -v'''):
puts(i)
# puts(getCommand("showrev"))
#硬件状态信息
#puts(getCommand("prtdiag -v"))
#cpu情况
#puts(getCommand("mpstat"))
#puts(getCommand("sar -u"))
#物理内存大小
#puts(getCommand('''/usr/sbin/prtdiag -v |grep "^Memory"'''))
#虚拟内存
#puts(getCommand('''vmstat 1 2'''))
#puts(getCommand('''swap -s'''))
#=================磁盘IO情况=================
#puts(getCommand('''iostat -xtc''')) #

This tutorial demonstrates how to use Python to process the statistical concept of Zipf's law and demonstrates the efficiency of Python's reading and sorting large text files when processing the law. You may be wondering what the term Zipf distribution means. To understand this term, we first need to define Zipf's law. Don't worry, I'll try to simplify the instructions. Zipf's Law Zipf's law simply means: in a large natural language corpus, the most frequently occurring words appear about twice as frequently as the second frequent words, three times as the third frequent words, four times as the fourth frequent words, and so on. Let's look at an example. If you look at the Brown corpus in American English, you will notice that the most frequent word is "th

Dealing with noisy images is a common problem, especially with mobile phone or low-resolution camera photos. This tutorial explores image filtering techniques in Python using OpenCV to tackle this issue. Image Filtering: A Powerful Tool Image filter

This article explains how to use Beautiful Soup, a Python library, to parse HTML. It details common methods like find(), find_all(), select(), and get_text() for data extraction, handling of diverse HTML structures and errors, and alternatives (Sel

This article compares TensorFlow and PyTorch for deep learning. It details the steps involved: data preparation, model building, training, evaluation, and deployment. Key differences between the frameworks, particularly regarding computational grap

Python, a favorite for data science and processing, offers a rich ecosystem for high-performance computing. However, parallel programming in Python presents unique challenges. This tutorial explores these challenges, focusing on the Global Interprete

This tutorial demonstrates creating a custom pipeline data structure in Python 3, leveraging classes and operator overloading for enhanced functionality. The pipeline's flexibility lies in its ability to apply a series of functions to a data set, ge

Serialization and deserialization of Python objects are key aspects of any non-trivial program. If you save something to a Python file, you do object serialization and deserialization if you read the configuration file, or if you respond to an HTTP request. In a sense, serialization and deserialization are the most boring things in the world. Who cares about all these formats and protocols? You want to persist or stream some Python objects and retrieve them in full at a later time. This is a great way to see the world on a conceptual level. However, on a practical level, the serialization scheme, format or protocol you choose may determine the speed, security, freedom of maintenance status, and other aspects of the program

Python's statistics module provides powerful data statistical analysis capabilities to help us quickly understand the overall characteristics of data, such as biostatistics and business analysis. Instead of looking at data points one by one, just look at statistics such as mean or variance to discover trends and features in the original data that may be ignored, and compare large datasets more easily and effectively. This tutorial will explain how to calculate the mean and measure the degree of dispersion of the dataset. Unless otherwise stated, all functions in this module support the calculation of the mean() function instead of simply summing the average. Floating point numbers can also be used. import random import statistics from fracti


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
