From c1cd41ba16ba7552204aeafa86afec53b69f7ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Skytte=20J=C3=B8rgensen?= Date: Mon, 20 Jun 2016 14:20:07 +0200 Subject: [PATCH] Generate write_bytes and read_bytes metrics write_sectors/read_sectors are multiplied by the secotr size of the device. --- collectors/0/iostat.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/collectors/0/iostat.py b/collectors/0/iostat.py index 7fbb4281..0ac49068 100755 --- a/collectors/0/iostat.py +++ b/collectors/0/iostat.py @@ -134,6 +134,21 @@ def is_device(device_name, allow_virtual): return os.access(devicename, os.F_OK) +cached_device_sector_size={} +def get_device_sector_size(device_name): + if device_name not in cached_device_sector_size: + filename = "/sys/block/"+device_name+"sda/queue/hw_sector_size" + + if os.path.exists(filename): + with open(filename,"r") as f: + sector_size = int(f.readline()) + else: + #hmmm? + sector_size = 512; #best guess + cached_device_sector_size[device_name] = sector_size + return cached_device_sector_size[device_name] + + def main(): """iostats main loop.""" init_stats = { @@ -181,6 +196,14 @@ def main(): for i in range(11): print("%s%s %d %s dev=%s" % (metric, FIELDS_DISK[i], ts, values[i+3], device)) + if FIELDS_DISK[i]=="read_sectors": + v = long(values[i+3]) * get_device_sector_size(device) + print("%s%s %d %s dev=%s" + % (metric, "read_bytes", ts, v, device)) + if FIELDS_DISK[i]=="write_sectors": + v = long(values[i+3]) * get_device_sector_size(device) + print("%s%s %d %s dev=%s" + % (metric, "write_bytes", ts, v, device)) ret = is_device(device, 0) # if a device or a partition, calculate the svctm/await/util