I recently introduced a lot of ansible use cases. This time I am back on the right track. I will introduce how to use zabbix to monitor CDN bandwidth, so that I can know in time when bandwidth exceptions occur and the economic losses caused by bandwidth exceptions.
The following uses chinacache CDN as an example. The monitoring method is through the API interface provided by CDN. Note: currently, the blue flood API interface can only view the bandwidth of individual channels and cannot view all channels. it is inconvenient to check the channel ID by yourself or customer service.
1. the API information is:
(A) interface address: https://api.chinacache.com/reportdata/monitor/query? Type = monitor & withtime = true & layerdetail = true & username = xxx & pass = xxx & billingid = 123 & starttime = 201009190000 & endtime = 201009192359 Description: 1. currently, two protocol interfaces are provided: HTTP and HTTPS. You can use either of them as needed. you can access the Protocol interface through post or get (2) parameter description: TYPE = monitor [required parameter]: Query type withtime = true [optional parameter ]: used to show whether the query results show the detailed timestamp layerdetail = true [optional parameter]: Used to show whether the query results show hierarchical data username [required parameter]: User Name, the customer's Logon account in the portal pass [required parameter]: password, the customer's logon password in the portal billingid [required parameter]: provides the service The ID of the billing unit defined by chinacache. When multiple billing units need to be queried, separate them with '&'. For example, billingid = 123 & billingid = 456starttime [required parameter]: start time, accurate to 1 minute. format: year, month, and day (12-digit, 4-digit year, 2-digit month, 2-digit Day, 2-digit hour, 2-digit minute) 2. example: 201009190000, indicating the endtime at 00:00, January 1, September 19, 2010 [required parameter]: end time, accurate to minute 1. format: year, month, and day (12-digit, 4-digit year, 2-digit month, 2-digit Day, 2-digit hour, 2-digit minute) 2. for example, 201009192359 indicates, January 1, September 19, 2010.
For other information about how to use chinacache or other CDN, please contact them for API documentation.
2. The following is a CDN bandwidth script (Python) for a channel through APIS)
#!/bin/bash#encoding=utf-8import datetimeimport urllibimport urllib2api_user=‘xxxx‘api_passwd=‘xxxx‘billid=‘3926x‘now_time=datetime.datetime.now()starttime=(now_time - datetime.timedelta(seconds=300)).strftime(‘%Y%m%d%H%M‘)endtime=(datetime.datetime.now()).strftime(‘%Y%m%d%H%M‘)url="https://api.chinacache.com/reportdata/monitor/query?type=monitor&withtime=true&layerdetail=true&username=%s&pass=%s&billingid=%s&starttime=%s&endtime=%s"%(api_user,api_passwd,billid,starttime,endtime)#get xxx product xmlresult = urllib2.urlopen(url, timeout=5).read()#follow is use xml‘‘‘from xml.etree import ElementTree as ETfrom xml.dom import minidomper=minidom.parseString(result)per=ET.parse(‘qsmy.xml‘)p=per.findall(‘/Total‘)for oneper in p: for child in oneper.getchildren():if child.tag == ‘MaxData‘: value = round(int(child.text)/float(1000)/float(1000),2) print value‘‘‘#follow is use stringimport xml.etree.ElementTree per = xml.etree.ElementTree.fromstring(result)p=per.findall(‘Total‘)for oneper in p: for child in oneper.getchildren(): if child.tag == ‘MaxData‘: value = int(child.text)/1000/1000 print value
There are two methods to obtain the interface. One is to save the information obtained by the API to an XML file, and then parse the XML file. The other is to retrieve the data directly through the interface and parse it, by default, I use the second method.
At the same time, I obtained the largest data in the last five minutes, measured in MB.
3. The following shows the results obtained by running APIs on the web.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/46/7D/wKiom1Pyp_WBfIyHAAKfe5yyRQI276.jpg "Title =" 8.jpg" alt = "wkiom1pyp_wbfiyhaakfe5yyrqi276.jpg"/> the result is 23 m
4. Run the command line to display the result.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/46/7D/wKiom1PyqK-x1SFNAACnaDn-xhM385.jpg "Title =" 8.jpg" alt = "wKiom1PyqK-x1SFNAACnaDn-xhM385.jpg"/> the result is 23, the above URL is output only to make it easier for everyone to see.
5. Combined with zabbix monitoring
A. Place the script in the/usr/local/zabbix/bin/directory and grant the 755 permission and zabbix user and group permission.
B. Configure in zabbix_agentd.conf
[[email protected] bin]# tail -n 1 /usr/local/zabbix/conf/zabbix_agentd.conf UserParameter=check_cdn[*],python /usr/local/zabbix/bin/qsmy_cdn.py
C. Restart the zabbix client.
ps -ef|grep zabbix|grep -v grep|awk ‘{print$2}‘|xargs kill -9/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf
D. Add the item in zabbix web as follows:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/46/7E/wKiom1PyqmbSdL39AAKK8Nk0Yhc314.jpg "Title =" 8.jpg" alt = "wkiom1pyqmbsdl39aakk8nk0yhc314.jpg"/>
E. Configure trigger
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/46/80/wKioL1Pyq8Kh1WMjAAFYfA6mNxs767.jpg "Title =" 8.jpg" alt = "wkiol1pyq8kh1wmjaafyfa6mnxs767.jpg"/> F. graphs your own configuration
The image in G. zabbix is displayed
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/46/7E/wKiom1PyqzfxWZ-tAAPBA70nQLQ791.jpg "Title =" 8.jpg" alt = "wKiom1PyqzfxWZ-tAAPBA70nQLQ791.jpg"/>
You can refer to this to customize your CDN bandwidth monitoring. If you have any questions, leave a message.
This article is from the "Yin-Technical Exchange" blog, please be sure to keep this source http://dl528888.blog.51cto.com/2382721/1541847