ch01
- 格式:ppt
- 大小:2.58 MB
- 文档页数:49
ch01系统基础信息模块详解第1章系统基础信息模块详解1.1 系统性能信息模块 psutil解决VMWare在Windows10的安装问题: 安装VC Redistributable 2017解决虚拟机的上⽹问题:修改VMWare 的⽹络设置解决PuTTY连接不上虚拟机的问题:修改VMnet8的IPv4地址在Centos7安装pip在Centos7安装psutil模块#1、以root⾝份登陆CentOS依次执⾏以下命令:wget https:///packages/source/p/psutil/psutil-2.1.3.tar.gz --no-check-certificatetar zxvf psutil-2.1.3.tar.gzcd psutil-2.1.3/python setup.py install#2、在执⾏以上命令最后的安装命令时,遇到以下问题psutil/_psutil_linux.c:12:20: fatal error: Python.h: No such file or directory这样的错误提⽰,表⽰缺少Python-dev的依赖环境,直接安装Python-devel即可yum -y install python-devel*安装完后,再执⾏ python setup.py install 即可安装完成提⽰:Installed /usr/lib64/python2.7/site-packages/psutil-2.1.3-py2.7-linux-x86_64.eggProcessing dependencies for psutil==2.1.3Finished processing dependencies for psutil==2.1.31.1.1 获取系统性能信息(1) CPU信息>>> import psutil/usr/lib64/python2.7/site-packages/psutil-2.1.3-py2.7-linux-x86_64.egg/_psutil_linux.py:3: UserWarning: Module _psutil_linux was already imported from /usr/lib64/python2.7/site-packages/psutil-2.1.3-py2.7-linux-x86_64.egg/_psutil_linux.pyc, but >>> psutil.cpu_times()scputimes(user=46.0, nice=0.27, system=87.6, idle=10040.74, iowait=52.76, irq=0.0, softirq=9.79, steal=0.0, guest=0.0, guest_nice=0.0)>>> psutil.cpu_times().user46.03>>> psutil.cpu_count()2>>> psutil.cpu_count(logical=False)2>>>(2)内存信息>>> mem = psutil.virtual_memory()>>> memsvmem(total=1907970048L, available=1505476608L, percent=21.1, used=915431424L, free=992538624L, active=423669760, inactive=202493952, buffers=2134016L, cached=510803968)>>> mem.total1907970048L>>> mem.free992538624L>>> psutil.swap_memory()sswap(total=2147479552L, used=0L, free=2147479552L, percent=0.0, sin=0, sout=0)>>>(3)磁盘信息>>> psutil.disk_partitions()[sdiskpart(device='/dev/sda3', mountpoint='/', fstype='xfs', opts='rw,seclabel,relatime,attr2,inode64,noquota'), sdiskpart(device='/dev/sda1', mountpoint='/boot', fstype='xfs', opts='rw,seclabel,relatime,attr2,inode64,noquota')]>>> psutil.disk_usage('/')sdiskusage(total=19001245696, used=4522000384, free=14479245312, percent=23.8)>>> psutil.disk_io_counters()sdiskio(read_count=14186, write_count=8265, read_bytes=432613888, write_bytes=230467072, read_time=225143, write_time=59109)>>> psutil.disk_io_counters(perdisk=True){'sr0': sdiskio(read_count=18, write_count=0, read_bytes=1052672, write_bytes=0, read_time=761, write_time=0), 'sda2': sdiskio(read_count=54, write_count=0, read_bytes=2527232, write_bytes=0, read_time=335, write_time=0), 'sda3': sdiskio(r >>>(4)⽹络信息>>> _io_counters()snetio(bytes_sent=1227849, bytes_recv=34910887, packets_sent=12412, packets_recv=29882, errin=0, errout=0, dropin=0, dropout=0)>>> _io_counters(pernic=True){'lo': snetio(bytes_sent=14274, bytes_recv=14274, packets_sent=144, packets_recv=144, errin=0, errout=0, dropin=0, dropout=0), 'ens33': snetio(bytes_sent=1216087, bytes_recv=34904091, packets_sent=12290, packets_recv=29824, errin=0, >>>(5)其他系统信息>>> ers()[suser(name='root', terminal='tty1', host='', started=1597921920.0), suser(name='root', terminal='pts/0', host='192.168.135.1', started=1597933824.0), suser(name='chenjo', terminal='pts/1', host='192.168.135.1', started=1597923712.0)]>>> import datetime>>> psutil.boot_time()1597925932.0>>> datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S")'2020-08-20 20:18:52'>>>1.1.2 系统进程管理⽅法(1)进程信息>>> import psutil>>> psutil.pids()[1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 36, 37, 38, 39, 47, 48, 49, 50, 51, 53, 66, 97, 638, 649, 655, 664, 666, 805, 810, 1678, 1683, 1824, 1828, 2876, 2877, 2887, 2890, 2893, 2894, 2895, 2896, >>> p = psutil.Process(17557)>>> <bound method of <psutil.Process(pid=17557, name='python') at 139991911690768>>>>> p.exe()'/usr/bin/python2.7;5f3e6c2d'>>> p.cwd()'/tmp'>>> p.status()'stopped'>>> p.create_time()1597928634.08>>> p.uids()puids(real=0, effective=0, saved=0)>>> p.gids()pgids(real=0, effective=0, saved=0)>>> p.cpu_times()pcputimes(user=0.01, system=0.0)>>> p.cpu_affinity()[0, 1]>>> p.memory_percent()0.27350031021032045>>> p.memory_info()pmem(rss=5218304, vms=133287936)>>> p.io_counters()pio(read_count=118, write_count=9, read_bytes=0, write_bytes=0)>>> p.connections()[]>>> p.num_threads()1>>>(2)popen类的使⽤import psutilfrom subprocess import PIPEp = psutil.Popen(["/usr/bin/python", "-c", "print('hello')"], stdout=PIPE)()ername()p.cpu_times()municate()#p.cpu_times()[root@ansible mycode]# pythonPython 2.7.5 (default, Apr 2 2020, 13:16:51)[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import psutil>>> from subprocess import PIPE>>> p = psutil.Popen(["/usr/bin/python", "-c", "print('hello')"], stdout=PIPE)>>> ()'python'>>> ername()'root'>>> p.cpu_times()pcputimes(user=0.01, system=0.0)>>> municate()('hello\n', None)>>>参考提⽰1.1.1节⽰例参考https:///giampaolo/psutil1.1.1节模块说明参考官⽹/en/latest1.2 实⽤的IP地址处理模块IPyCentos7上安装ipy>>> from IPy import IP>>> IP('10.0.0.0/8').version()4>>> IP('::1').version()6>>>>>> ip = IP('192.168.0.0/16')>>> print ip.len()65536>>> for x in ip:... print(x)...192.168.0.0192.168.0.1192.168.0.2192.168.0.3...>>> print(IP('192.168.1.0').make_net('255.255.255.0'))192.168.1.0/24>>> print(IP('192.168.1.0/255.255.255.0', make_net=True))192.168.1.0/24>>> print(IP('192.168.1.0-192.168.1.255', make_net=True))192.168.1.0/24>>>wantprefixlen 的取值及含义:wantprefixlen = 0,⽆返回,如192.168.1.0。
引例沃尔玛借助管理信息系统登上世界企业500强之首在美国《财富》杂志评选的2001年美国企业500强中,零售业巨人沃尔玛连锁店将埃克森·美孚石油公司拉下马来,以2 198.12亿美元的营业收入总额坐上了美国乃至世界企业的龙头宝座。
而沃尔玛的主席罗伯逊·沃尔玛超过微软公司董事长比尔·盖茨成为全球首富。
沃尔玛在全球拥有4 600多家连锁店,雇员120多万人。
如此庞大的队伍,确实可称得上企业帝国。
这个企业帝国的成功秘诀是其管理信息系统。
沃尔玛的全球采购战略、配送系统、商品管理、电子数据系统、天天平价战略在业界都是经典。
其成功建立在利用信息技术整合优势资源、信息技术战略与零售业整合的基础之上。
沃尔玛在全球的4 600多家连锁店通过它的网络可在1小时之内对每种商品的库存、上架、销售量全部盘点一遍。
公司的创始人山姆·沃尔玛特别重视信息的沟通和信息系统的建设。
在20世纪60年代中期,他只拥有几家商店时,就已经认识到管理人员必须能够随时随地获得所需要的数据。
某种商品在沃尔玛的商店里一共有多少?订购了多少商品?上周的销售量、订购量呢?昨天呢?去年呢?订购的商品什么时候可以到达?在管理信息系统应用之前,必须通过大量的人工计算与处理才能得到。
要在现有的基础上扩大经营规模,只有不断应用先进的管理信息系统。
在管理信息系统的支持下,沃尔玛能够以最优质的服务、最低的成本、最快速的反应进行全球运作。
1974年,公司开始在其分销中心和各家连锁店运用计算机进行库存控制管理。
1983年,沃尔玛用上条码扫描系统。
1984年,沃尔玛开发了一套市场营销管理软件系统,这可以使每家连锁店按照自身的市场环境和销售类型制定出相应的营销产品组合。
在1985—1987年,沃尔玛安装了公司专用的卫星通信系统,使总部、分销中心和各连锁店之间可以实现双向的声音和数据传输,全球各家分店也都能够通过自己的终端与总部进行实时的通信联系。