Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

  1. #!/usr/bin/perl
  2. #
  3. # Copyright 2014 Pierre Mavro <deimos@deimos.fr>
  4. # Copyright 2014 Vivien Didelot <vivien@didelot.org>
  5. # Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
  6. #
  7. # Licensed under the terms of the GNU GPL v3, or any later version.
  8. use strict;
  9. use warnings;
  10. use utf8;
  11. use Getopt::Long;
  12. # use Env::Modify qw(:ksh source);
  13. # default values
  14. my $t_warn = 50;
  15. my $t_crit = 80;
  16. my $cpu_usage = -1;
  17. sub help {
  18. print "Usage: cpu_usage [-w <warning>] [-c <critical>]\n";
  19. print "-w <percent>: warning threshold to become yellow\n";
  20. print "-c <percent>: critical threshold to become red\n";
  21. exit 0;
  22. }
  23. GetOptions("help|h" => \&help,
  24. "w=i" => \$t_warn,
  25. "c=i" => \$t_crit);
  26. # Get CPU usage
  27. $ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
  28. open (MPSTAT, 'mpstat 1 1 -P ALL |') or die;
  29. while (<MPSTAT>) {
  30. if (/^.*\s+(\d+\.\d+)\s+$/) {
  31. $cpu_usage = 100 - $1; # 100% - %idle
  32. last;
  33. }
  34. }
  35. close(MPSTAT);
  36. $cpu_usage eq -1 and die 'Can\'t find CPU information';
  37. # Print short_text, full_text
  38. printf "%.0f%%\n", $cpu_usage;
  39. printf "%.0f%%\n", $cpu_usage;
  40. system("sudo source \"/home/kevin/.cache/wal/colors.sh\" 2> /dev/null");
  41. printf "%s\n", $ENV{'COLOR7'};
  42. # Print color, if needed
  43. # if ($cpu_usage >= $t_crit) {
  44. # print "#FF0000\n";
  45. # exit 33;
  46. # } elsif ($cpu_usage >= $t_warn) {
  47. # print "#FFFC00\n";
  48. # }
  49. exit 0;