dool icon indicating copy to clipboard operation
dool copied to clipboard

/proc/diskstats: better detection of unused block devices

Open leahneukirchen opened this issue 3 years ago • 1 comments

ISSUE TYPE
  • Bugfix pull-request
DSTAT VERSION
Dool 1.0.0
Written by Scott Baker <[email protected]>
Forked from Dstat written by Dag Wieers <[email protected]>
Homepage at https://github.com/scottchiefbaker/dool/

Platform posix/linux
Kernel 5.13.12_1
Python 3.10.2 (main, Jan 15 2022, 03:11:32) [GCC 10.2.1 20201203]

Terminal type: rxvt-unicode-256color (color support)
Terminal size: 82 lines, 154 columns

Processors: 8
Pagesize: 4096
Clock ticks per secs: 100

internal:
	aio,cpu,cpu-adv,cpu-use,cpu24,disk,disk24,disk24-old,epoch,fs,int,int24,io,ipc,load,lock,mem,mem-adv,net,page,page24,proc,
	raw,socket,swap,swap-old,sys,tcp,time,udp,unix,vm,vm-adv,zones
/home/leah/src/dool/plugins:
	battery,battery-remain,condor-queue,cpufreq,dbus,disk-avgqu,disk-avgrq,disk-svctm,disk-tps,disk-util,disk-wait,dool,dool-cpu,
	dool-ctxt,dool-mem,fan,freespace,fuse,gpfs,gpfs-ops,helloworld,ib,innodb-buffer,innodb-io,innodb-ops,jvm-full,jvm-vm,lustre,
	md-status,memcache-hits,mongodb-conn,mongodb-mem,mongodb-opcount,mongodb-queue,mongodb-stats,mysql-io,mysql-keys,mysql5-cmds,
	mysql5-conn,mysql5-innodb,mysql5-innodb-basic,mysql5-innodb-extra,mysql5-io,mysql5-keys,net-packets,nfs3,nfs3-ops,nfsd3,nfsd3-ops,
	nfsd4-ops,nfsstat4,ntp,postfix,power,proc-count,qmail,redis,rpc,rpcd,sendmail,snmp-cpu,snmp-load,snmp-mem,snmp-net,snmp-net-err,
	snmp-sys,snooze,squid,test,thermal,top-bio,top-bio-adv,top-childwait,top-cpu,top-cpu-adv,top-cputime,top-cputime-avg,top-int,
	top-io,top-io-adv,top-latency,top-latency-avg,top-mem,top-oom,utmp,vm-cpu,vm-mem,vm-mem-adv,vmk-hba,vmk-int,vmk-nic,vz-cpu,vz-io,
	vz-ubc,wifi,zfs-arc,zfs-l2arc,zfs-zil
SUMMARY

The format of /proc/diskstats has changed over the years: Until kernel 4.17 there were 14 fields (which this code assumed) Since 4.18 there are 18 fields, since 5.5 there are 20 fields.

Assume unused devices have all fields zero.

Fixes #1. Fixes #5. Fixes #7.

% ./dool --disk-wait                      
--loop0----nvme0n1----zram0--                  
rawa wawa:rawa wawa:rawa wawa
0.05    0:0.16 2.46:0.00 0.01
   0    0:   0    0:   0    0
   0    0:   0 1.67:   0    0^C

leahneukirchen avatar Jan 22 '22 00:01 leahneukirchen

I realized this issue occurs all over the code base and fixed it everywhere.

leahneukirchen avatar Jan 22 '22 00:01 leahneukirchen

Apologies... Github was not sending me alerts for issues and pull requests on this repo. I did not see this until just now.

Is this still relevant? I'm working through some backlog.

scottchiefbaker avatar Jun 03 '23 02:06 scottchiefbaker

Yes, it's still relevant (even more so as people don't run <4.17 kernels anymore really).

leahneukirchen avatar Jun 03 '23 13:06 leahneukirchen

Thank you for the contribution. I am happy to see people actually using dool in the wild. I didn't know anyone other than myself was using it. Merging now!

Python is not my primary language, can you help me understand exactly what this is doing?

if set(l[3:]) == {'0'}: continue

I'm thinking it's saying "if the array elements of l beyond the 4th (5,6,7+) item are all 0 skip this loop"? The set() syntax is throwing me off a bit.

scottchiefbaker avatar Jun 05 '23 15:06 scottchiefbaker

it means "make a set out of the items from the 4th" and "check it's the same set that contains only "0", i.e. it checks all items are "0".

leahneukirchen avatar Jun 05 '23 15:06 leahneukirchen

Thanks for the explanation.

scottchiefbaker avatar Jun 05 '23 17:06 scottchiefbaker