欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

一次公司需求記錄,python處理sysstat收集的sa性能數(shù)據(jù)

鑒于每個月需要把公司上千臺的服務的cpu使用利率,CPU負載,內存使用率、網(wǎng)絡流量等數(shù)據(jù)取出,以前是手動通過zabbix的平臺去獲取,每次都需要花費1-2小時才能完成這個需求,太耗時,因此優(yōu)化為systat軟件采集數(shù)據(jù),然后通過python腳本處理/var/log/sa下采集到數(shù)據(jù),然后入庫到MySQL數(shù)據(jù)庫中,以后每次取數(shù)據(jù),只需要一行sql代碼就能獲取到數(shù)據(jù),方便快捷,本文把采集數(shù)據(jù)的腳本截圖,如下所示:
一次公司需求記錄,python處理sysstat收集的sa性能數(shù)據(jù)
一次公司需求記錄,python處理sysstat收集的sa性能數(shù)據(jù)
一次公司需求記錄,python處理sysstat收集的sa性能數(shù)據(jù)
一次公司需求記錄,python處理sysstat收集的sa性能數(shù)據(jù)
一次公司需求記錄,python處理sysstat收集的sa性能數(shù)據(jù)
最后附上完整代碼:
#!/bin/python2.7
#coding: utf-8
#################腳本用法:要取哪天的數(shù)據(jù)就輸入哪天的時間,比如9月1輸入應為20190901
import os
import sys
import datetime
import commands
import time

創(chuàng)新互聯(lián)建站成立十載來,這條路我們正越走越好,積累了技術與客戶資源,形成了良好的口碑。為客戶提供做網(wǎng)站、成都網(wǎng)站設計、網(wǎng)站策劃、網(wǎng)頁設計、申請域名、網(wǎng)絡營銷、VI設計、網(wǎng)站改版、漏洞修補等服務。網(wǎng)站是否美觀、功能強大、用戶體驗好、性價比高、打開快等等,這些對于網(wǎng)站建設都非常重要,創(chuàng)新互聯(lián)建站通過對建站技術性的掌握、對創(chuàng)意設計的研究為客戶提供一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進步。

def get_cpu(sdate,edate):
cpunum = int(commands.getoutput("cat /proc/cpuinfo |grep processor|wc -l"))
path = os.popen("find /var/log/sa/ -type f -newermt "+sdate+" ! -newermt "+edate+" |grep -v sar").readlines()
path = [m.rstrip("\n") for m in path]
for n in path:
idle = os.popen("sar -f "+n+" -u|awk '{print $NF}'|sed '1,3d'|sed '$d'|sed '/^$/d'").readlines()
data = list(idle)
data = [i.rstrip("\n") for i in idle]
data = [j for j in data if j != '']

    while '%idle' in data:
        data.remove("%idle")
    while 'RESTART' in data:
        data.remove("RESTART")

    data_tmp = list(map(float,data))
    data_num = [100-x for x in data_tmp]
    max_num = max(data_num)
    min_num = min(data_num)
    average_num=sum(data_num)/len(data_num)

    print("%s CPU useed max:%.4f,min:%.4f,average:%.4f"  % (n,max_num,min_num,average_num))

def get_dev(sdate,edate):
net = commands.getoutput("route -n|sed '1,2d'|awk -F' ' '{print $1,$8}'|grep 0.0.0.0|awk -F' ' '{print $2}'|sed -n '1p'")
rxkB=list()
txkB=list()
path = os.popen("find /var/log/sa/ -type f -newermt "+sdate+" ! -newermt "+edate+" |grep -v sar").readlines()
path = [m.rstrip("\n") for m in path]

for n in path:
    rxkB = commands.getoutput("sar -f "+n+" -n DEV|grep "+net+" |grep -v Average|awk -F' ' '{print $6}'|sed '$d'").split("\n")
    txkB = commands.getoutput("sar -f "+n+" -n DEV|grep "+net+" |grep -v Average|awk -F' ' '{print $7}'").split("\n")

    data_txkB = list(map(float,txkB))
    max_txkB=max(data_txkB)
    min_txkB=min(data_txkB)
    average_txkB=sum(data_txkB)/len(data_txkB)

    data_rxkB = list(map(float,rxkB))
    max_rxkB=max(data_rxkB)
    min_rxkB=min(data_rxkB)
    average_rxkB=sum(data_rxkB)/len(data_rxkB)
    print "%s rxval max:%.4f,min:%.4f,average:%.4f,dev:%s" %(n,max_rxkB,min_rxkB,average_rxkB,net)
    print "%s txval max:%.4f,min:%.4f,average:%.4f,dev:%s" %(n,max_txkB,min_txkB,average_txkB,net)

def get_mem(sdate,edate):
path = os.popen("find /var/log/sa/ -type f -newermt "+sdate+" ! -newermt "+edate+" |grep -v sar").readlines()
path = [m.rstrip("\n") for m in path]
for n in path:

    a=int(commands.getoutput("sar -f "+n+" -r|awk 'END{print NF}'"))
    if(a >= 11):
         memused = os.popen("sar -f "+n+" -r|grep -v ^$|grep -iv Linux|grep -iv memused|grep -iv Average|awk '{print(($(NF-8)-$(NF-5))/($(NF-9)+$(NF-8)))}'").readlines()
    else:
         memused = os.popen("sar -f "+n+" -r|grep -v ^$|grep -iv Linux|grep -iv memused|grep -iv Average|awk '{print(($(NF-5)-$(NF-2))/($(NF-6)+$(NF-5)))}'").readlines()
    data = list(memused)
    data = [i.rstrip("\n") for i in memused]
    data_num = list(map(float,data))
    max_num=max(data_num)
    min_num=min(data_num)
    average_num=sum(data_num)/len(data_num)
    print "%s memused max:%.4f,min:%.4f,average:%.4f" %(n,max_num,min_num,average_num)

