首页 文章 精选 留言 我的

精选列表

搜索[数据库监控],共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'

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

搭建cadvisor + influxdb + grafana 监控系统

启动influxdb 1 2 dockerrun-d--net=host-ePRE_CREATE_DB=cadvisor--nameinfluxsrvtutum/ influxdb:0.8.8 启动cadvisor 1 2 3 4 5 6 7 8 9 10 dockerrun\ --volume=/: /rootfs :ro\ --volume= /var/run : /var/run :rw\ --volume= /sys : /sys :ro\ --volume= /var/lib/docker/ : /var/lib/docker :ro\ --publish=8080:8080\ --detach= true \ --name=cadvisor\ -eRUN_OPTS= "-storage_driver=influxdb-storage_driver_host=hostip:8086" \ logbase /cadvisor-influxdb 异常: 一开始 在 influxdb 执行 list series 无数据, 知道cadvisor没有往db 传 /usr/bin/cadvisor --logtostderr --v=2 查看详细日志,一般是网络问题,官方镜像一直有问题,无法读取网络状态,所以更换镜像 启动grafana 1 2 3 4 5 6 7 8 9 10 dockerrun-d--net=host\ -eHTTP_USER=admin\ -eHTTP_PASS=admin\ -eINFLUXDB_HOST=localhost\ -eINFLUXDB_PORT=8086\ -eINFLUXDB_NAME=cadvisor\ -eINFLUXDB_USER=root\ -eINFLUXDB_PASS=root\ --namegrafanagrafana/ grafana:2.0.2 本文转自银狐博客51CTO博客,原文链接http://blog.51cto.com/foxhound/1774410如需转载请自行联系原作者 战狐

资源下载

更多资源
Mario

Mario

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

Spring

Spring

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

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册