Add i3blocks-contrib stuff
Stuff pulled from [i3blocks-contrib](https://github.com/vivien/i3blocks-contrib) and Luke Smith's [dotfiles](https://github.com/LukeSmithxyz/voidrice/tree/master/.scripts/statusbar) the contents may have been modified to work on my system
This commit is contained in:
parent
844f1944c2
commit
b68268b5a5
@ -29,21 +29,37 @@ command=~/bin/i3blocks/$BLOCK_NAME
|
||||
separator_block_width=15
|
||||
markup=pango
|
||||
|
||||
[disk]
|
||||
interval=60
|
||||
command=~/bin/i3blocks/disk /
|
||||
[gpu-load]
|
||||
interval=15
|
||||
label=⎚
|
||||
|
||||
[disk]
|
||||
interval=60
|
||||
command=~/bin/i3blocks/disk /home 🏠
|
||||
[load_average]
|
||||
interval=15
|
||||
label=⨏
|
||||
|
||||
[cpu_usage]
|
||||
interval=persist
|
||||
label=💻
|
||||
|
||||
[cpu]
|
||||
interval=15
|
||||
label=🌡
|
||||
|
||||
[memory]
|
||||
interval=30
|
||||
label=🧠
|
||||
|
||||
[cpu]
|
||||
interval=15
|
||||
label=💻
|
||||
[bandwidth]
|
||||
interval=persist
|
||||
#label=
|
||||
|
||||
#[disk]
|
||||
#interval=60
|
||||
#command=~/bin/i3blocks/disk /
|
||||
|
||||
#[disk]
|
||||
#interval=60
|
||||
#command=~/bin/i3blocks/disk /home 🏠
|
||||
|
||||
[clock]
|
||||
label=📅
|
||||
|
104
i3/i3blocks/bandwidth
Executable file
104
i3/i3blocks/bandwidth
Executable file
@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright (C) 2015 James Murphy
|
||||
# Licensed under the terms of the GNU GPL v2 only.
|
||||
#
|
||||
# i3blocks blocklet script to monitor bandwidth usage
|
||||
|
||||
iface="${BLOCK_INSTANCE}"
|
||||
iface="${IFACE:-$iface}"
|
||||
dt="${DT:-3}"
|
||||
unit="${UNIT:-Mb}"
|
||||
LABEL="${LABEL:- }" # down arrow up arrow
|
||||
printf_command="${PRINTF_COMMAND:-"printf \"${LABEL}%-5.1f/%5.1f %s/s\\n\", rx, wx, unit;"}"
|
||||
|
||||
function default_interface {
|
||||
ip route | awk '/^default via/ {print $5; exit}'
|
||||
}
|
||||
|
||||
function check_proc_net_dev {
|
||||
if [ ! -f "/proc/net/dev" ]; then
|
||||
echo "/proc/net/dev not found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function list_interfaces {
|
||||
check_proc_net_dev
|
||||
echo "Interfaces in /proc/net/dev:"
|
||||
grep -o "^[^:]\\+:" /proc/net/dev | tr -d " :"
|
||||
}
|
||||
|
||||
while getopts i:t:u:p:lh opt; do
|
||||
case "$opt" in
|
||||
i) iface="$OPTARG" ;;
|
||||
t) dt="$OPTARG" ;;
|
||||
u) unit="$OPTARG" ;;
|
||||
p) printf_command="$OPTARG" ;;
|
||||
l) list_interfaces && exit 0 ;;
|
||||
h) printf \
|
||||
"Usage: bandwidth3 [-i interface] [-t time] [-u unit] [-p printf_command] [-l] [-h]
|
||||
Options:
|
||||
-i\tNetwork interface to measure. Default determined using \`ip route\`.
|
||||
-t\tTime interval in seconds between measurements. Default: 3
|
||||
-u\tUnits to measure bytes in. Default: Mb
|
||||
\tAllowed units: Kb, KB, Mb, MB, Gb, GB, Tb, TB
|
||||
\tUnits may have optional it/its/yte/ytes on the end, e.g. Mbits, KByte
|
||||
-p\tAwk command to be called after a measurement is made.
|
||||
\tDefault: printf \"<span font='FontAwesome'> </span>%%-5.1f/%%5.1f %%s/s\\\\n\", rx, wx, unit;
|
||||
\tExposed variables: rx, wx, tx, unit, iface
|
||||
-l\tList available interfaces in /proc/net/dev
|
||||
-h\tShow this help text
|
||||
" && exit 0;;
|
||||
esac
|
||||
done
|
||||
|
||||
check_proc_net_dev
|
||||
|
||||
iface="${iface:-$(default_interface)}"
|
||||
while [ -z "$iface" ]; do
|
||||
echo No default interface
|
||||
sleep "$dt"
|
||||
iface=$(default_interface)
|
||||
done
|
||||
|
||||
case "$unit" in
|
||||
Kb|Kbit|Kbits) bytes_per_unit=$((1024 / 8));;
|
||||
KB|KByte|KBytes) bytes_per_unit=$((1024));;
|
||||
Mb|Mbit|Mbits) bytes_per_unit=$((1024 * 1024 / 8));;
|
||||
MB|MByte|MBytes) bytes_per_unit=$((1024 * 1024));;
|
||||
Gb|Gbit|Gbits) bytes_per_unit=$((1024 * 1024 * 1024 / 8));;
|
||||
GB|GByte|GBytes) bytes_per_unit=$((1024 * 1024 * 1024));;
|
||||
Tb|Tbit|Tbits) bytes_per_unit=$((1024 * 1024 * 1024 * 1024 / 8));;
|
||||
TB|TByte|TBytes) bytes_per_unit=$((1024 * 1024 * 1024 * 1024));;
|
||||
*) echo Bad unit "$unit" && exit 1;;
|
||||
esac
|
||||
|
||||
scalar=$((bytes_per_unit * dt))
|
||||
init_line=$(cat /proc/net/dev | grep "^[ ]*$iface:")
|
||||
if [ -z "$init_line" ]; then
|
||||
echo Interface not found in /proc/net/dev: "$iface"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
init_received=$(awk '{print $2}' <<< $init_line)
|
||||
init_sent=$(awk '{print $10}' <<< $init_line)
|
||||
|
||||
(while true; do cat /proc/net/dev; sleep "$dt"; done) |\
|
||||
stdbuf -oL grep "^[ ]*$iface:" |\
|
||||
awk -v scalar="$scalar" -v unit="$unit" -v iface="$iface" '
|
||||
BEGIN{old_received='"$init_received"';old_sent='"$init_sent"'}
|
||||
{
|
||||
received=$2
|
||||
sent=$10
|
||||
rx=(received-old_received)/scalar;
|
||||
wx=(sent-old_sent)/scalar;
|
||||
tx=rx+wr;
|
||||
old_received=received;
|
||||
old_sent=sent;
|
||||
if(rx >= 0 && wx >= 0){
|
||||
'"$printf_command"';
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
'
|
BIN
i3/i3blocks/cpu_usage
Executable file
BIN
i3/i3blocks/cpu_usage
Executable file
Binary file not shown.
67
i3/i3blocks/gpu-load
Executable file
67
i3/i3blocks/gpu-load
Executable file
@ -0,0 +1,67 @@
|
||||
#! /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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use Getopt::Long;
|
||||
|
||||
# default values
|
||||
my $t_warn = $ENV{T_WARN} || 70;
|
||||
my $t_crit = $ENV{T_CRIT} || 90;
|
||||
my $gpu_usage = -1;
|
||||
my $gpu_mem = -1;
|
||||
my $gpu_video = -1;
|
||||
my $gpu_pcie = -1;
|
||||
|
||||
sub help {
|
||||
print "Usage: gpu-load [-w <warning>] [-c <critical>]\n";
|
||||
print "-w <percent>: warning threshold to become amber\n";
|
||||
print "-c <percent>: critical threshold to become red\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
GetOptions("help|h" => \&help,
|
||||
"w=i" => \$t_warn,
|
||||
"c=i" => \$t_crit);
|
||||
|
||||
# Get GPU usage from nvidia-settings
|
||||
open (NVS, 'nvidia-settings -q GPUUtilization -t |') or die;
|
||||
while (<NVS>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
close(NVS);
|
||||
|
||||
$gpu_usage eq -1 and die 'Can\'t find GPU information';
|
||||
|
||||
# Print full_text, short_text
|
||||
printf "%.0f%% %.0f%% %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie;
|
||||
printf "%.0f%%\n", $gpu_usage;
|
||||
|
||||
# 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;
|
||||
} elsif ($gpu_usage >= $t_warn || $gpu_mem >= $t_warn || $gpu_video >= $t_warn || $gpu_pcie >= $t_warn) {
|
||||
print "#FFBF00\n";
|
||||
}
|
||||
|
||||
exit 0;
|
34
i3/i3blocks/load_average
Executable file
34
i3/i3blocks/load_average
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
||||
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
load="$(cut -d ' ' -f1 /proc/loadavg)"
|
||||
cpus="$(nproc)"
|
||||
|
||||
# full text
|
||||
echo "$load"
|
||||
|
||||
# short text
|
||||
echo "$load"
|
||||
|
||||
# color if load is too high
|
||||
awk -v cpus=$cpus -v cpuload=$load '
|
||||
BEGIN {
|
||||
if (cpus <= cpuload) {
|
||||
print "#FF0000";
|
||||
exit 33;
|
||||
}
|
||||
}
|
||||
'
|
Loading…
Reference in New Issue
Block a user