zabbix 監控CDN頻寬

來源:互聯網
上載者:User

標籤:密碼   監控   介面   電訊廠商   頻寬   

       我這邊使用的是網宿的CDN做加速,然後有一堆的介面可以調用單獨查詢;網宿提供所有頻道一起查詢;cdn上面都是錢,稍微監控還是非常有必要的。api資訊格式:https://myview.chinanetcenter.com/api/bandwidth-channel.action?u=xxxx&p=xxxx&cust=xxx&date=xxxx&channel=xxxxxx;xxxxx&isExactMatch=false&region=xxxx&isp=xxxx&resultType=xxxx&format=xxx&startdate=xxxx&enddate=xxxx說明:u 和p 是必選項,p是cdn後台設定的myview密碼;其他可以預設或者不選;channel:頻道資訊;不填預設是全部。isp:電訊廠商頻寬;預設是所有。startdate和enddate: 查詢的時間;不選預設是全部,而這個時間也有一個規律,就是年月和時間之前用%20轉碼:比如(2013-01-01%2010:10就是 2013-01-01 10:10)其api文檔可以諮詢客服。
1、先匯入bs 查看返回資料結構:
開始查看資料指令碼:
[[email protected] python]# cat check_cndbindwaith.py #coding=utf-8import urllib,urllib2from bs4 import BeautifulSoupimport datetimeimport sysusername = "xxx"password = "xxxx"now_time=datetime.datetime.now()starttime=(now_time - datetime.timedelta(seconds=300)).strftime(‘%Y-%m-%d %H:%M‘)starttimeformat = starttime.split()[0]+"%20"+starttime.split()[1]endtime=(datetime.datetime.now()).strftime(‘%Y-%m-%d %H:%M‘)endtimtformat = endtime.split()[0]+"%20"+endtime.split()[1]url = "https://myview.chinanetcenter.com/api/bandwidth-channel.action?u=%s&p=%s&startdate=%s&enddate=%s" %(username,password,starttimeformat,endtimtformat)try:    html = urllib2.urlopen(url, timeout=5)except urllib2.HTTPError as err:    print str(err)soup = BeautifulSoup(html)print soup
二、查看結果並取值:
[[email protected] python]# python check_cndbindwaith.py   markup_type=markup_type))<?xml version="1.0" encoding="utf-8"?><html><body><provider name="ChinaNetCenter" resulttype="1" type="bandwidth-channel"><bandwidth time="2016-01-26 15:35:00">0.00</bandwidth></channel></date></provider></body></html>備忘:我們要取的是bandwidth的值。然後通過觀察發現有時候指令碼返回兩個值。而我們zabbix應該只要一個傳回值。三、zabbix 指令碼:#coding=utf-8import urllib,urllib2from bs4 import BeautifulSoupimport datetimeimport sysdef cdn():    username = "xxx"    password = "xxxx"    now_time=datetime.datetime.now()    starttime=(now_time - datetime.timedelta(seconds=300)).strftime(‘%Y-%m-%d %H:%M‘)    starttimeformat = starttime.split()[0]+"%20"+starttime.split()[1]    endtime=(datetime.datetime.now()).strftime(‘%Y-%m-%d %H:%M‘)    endtimtformat = endtime.split()[0]+"%20"+endtime.split()[1]    data = []    url = "https://myview.chinanetcenter.com/api/bandwidth-channel.action?u=%s&p=%s&startdate=%s&enddate=%s" %(username,password,starttimeformat,endtimtformat)    try:        html = urllib2.urlopen(url, timeout=5)    except urllib2.HTTPError as err:        print str(err)    soup = BeautifulSoup(html)    for key in soup.find_all("bandwidth"):        data.append(key.get_text())    for i in data:         if i.startswith("0") and not i.startswith("1"):            return 0        else:            return int(i.split(".")[0])if __name__ == "__main__":    print cdn()

四、zabbix agent編寫指令碼並且收集資料:

[[email protected] scripts]# vim /usr/local/zabbix/etc/zabbix_agentd.confUserParameter=cdn,/usr/bin/python /usr/local/zabbix/scripts/check_cdnbindwaitch.py

五、添加item:

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/7A/4D/wKioL1anJQOwkk-sAABddOJ9NHc598.png" title="QQ圖片20160126154842.png" alt="wKioL1anJQOwkk-sAABddOJ9NHc598.png" />


六:出圖和觸發器根據自己需要進行添加:

650) this.width=650;" style="width:700px;height:217px;" src="http://s4.51cto.com/wyfs02/M02/7A/4E/wKioL1anJoGwusRoAABOLzA9zfI486.png" title="QQ圖片20160126155520.png" alt="wKioL1anJoGwusRoAABOLzA9zfI486.png" border="0" height="217" hspace="0" vspace="0" width="700" />


本文出自 “小羅” 部落格,請務必保留此出處http://xiaoluoge.blog.51cto.com/9141967/1738652

zabbix 監控CDN頻寬

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.