首页 文章 精选 留言 我的

精选列表

搜索[Python],共10000篇文章
优秀的个人博客,低调大师

python监控服务器信息

本文转载自http://www.linuxtone.org/thread-29256-1-1.html 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 #coding:utf-8 #by_wangyi #by:QQ917611 #QQ群:251289157 import psutil import time import os import sys import re stats = [ 0 , 1 ] stoptimes = 2 if len (sys.argv)> 1 : interface = sys.argv[ 1 ] else : interface = 'eth0' class Monitor: def __init__( self ,user_uid,stoptime): self .user_uid = user_uid self .stoptime = stoptime if user_uid = = 0 : print "请使用root用户运行此脚本" exit() def meminfo( self ,used_vm,free_vm,buffers,cached): total = psutil.virtual_memory().total / 1024 / 1024 used = used_vm - (buffers + cached) free = total - used print "totalmem:%sM" % total print "usedmem:%sM" % used print "freemem:%sM" % free def diskinfo( self ): list = [] for i in psutil.disk_partitions(): list .append(i[ 1 ]) for k in range ( len ( list )): total = "%-15s分区\ttotal:%s" % ( list [k],psutil.disk_usage( list [k]).total / 1024 / 1024 / 1024 ) used = "used:%s" % (psutil.disk_usage( list [k]).used / 1024 / 1024 / 1024 ) free = "free:%s" % (psutil.disk_usage( list [k]).free / 1024 / 1024 / 1024 ) print "%sG\t%sG\t%sG" % (total,used,free) def cpuinfo( self ): with open ( '/proc/loadavg' )asf: loadavg = f.read() print "5分钟cpuload:%s" % (loadavg.split()[ 0 ]) print "10分钟cpuload:%s" % (loadavg.split()[ 1 ]) print "15分钟cpuload:%s" % (loadavg.split()[ 2 ]) print "当前运行proc:%s" % (loadavg.split()[ 3 ].split( '/' )[ 0 ]) print "最后运行pid:%s" % (loadavg.split()[ 4 ]) print '当前cpu%s' % (psutil.cpu_percent()) def flowinfo( self ): f = open ( '/proc/net/dev' , 'r' ).readlines() for i in f: if re.search(interface,i): rx = i.split( ':' )[ 1 ].split()[ 0 ] tx = i.split()[ 8 ] stats[ 0 ] = rx stats[ 1 ] = tx used_vm = psutil.virtual_memory().used / 1024 / 1024 free_vm = psutil.virtual_memory().free / 1024 / 1024 buffers = psutil.virtual_memory().buffers / 1024 / 1024 cached = psutil.virtual_memory().cached / 1024 / 1024 if __name__ = = '__main__' : user_uid = os.geteuid() stoptime = 2 task = Monitor(user_uid,stoptime) print "servermeminfo:\n" task.meminfo(used_vm,free_vm,buffers,cached) print "==================================" print "serverdiskinfo:\n" task.diskinfo() print "===================================" print "servercpuinfo:\n" task.cpuinfo() print "===================================" print "serverflowinfo:\n" task.flowinfo() RX_one = float (stats[ 0 ]) TX_one = float (stats[ 1 ]) time.sleep(stoptimes) task.flowinfo() RX_two = float (stats[ 0 ]) TX_two = float (stats[ 1 ]) RX_rate = round ( float (RX_two - RX_one) / 1024 , 2 ) TX_rate = round ( float (TX_two - TX_one) / 1024 , 2 ) print time.strftime( "%Y-%m-%d%H:%M:%S" ), 'RXbytes=' ,RX_rate, 'KB' print time.strftime( "%Y-%m-%d%H:%M:%S" ), 'TXbytes=' ,TX_rate, 'KB'

优秀的个人博客,低调大师

[Spark][Python]RDD flatMap 操作例子

RDD flatMap 操作例子: flatMap,对原RDD的每个元素(行)执行函数操作,然后把每行都“拍扁” [training@localhost ~]$ hdfs dfs -put cats.txt [training@localhost ~]$ hdfs dfa -cat cats.txt Error: Could not find or load main class dfa [training@localhost ~]$ hdfs dfs -cat cats.txt The cat on the mat The aardvark sat on the sofa mydata=sc.textFile("cats.txt") mydata.count() Out[14]: 2 mydata.take(2) Out[15]: [u'The cat on the mat', u'The aardvark sat on the sofa'] myflatdata=mydata.flatMap(lambda line: line.split(' ')) myflatdta.count() Out[19]: 11 myflatdata.take(2) Out[20]: [u'The', u'cat'] myflatdata.take(11) Out[21]: [u'The', u'cat', u'on', u'the', u'mat', u'The', u'aardvark', u'sat', u'on', u'the', u'sofa'] 本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/7593885.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

[Spark][Python]Spark Join 小例子

[training@localhost ~]$ hdfs dfs -cat people.json {"name":"Alice","pcode":"94304"} {"name":"Brayden","age":30,"pcode":"94304"} {"name":"Carla","age":19,"pcoe":"10036"} {"name":"Diana","age":46} {"name":"Etienne","pcode":"94104"} [training@localhost ~]$ hdfs dfs -cat pcodes.json {"pcode":"10036","city":"New York","state":"NY"} {"pcode:"87501","city":"Santa Fe","state":"NM"} {"pcode":"94304","city":"Palo Alto","state":"CA"} {"pcode":"94104","city":"San Francisco","state":"CA"} sqlContext = HiveContext(sc) peopleDF = sqlContext.read.json("people.json") sqlContext = HiveContext(sc) pcodesDF = sqlContext.read.json("pcodes.json") mydf001=peopleDF.join(pcodesDF,"pcode") mydf001.limit(5).show() +-----+----+-------+----+---------------+-------------+-----+ |pcode| age| name|pcoe|_corrupt_record| city|state| +-----+----+-------+----+---------------+-------------+-----+ |94304|null| Alice|null| null| Palo Alto| CA| |94304| 30|Brayden|null| null| Palo Alto| CA| |94104|null|Etienne|null| null|San Francisco| CA| +-----+----+-------+----+---------------+-------------+-----+ 本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/7630003.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

python 多用户发邮件

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 #!/usr/bin/envpython #-*-coding:utf-8-*- #导入smtplib和MIMEText import smtplib from email.header import Header from email.mime.text import MIMEText def send_server(to_list,sub,content): #设置服务器,用户名、口令以及邮箱的后缀 mail_host = "smtp.163.com" mail_user = "w67300444@163.com" mail_pass = "1234556" mail_postfix = "163.com" me = mail_user + "<" + mail_user + "@" + mail_postfix + ">" msg = MIMEText(content) msg[ 'Subject' ] = sub #msg['From']=me msg[ 'From' ] = '%s<%s>' % (Header( '运维团队' , 'utf-8' ), 'w67300444@163.com' ) msg[ 'To' ] = to_list try : s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pass) s.sendmail(me,to_list,msg.as_string()) s.close() #print'1' return True except Exception,e: #print'2' print str (e) return False def send_to(): #发到用户的列表 mail_list = [ "buser.com" , "cuser.com" ] for i in range ( 0 , len (mail_list)): if send_server(mail_list[i], "ECS启动汇总" , "ECS启动完毕" ): print "发送成功" i = i + 1 ; else : print "发送失败" i = i + 1 ; if __name__ = = '__main__' : send_to() 本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/2068667,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册