zabbix api 獲取圖形
一.背景
因為介面壓測平臺需要獲取介面伺服器的效能資料,所以找了一圈zabbix api獲取資料的方式,以此記錄下來。
zabbix api地址:https://www.zabbix.com/documentation/3.4/zh/manual/api 功能還真挺多,挺詳細的。
二.zabbix api獲取方式
1.獲取token
url = "http://ip/zabbix/api_jsonrpc.php"
header = {
"Content-Type": "application/json"
}
def get_token():
data = {"jsonrpc": "2.0", "method": "user.login", "params": {"user": "xxx", "password": "xxx"},
"id": 1, "auth": None}
resp = requests.post(url, json=data, headers=header)
print(resp.status_code)
print(resp.text)
if resp.status_code == 200:
json_data = json.loads(resp.text)
return json_data['result']
return None
2.獲取伺服器ip,這個可以獲取到hostid
def get_machine():
auth = get_token()
data = {
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 2,
"auth": auth
}
resp = requests.post(url, json=data, headers=header)
print(resp.status_code)
print(resp.text)
3.獲取graphid
def get_graph():
auth = get_token()
data = {
"jsonrpc": "2.0",
"method": "graph.get",
"params": {
"output": "extend",
"hostids": 10351,
"sortfield": "name"
},
"auth": auth,
"id": 1
}
resp = requests.post(url, json=data, headers=header)
print(resp.status_code)
print(resp.text)
4.獲取圖形寫入檔案
def get_png():
token = get_token()
print(token)
header = {
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Cookie": "PHPSESSID=2bvctu9rva99ppd74gaopb8i42; zbx_sessionid=" + token,
"Pragma": "no-cache",
"Upgrade-Insecure-Requests": "1"
}
charUrl = "http://ip/zabbix/chart2.php?graphid=3396&period=120&stime=20200624103155&isNow=0&profileIdx=web.graphs&profileIdx2=3396&width=682&sid=96b019eb208dec18&screenid=&curtime=1592965915667"
resp = requests.get(charUrl, headers=header)
with open("test_img.png", 'wb') as f:
f.write(resp.content)
關鍵引數:
charUrl
可以從graphs查詢的圖片,然後右擊-複製圖片地址獲取到
graphid=3396
這個就是graph下拉那塊的id,有CPU、流量等,上面有方法通過hostid可以獲取到
period=120
這個單位秒,即獲取2分鐘的圖形,可以隨便改
stime=20200624103155
開始時間,意思很明朗;所以其實獲取的圖形,就是從stime到stime+period這段的圖形
width=682
這個是圖片寬度
isNow=0
預設是1,就是5分鐘時長的圖形,改為0後,period就起作用了
總結:簡單記錄api獲取方式,但是其實我是想獲取CPU的資料,不是圖形,還在琢磨能不能獲取到一段時間的平均值。有知道的請告訴我哇~~
有問題請指出哦~~
相關文章
- 【API】隨機獲取圖片API隨機
- 利用marching square algorithm獲取圖形輪廓Go
- 利用API獲取金融資料並畫圖API
- api暴力獲取API
- Zabbix頁面圖形內中文有亂碼問題處理(Zabbix 3.0.9)
- API 獲取商品評論?API
- C#中通過API呼叫獲取檔案圖示C#API
- 智慧手環心率API獲取API
- 分散式監控系統Zabbix-批量新增聚合圖形分散式
- 獲取app 圖片APP
- 智慧手環計步API獲取API
- D3圖形庫API參考API
- 獲取javascript函式形參的數目JavaScript函式
- Linux下Zabbix5.0 LTS + Grafana8.2.2圖形視覺化LinuxGrafana視覺化
- 分散式監控系統Zabbix--使用Grafana進行圖形展示分散式Grafana
- 從 falcon api 中獲取資料API
- 教你如何使用API介面獲取資料!API
- 智慧手環運動軌跡API獲取API
- 智慧手環睡眠資料API獲取API
- API介面獲取搜尋詞統計?API
- 淘寶API分享:獲取淘寶商品SKU資訊API
- 淘寶API,獲取店鋪的所有商品API
- 淘寶API分享:獲取淘寶商品評論API
- restfus webservices獲取資料的api方法RESTWebAPI
- 詳情API介面上貨搬運獲取資訊API介面API
- Zabbix開發實踐:HPUX獲取磁碟利用率最大值UX
- zabbix 操作 API 用例小記API
- zabbix利用API批量新增Screen薦API
- 利用微信公眾號提供的官方API上傳圖片獲取永久圖片素材!當圖床用!API圖床
- 獲取本地圖片/視訊地圖
- iOS 獲取視訊圖片iOS
- 小微型庫(1.獲取元素的API)API
- 如何使用API介面獲取淘寶商品資料API
- 如何呼叫API獲取你想要的資料API
- 智慧手環報文資料API獲取API
- 智慧手環體溫資料API獲取API
- 智慧手環圍欄資料API獲取API
- 使用API介面獲取拼多多商品詳情API