From 4709959c821f323295de7cce78b0f1a8f525de6f Mon Sep 17 00:00:00 2001
From: David Luevano Alvarado <55825613+luevano@users.noreply.github.com>
Date: Thu, 27 Feb 2020 13:36:06 -0700
Subject: Tweak blocklets
---
.local/bin/blocks/gpu | 50 ++++++++++++++++++--------------------------------
1 file changed, 18 insertions(+), 32 deletions(-)
(limited to '.local/bin/blocks/gpu')
diff --git a/.local/bin/blocks/gpu b/.local/bin/blocks/gpu
index 73c17f1..b20fc4a 100755
--- a/.local/bin/blocks/gpu
+++ b/.local/bin/blocks/gpu
@@ -1,18 +1,5 @@
#!/usr/bin/perl
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
use strict;
use warnings;
use utf8;
@@ -28,44 +15,43 @@ my $gpu_pcie = -1;
my $label = $ENV{LABEL} // "";
sub help {
- print "Usage: gpu-load [-w ] [-c ]\n";
- print "-w : warning threshold to become amber\n";
- print "-c : critical threshold to become red\n";
- exit 0;
+ print "Usage: gpu-load [-w ] [-c ]\n";
+ print "-w : warning threshold to become amber\n";
+ print "-c : critical threshold to become red\n";
+ exit 0;
}
GetOptions("help|h" => \&help,
- "w=i" => \$t_warn,
- "c=i" => \$t_crit);
+ "w=i" => \$t_warn,
+ "c=i" => \$t_crit);
# Get GPU usage from nvidia-settings
open (NVS, 'nvidia-settings -q GPUUtilization -t |') or die;
while () {
- if (/^[a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+)$/) {
- $gpu_usage = $1;
+ if (/^[a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+)$/) {
+ $gpu_usage = $1;
$gpu_mem = $2;
$gpu_video = $3;
$gpu_pcie = $4;
- last;
- }
+ last;
+ }
}
close(NVS);
$gpu_usage eq -1 and die 'Can\'t find GPU information';
-# I edited this to only show the gpu_usage and gpu_mem.
-# Also fixed the label thing.
-# Print full_text, short_text
-# printf "%.0f%% %.0f%% %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie;
-# printf "%.0f%%\n", $gpu_usage;
-printf "${label} %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem;
+# Full text.
+# printf "%s %.0f%% %.0f%% %.0f%% %.0f%%\n", $label, $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie;
+printf "%s %.0f%% %.0f%%\n", $label, $gpu_usage, $gpu_mem;
+# Short text.
+printf "%s %.0f%% %.0f%%\n", $label, $gpu_usage, $gpu_mem;
# Print color, if needed
if ($gpu_usage >= $t_crit || $gpu_mem >= $t_crit || $gpu_video >= $t_crit || $gpu_pcie >= $t_crit) {
- print "#FF0000\n";
- exit 33;
+ print "#FF0000\n";
+ exit 33;
} elsif ($gpu_usage >= $t_warn || $gpu_mem >= $t_warn || $gpu_video >= $t_warn || $gpu_pcie >= $t_warn) {
- print "#FFBF00\n";
+ print "#FFBF00\n";
}
exit 0;
--
cgit v1.2.3-70-g09d2