Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 77 lines (66 sloc) 2.49 KB
#! /usr/bin/env perl6
use v6.d;
our &BOLD = sub (*@s) {
"\e[1m{@s.join('')}\e[0m"
}
our &RED = sub (*@s) {
"\e[31m{@s.join('')}\e[0m"
}
our &RESET = sub (*@s) {
"\e[0m{@s.join('')}\e[0m"
}
&BOLD = &RED = &RESET = sub (Stringy $s) { $s } unless $*OUT.t;
sub bcache-devs(){
dir('/sys/block/'.basename.grep: *.starts-with('bcache')
}
sub bcache-caches() {
dir('/sys/fs/bcache/'.basename.grep: *.contains('-')
}
my @stats =
'cache state', -> $dev { slurp("/sys/block/$dev/bcache/state").chomp },
'cache mode', -> $dev { slurp("/sys/block/$dev/bcache/cache_mode").chomp ~~ /'[' (\w+) ']'/; $0 },
'dirty data', -> $dev { slurp("/sys/block/$dev/bcache/dirty_data").chomp },
'hit ratio', -> $cache {
slurp("/sys/fs/bcache/$cache/stats_total/cache_hit_ratio").chomp ~ '%',
slurp("/sys/fs/bcache/$cache/stats_day/cache_hit_ratio").chomp ~ '%/d',
slurp("/sys/fs/bcache/$cache/stats_hour/cache_hit_ratio").chomp ~ '%/h',
slurp("/sys/fs/bcache/$cache/stats_five_minute/cache_hit_ratio").chomp ~ '%/5min'
},
'bypassed', -> $cache {
slurp("/sys/fs/bcache/$cache/stats_total/bypassed").chomp,
slurp("/sys/fs/bcache/$cache/stats_day/bypassed").chomp ~ '/d',
slurp("/sys/fs/bcache/$cache/stats_hour/bypassed").chomp ~ '/h',
slurp("/sys/fs/bcache/$cache/stats_five_minute/bypassed").chomp ~ '/5min'
},
'cache available', -> $cache {
slurp("/sys/fs/bcache/$cache/cache_available_percent").chomp ~ '%'
},
'written to cache', -> $cache { slurp("/sys/fs/bcache/$cache/cache0/written").chomp },
'btree written', -> $cache { slurp("/sys/fs/bcache/$cache/cache0/btree_written").chomp }
;
multi sub MAIN() {
for bcache-devs() -> $dev {
with $dev {
say BOLD $dev, ':';
for @stats -> $name, &f {
next unless &f.signature.params».name eq '$dev';
put "\t", $name, ': ', .&f
}
}
}
put "";
for bcache-caches() -> $cache {
say BOLD $cache, ':';
with $cache {
for @stats -> $name, &f {
next unless &f.signature.params».name eq '$cache';
put "\t", $name, ': ', .&f
}
}
}
}
multi sub MAIN($delay) {
react whenever Supply.interval($delay) {
MAIN();
}
}