summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-10-01 01:46:05 -0400
committerJesse Luehrs <doy@tozt.net>2013-10-01 01:46:31 -0400
commit412d8633532d3f172c5845df1fd9a8b2abecc66d (patch)
treeb23d1625c6b3d10ac75c99254dff1fda8fcb0ec9
parentac66257c1052c15c8a87a5cd9c8022ebfcefd582 (diff)
downloadconf-412d8633532d3f172c5845df1fd9a8b2abecc66d.tar.gz
conf-412d8633532d3f172c5845df1fd9a8b2abecc66d.zip
color cpu status based on load average instead of cpu percent
-rwxr-xr-xbin/status16
-rw-r--r--i3status.conf5
2 files changed, 17 insertions, 4 deletions
diff --git a/bin/status b/bin/status
index 8887235..07a8eee 100755
--- a/bin/status
+++ b/bin/status
@@ -12,11 +12,15 @@ print scalar(<$i3status>);
while (<$i3status>) {
my $comma = s/^,//;
+ my $data = decode_json($_);
+
+ my %line = map { $_->{name} => $_ } @$data;
my $line = [
grep {
- !($_->{name} eq 'wireless' || $_->{name} eq 'ethernet')
- || ($_->{instance} ne $_->{full_text})
- } @{ decode_json($_) }
+ $_->{name} eq 'wireless' || $_->{name} eq 'ethernet'
+ ? $_->{instance} ne $_->{full_text}
+ : $_->{name} ne 'load'
+ } @$data
];
my $discharge_rate;
@@ -35,7 +39,7 @@ while (<$i3status>) {
: '#FFFFFF';
}
if ($item->{name} eq 'cpu_usage') {
- my ($val) = $item->{full_text} =~ /CPU: (\d+)%/;
+ my ($val) = $line{load}{full_text} * 100 / ncpu();
$item->{color} =
$val >= 50 ? '#FF0000'
: $val >= 25 ? '#FFFF00'
@@ -136,6 +140,10 @@ sub find {
}
}
+sub ncpu {
+ scalar grep { !/^#/ } `lscpu -p=cpu`
+}
+
sub human_bytes {
my ($bytes) = @_;
my @prefixes = ('', qw(k M G T));
diff --git a/i3status.conf b/i3status.conf
index 52d7ce9..1b7914f 100644
--- a/i3status.conf
+++ b/i3status.conf
@@ -8,6 +8,7 @@ order += "wireless wlan0"
order += "ethernet eth0"
order += "battery 0"
order += "time"
+order += "load"
cpu_usage {
format = "CPU: %usage"
@@ -31,3 +32,7 @@ battery 0 {
time {
format = "%a %b %d %H:%M:%S"
}
+
+load {
+ format = "%1min"
+}