diff --git a/i3/i3blocks.conf b/i3/i3blocks.conf index a4b6f19..634fb69 100644 --- a/i3/i3blocks.conf +++ b/i3/i3blocks.conf @@ -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=📅 diff --git a/i3/i3blocks/bandwidth b/i3/i3blocks/bandwidth new file mode 100755 index 0000000..26bb904 --- /dev/null +++ b/i3/i3blocks/bandwidth @@ -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 \" %%-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); + } +} +' diff --git a/i3/i3blocks/cpu_usage b/i3/i3blocks/cpu_usage new file mode 100755 index 0000000..60b9c82 Binary files /dev/null and b/i3/i3blocks/cpu_usage differ diff --git a/i3/i3blocks/gpu-load b/i3/i3blocks/gpu-load new file mode 100755 index 0000000..4d3ff0d --- /dev/null +++ b/i3/i3blocks/gpu-load @@ -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 . + +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 ] [-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); + +# 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; + $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; diff --git a/i3/i3blocks/load_average b/i3/i3blocks/load_average new file mode 100755 index 0000000..37a5c71 --- /dev/null +++ b/i3/i3blocks/load_average @@ -0,0 +1,34 @@ +#!/bin/sh +# Copyright (C) 2014 Julien Bonjean + +# 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 . + +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; + } + } +'