2018-10-04 18:50:34 -07:00
|
|
|
from pymonitor import Metric
|
2015-12-09 15:47:47 -08:00
|
|
|
from psutil import disk_io_counters
|
|
|
|
|
2017-05-15 17:29:20 -07:00
|
|
|
|
2015-12-09 15:47:47 -08:00
|
|
|
def diskio(disks=[]):
|
|
|
|
with open("/proc/uptime", "r") as f:
|
|
|
|
uptime = int(float(f.read().split(" ")[0]))
|
|
|
|
diskinfo = disk_io_counters(perdisk=True)
|
2017-05-15 17:29:20 -07:00
|
|
|
for disk, stats in diskinfo.items():
|
2015-12-09 15:47:47 -08:00
|
|
|
if disks and disk not in disks:
|
|
|
|
continue
|
2015-12-09 15:54:04 -08:00
|
|
|
if stats.read_count == 0 and disk not in disks:
|
|
|
|
continue
|
2015-12-09 15:47:47 -08:00
|
|
|
stats = {
|
|
|
|
"disk": disk,
|
2017-05-15 17:29:20 -07:00
|
|
|
"reads_ps": round(stats.read_count / uptime, 2),
|
|
|
|
"writes_ps": round(stats.write_count / uptime, 2),
|
|
|
|
"read_ps": round(stats.read_bytes / uptime, 2),
|
|
|
|
"write_ps": round(stats.write_bytes / uptime, 2),
|
|
|
|
"reads": stats.read_count,
|
|
|
|
"writes": stats.write_count,
|
|
|
|
"read": stats.read_bytes,
|
|
|
|
"written": stats.write_bytes,
|
2018-10-04 18:50:34 -07:00
|
|
|
"read_size": round(stats.read_bytes / stats.read_count, 2) if stats.read_count > 0 else 0.0,
|
|
|
|
"write_size": round(stats.write_bytes / stats.write_count, 2) if stats.write_count > 0 else 0.0
|
2015-12-09 15:47:47 -08:00
|
|
|
}
|
2018-10-04 18:50:34 -07:00
|
|
|
yield Metric(stats, {"disk": disk})
|
2015-12-09 15:47:47 -08:00
|
|
|
|
2017-05-15 17:29:20 -07:00
|
|
|
|
2015-12-09 15:47:47 -08:00
|
|
|
mapping = {
|
2018-10-04 18:50:34 -07:00
|
|
|
"disk": {
|
|
|
|
"type": "text"
|
|
|
|
},
|
|
|
|
"disk_raw": {
|
|
|
|
"type": "keyword"
|
|
|
|
},
|
|
|
|
"reads_ps": {
|
|
|
|
"type": "double"
|
|
|
|
},
|
|
|
|
"writes_ps": {
|
|
|
|
"type": "double"
|
|
|
|
},
|
|
|
|
"read_ps": {
|
|
|
|
"type": "double"
|
|
|
|
},
|
|
|
|
"write_ps": {
|
|
|
|
"type": "double"
|
|
|
|
},
|
|
|
|
"reads": {
|
|
|
|
"type": "long"
|
|
|
|
},
|
|
|
|
"writes": {
|
|
|
|
"type": "long"
|
|
|
|
},
|
|
|
|
"read": {
|
|
|
|
"type": "long"
|
|
|
|
},
|
|
|
|
"written": {
|
|
|
|
"type": "long"
|
|
|
|
},
|
|
|
|
"read_size": {
|
|
|
|
"type": "double"
|
|
|
|
},
|
|
|
|
"write_size": {
|
|
|
|
"type": "double"
|
2015-12-09 15:47:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
for item in diskio():
|
|
|
|
print(item)
|