def get_ldavg(sdate,edate):
cpunum = int(commands.getoutput("cat /proc/cpuinfo |grep processor|wc -l"))
path = os.popen("find /var/log/sa/ -type f -newermt "+sdate+" ! -newermt "+edate+" |grep -v sar").readlines()
path = [m.rstrip("\n") for m in path]
for n in path:

    a=int(commands.getoutput("sar -f "+n+" -q|sed -n '10p'|awk 'END{print NF}'"))
    if a == 7:
        ldavg_1 = os.popen("sar -f "+n+" -q|awk -F' ' '{print $5}'|sed '1,3d'|sed '$d'|sed '/^$/d'|grep -v ldavg-1").readlines()
        ldavg_15 = os.popen("sar -f "+n+" -q|awk -F' ' '{print $7}'|sed '1,3d'|sed '$d'|sed '/^$/d'|grep -v ldavg-15").readlines()
    elif a == 8:
        ldavg_1 = os.popen("sar -f "+n+" -q|awk -F' ' '{print $5}'|sed '1,3d'|sed '$d'|sed '/^$/d'|grep -v ldavg-1").readlines()
        ldavg_15 = os.popen("sar -f "+n+" -q|awk -F' ' '{print $7}'|sed '1,3d'|sed '$d'|sed '/^$/d'|grep -v ldavg-15").readlines()
    elif a == 6:
        ldavg_1 = os.popen("sar -f "+n+" -q|awk -F' ' '{print $4}'|sed '1,3d'|sed '$d'|sed '/^$/d'|grep -v ldavg-1").readlines()
        ldavg_15 = os.popen("sar -f "+n+" -q|awk -F' ' '{print $6}'|sed '1,3d'|sed '$d'|sed '/^$/d'|grep -v ldavg-15").readlines()

    data1 = [i.rstrip("\n") for i in ldavg_1]
    data15 =[j.rstrip("\n") for j in ldavg_15]
    data1 = list(map(float,data1))
    data15 = list(map(float,data15))
    max_data1=max(data1)
    min_data1=min(data1)
    average_data1=sum(data1)/len(data1)
    max_data15=max(data15)
    min_data15=min(data15)
    average_data15=sum(data15)/len(data15)
    print "%s cpu 1minute load max:%.4f,min:%.4f,average:%.4f" %(n,max_data1/cpunum,min_data1/cpunum,average_data1/cpunum)
    print "%s cpu 15minute load max:%.4f,min:%.4f,average:%.4f" %(n,max_data15/cpunum,min_data15/cpunum,average_data15/cpunum)

if name== "main":
sdate=sys.argv[1]
sdate=datetime.datetime.strptime(sdate,'%Y%m%d')
edate=sdate+datetime.timedelta(days=1)
sdate=sdate.strftime('%Y%m%d')
edate=edate.strftime('%Y%m%d')
get_cpu(sdate,edate)
get_ldavg(sdate,edate)
get_mem(sdate,edate)
get_dev(sdate,edate)

本文標題:一次公司需求記錄,python處理sysstat收集的sa性能數(shù)據(jù)
本文URL:http://aaarwkj.com/article2/isjgoc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設計、品牌網(wǎng)站建設、網(wǎng)站內鏈、網(wǎng)站收錄、企業(yè)建站、網(wǎng)站導航

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設
日本一区二区日本一区| 亚洲av精二区三区四区| 人人妻人人澡人人爽的视频| 国产女人高潮流白丝视频| 国产无人区码一区二区| 日韩欧美高清一区二区| 中文字幕国产精品资源| av在线亚洲网站区一| 日韩成人大片在线播放| 91中文字幕精品一区二区| 亚洲欧美日韩香蕉在线观看| 亚洲香蕉一级视频在线播放| 91成人精品永久在线观看| 国产精品国产三级国产不产一地| 国产精品一区久久91| 97视频精品免费观看| 日本中文字幕一二三四区| 亚洲av不卡一区二区在线观看| 未满十八禁止在线播放| 久久午夜人妻一区二区| 亚洲人妻乱人伦中文字幕在线| 杨幂一区二区在线观看| 开裆丝袜高跟啪啪高潮av| 国产精品一区二区高潮| 果冻国产精品麻豆成人av| 三级久久三级久久三级| 日韩精品一区二区三区四区在线视频 | 熟女乱熟乱熟妇综合网二区| 久久一区二区三区播放| 黄色欧美在线观看免费| 高清av网站大全网站| 欧美香蕉高清视频免费| 日本亚洲精品在线观看| 人妻鲁丝一区二区三区| 97日韩在线免费视频网站| 亚洲日本中文字幕免费观看| 日韩成人免费观看视频| 国产日韩视频一区二区| 国产精品一区二区三区熟女| 日本一区二区免费视频| 久久久久久这里都是精品|