How to retrieve specific cpu, memory and interface statistics only
2
votes
3
answers
3121
views
There is requirement to collect only specific stats like %idle, memfree, available, pmemused etc. I further have to convert the output to a json string and consume it.
Is there any UNIX tool which can do the same?
I tried sar and sadf in combination, but I am getting a complex json format which I don't require.
/usr/bin/sar -r 1 1 -o tmp1 &> 1;
/usr/bin/sadf tmp1 -j --iface=eth1 -- -u -r -n DEV
I get this output:
{
"sysstat": {
"hosts": [{
"nodename": "ESDNAS1",
"sysname": "Linux",
"release": "4.4.143-94.47-default",
"machine": "x86_64",
"number-of-cpus": 8,
"file-date": "2019-08-02",
"file-utc-time": "04:53:09",
"statistics": [{
"timestamp": {
"date": "2019-08-02",
"time": "04:53:10",
"utc": 1,
"interval": 1
},
"cpu-load": [{
"cpu": "all",
"user": 0.25,
"nice": 0.00,
"system": 1.00,
"iowait": 0.00,
"steal": 0.00,
"idle": 98.75
}],
"memory": {
"memfree": 3707764,
"avail": 12451860,
"memused": 12013448,
"memused-percent": 45.01,
"buffers": 225176,
"cached": 4361204,
"commit": 28665304,
"commit-percent": 107.41,
"active": 13473076,
"inactive": 1535816,
"dirty": 616
},
"network": {
"net-dev": [{
"iface": "eth1",
"rxpck": 1.00,
"txpck": 1.00,
"rxkB": 0.11,
"txkB": 0.00,
"rxcmp": 0.00,
"txcmp": 0.00,
"rxmcst": 0.00,
"ifutil-percent": 0.00
}]
}
}],
"restarts": []
}]
}
}
I am looking for something like this (or close one which is simple):
{
"sysstat": {
"hosts": [
{
"nodename": "HOSTNAME",
"statistics": [
{
"timestamp": {
"date": "2019-08-02",
"time": "04:53:10"
},
"cpu-load": [
{
"idle": 98.75
}
],
"memory": {
"memfree": 3707764,
"avail": 12451860,
"memused-percent": 45.01
},
"network": {
"net-dev": [
{
"iface": "eth1",
"rxpck": 1,
"txpck": 1,
"ifutil-percent": 0
}
]
}
}
],
"restarts": []
}
]
}
}
Asked by Aditya369
(133 rep)
Aug 2, 2019, 07:33 AM
Last activity: Aug 4, 2019, 02:43 PM
Last activity: Aug 4, 2019, 02:43 PM