Skip to content

Instantly share code, notes, and snippets.

@qolarnix
Created November 27, 2022 18:39
Show Gist options
  • Save qolarnix/9a772f100673525fc21817fe97f7953f to your computer and use it in GitHub Desktop.
Save qolarnix/9a772f100673525fc21817fe97f7953f to your computer and use it in GitHub Desktop.
FreeBSD Polybar Module - CPU
#!/usr/local/bin/php
<?php
$iostat_cpu_usr = shell_exec("iostat -c 2 | awk '{print $12}'");
$iostat_cpu_sys = shell_exec("iostat -c 2 | awk '{print $14}'");
$cpu_usr_arr = explode("\n", $iostat_cpu_usr);
$cpu_sys_arr = explode("\n", $iostat_cpu_sys);
$cpu_usr = intval($cpu_usr_arr[3]);
$cpu_sys = intval($cpu_sys_arr[3]);
$cpu_total = $cpu_usr + $cpu_sys;
echo 'CPU: '.$cpu_total.'%';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment