计算时间戳
获取 2018/04/12 00:00:00 ~ 2018/04/12 10:00:00 的内存使用记录
转换为时间戳: 1523462400 ~ 1523498400
item
id
获取总内存vm.memory.size[total]与可用内存vm.memory.size[available]的Payload:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": ["itemid","hostid","key_","value_type","status","units"],
"hostids": "10254",
"search": {
"key_": "vm.memory.size[total]"
},
"sortfield": "name"
},
"auth": "54ec7f0d103f635ada0a76147d8a93a5",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "28272",
"hostid": "10254",
"key_": "vm.memory.size[total]",
"value_type": "3",
"status": "0",
"units": "B"
}
],
"id": 1
}
Payload:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": ["itemid","hostid","key_","value_type","status","units"],
"hostids": "10254",
"search": {
"key_": "vm.memory.size[available]"
},
"sortfield": "name"
},
"auth": "54ec7f0d103f635ada0a76147d8a93a5",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "28317",
"hostid": "10254",
"key_": "vm.memory.size[available]",
"value_type": "3",
"status": "0",
"units": "B"
}
],
"id": 1
}
记录下两个item id 分别为28272, 28317
分别获取total memory 与 available memory 的history值
Payload:
{
"jsonrpc": "2.0",
"method": "history.get",
"params": {
"output": "extend",
"history": 3,
"itemids": "28272",
"sortfield": "clock",
"sortorder": "DESC",
"time_from": "1523462400",
"time_till": "1523498400"
},
"auth": "54ec7f0d103f635ada0a76147d8a93a5",
"id": 1
}
Respones:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "28272",
"clock": "1523497872",
"value": "3958050816",
"ns": "360074776"
},
{
"itemid": "28272",
"clock": "1523494272",
"value": "3958050816",
"ns": "331780004"
},
{
"itemid": "28272",
"clock": "1523490672",
"value": "3958050816",
"ns": "771174968"
},
...
...
{
"itemid": "28317",
"clock": "1523462577",
"value": "1576091648",
"ns": "50470151"
},
{
"itemid": "28317",
"clock": "1523462517",
"value": "1576214528",
"ns": "469703166"
},
{
"itemid": "28317",
"clock": "1523462457",
"value": "1576411136",
"ns": "848907144"
}
],
"id": 1
}
内存使用率计算公式为: available memroy/total memory * 100 %
, 这里total memroy一般为恒定值