Add diskusage support
add support to show used disk for a given mountpoint
This commit is contained in:
parent
db63d3dc96
commit
21afb5a8f8
2 changed files with 25 additions and 2 deletions
|
@ -20,14 +20,18 @@ static const char timeformat[] = "%y-%m-%d %H:%M:%S";
|
||||||
/* bar update interval in seconds (smallest value = 1) */
|
/* bar update interval in seconds (smallest value = 1) */
|
||||||
static unsigned int update_interval = 1;
|
static unsigned int update_interval = 1;
|
||||||
|
|
||||||
|
/* mountpoint for diskusage */
|
||||||
|
static const char mountpath[] = "/home";
|
||||||
|
|
||||||
/* statusbar
|
/* statusbar
|
||||||
Possible arguments:
|
Possible arguments:
|
||||||
- battery (battery percentage)
|
- battery (battery percentage)
|
||||||
- cpu_temperature (cpu temperature in degrees)
|
- cpu_temperature (cpu temperature in degrees)
|
||||||
- cpu usage (cpu usage in percent)
|
- cpu usage (cpu usage in percent)
|
||||||
- datetime (date and time)
|
- datetime (date and time)
|
||||||
|
- diskusage (disk usage in percent)
|
||||||
- ram_usage (ram usage in percent)
|
- ram_usage (ram usage in percent)
|
||||||
- volume (alsa volume and mute status in percent)
|
- volume (alsa volume and mute status in percent)
|
||||||
- wifi_signal (wifi signal in percent) */
|
- wifi_signal (wifi signal in percent) */
|
||||||
#define FORMATSTRING "wifi %4s | bat %4s | cpu %4s %3s | ram %3s | vol %4s | %3s"
|
#define FORMATSTRING "wifi %4s | bat %4s | cpu %4s %3s | ram %3s | vol %4s | disk %4s | %3s"
|
||||||
#define ARGUMENTS wifi_signal, battery, cpu_usage, cpu_temperature, ram_usage, volume, datetime
|
#define ARGUMENTS wifi_signal, battery, cpu_usage, cpu_temperature, ram_usage, volume, diskusage, datetime
|
||||||
|
|
19
slstatus.c
19
slstatus.c
|
@ -10,6 +10,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -31,6 +32,7 @@ char *get_battery();
|
||||||
char *get_cpu_temperature();
|
char *get_cpu_temperature();
|
||||||
char *get_cpu_usage();
|
char *get_cpu_usage();
|
||||||
char *get_datetime();
|
char *get_datetime();
|
||||||
|
char *get_diskusage();
|
||||||
char *get_ram_usage();
|
char *get_ram_usage();
|
||||||
char *get_volume();
|
char *get_volume();
|
||||||
char *get_wifi_signal();
|
char *get_wifi_signal();
|
||||||
|
@ -204,6 +206,20 @@ get_datetime()
|
||||||
return smprintf("%s", buf);
|
return smprintf("%s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* disk usage percentage */
|
||||||
|
char *
|
||||||
|
get_diskusage()
|
||||||
|
{
|
||||||
|
struct statvfs fs;
|
||||||
|
float perc = 0;
|
||||||
|
if (statvfs(mountpath, &fs) < 0) {
|
||||||
|
fprintf(stderr, "Could not get filesystem info.\n");
|
||||||
|
return smprintf("n/a");
|
||||||
|
}
|
||||||
|
perc = 1.0f - ((float)fs.f_bavail/(float)fs.f_blocks);
|
||||||
|
return smprintf("%2f%%", perc);
|
||||||
|
}
|
||||||
|
|
||||||
/* ram percentage */
|
/* ram percentage */
|
||||||
char *
|
char *
|
||||||
get_ram_usage()
|
get_ram_usage()
|
||||||
|
@ -343,6 +359,7 @@ main()
|
||||||
char *cpu_temperature = NULL;
|
char *cpu_temperature = NULL;
|
||||||
char *cpu_usage = NULL;
|
char *cpu_usage = NULL;
|
||||||
char *datetime = NULL;
|
char *datetime = NULL;
|
||||||
|
char *diskusage = NULL;
|
||||||
char *ram_usage = NULL;
|
char *ram_usage = NULL;
|
||||||
char *volume = NULL;
|
char *volume = NULL;
|
||||||
char *wifi_signal = NULL;
|
char *wifi_signal = NULL;
|
||||||
|
@ -366,6 +383,7 @@ main()
|
||||||
cpu_temperature = get_cpu_temperature();
|
cpu_temperature = get_cpu_temperature();
|
||||||
cpu_usage = get_cpu_usage();
|
cpu_usage = get_cpu_usage();
|
||||||
datetime = get_datetime();
|
datetime = get_datetime();
|
||||||
|
diskusage = get_diskusage();
|
||||||
ram_usage = get_ram_usage();
|
ram_usage = get_ram_usage();
|
||||||
volume = get_volume();
|
volume = get_volume();
|
||||||
wifi_signal = get_wifi_signal();
|
wifi_signal = get_wifi_signal();
|
||||||
|
@ -379,6 +397,7 @@ main()
|
||||||
free(cpu_temperature);
|
free(cpu_temperature);
|
||||||
free(cpu_usage);
|
free(cpu_usage);
|
||||||
free(datetime);
|
free(datetime);
|
||||||
|
free(diskusage);
|
||||||
free(ram_usage);
|
free(ram_usage);
|
||||||
free(volume);
|
free(volume);
|
||||||
free(wifi_signal);
|
free(wifi_signal);
|
||||||
|
|
Loading…
Reference in a new issue