-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
218 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
jnfo (1.0.1-1) unstable; urgency=medium | ||
|
||
* Add filesystem statistics | ||
|
||
-- Giorgio Tropiano <[email protected]> Sun, 13 Jun 2021 13:25:54 +0200 | ||
|
||
jnfo (1.0.0-1) unstable; urgency=medium | ||
|
||
* Initial release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#pragma once | ||
|
||
#include <string.h> | ||
#include <sys/statvfs.h> | ||
|
||
#include "defines.h" | ||
#include "formatter.h" | ||
|
||
typedef struct { | ||
string name; | ||
string path; | ||
unsigned long capacity; | ||
unsigned long free; | ||
unsigned long available; | ||
unsigned long used; | ||
unsigned long nonroot_total; | ||
} fs_t; | ||
|
||
vector<fs_t> get_filesystem() { | ||
vector<fs_t> result; | ||
|
||
FILE* fd = fopen(MTAB_PATH, "r"); | ||
|
||
if (fd == NULL) { | ||
std::cerr << "cannot open " << MTAB_PATH << std::endl; | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
char line[128]; | ||
char part_name[32]; | ||
char mount_path[32]; | ||
|
||
while (fgets(line, 128, fd) != NULL) { | ||
// parse line | ||
if (sscanf(line, "%s %s", part_name, mount_path) == 2) { | ||
int num_slashes = 0; | ||
char* ptr = mount_path; | ||
|
||
// count forward slashes in path | ||
while ((ptr = strchr(ptr, '/')) != NULL) { | ||
num_slashes++, ptr++; | ||
} | ||
|
||
if (num_slashes == 1) { | ||
// consider filesystem | ||
fs_t filesystem; | ||
filesystem.path = mount_path; | ||
#if __APPLE__ | ||
if (filesystem.path == "/") { | ||
#endif | ||
filesystem.name = part_name; | ||
|
||
struct statvfs vfs; | ||
|
||
int err = statvfs(filesystem.path.c_str(), &vfs); | ||
if (err != 0) { | ||
std::cerr << "Cannot stat filesystem." << std::endl; | ||
std::cerr << err << std::endl; | ||
fclose(fd); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
filesystem.capacity = vfs.f_blocks * vfs.f_frsize; | ||
filesystem.free = vfs.f_bfree * vfs.f_frsize; | ||
filesystem.available = vfs.f_bavail * vfs.f_frsize; | ||
|
||
filesystem.used = filesystem.capacity - filesystem.free; | ||
filesystem.nonroot_total = filesystem.used + filesystem.available; | ||
|
||
result.push_back(filesystem); | ||
} | ||
|
||
#if __APPLE__ | ||
} | ||
#endif | ||
} else { | ||
std::cerr << "cannot parse " << MTAB_PATH << std::endl; | ||
fclose(fd); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
fclose(fd); | ||
|
||
return result; | ||
} | ||
|
||
void pretty_print(vector<fs_t> info, bool summary = false) { | ||
fmt_measure_t fmt; | ||
|
||
pretty("Filesystem", "", 0); | ||
|
||
for (const auto& fs : info) { | ||
if (summary) { | ||
if (fs.path == "/") { | ||
fmt = format_storage(fs.capacity, 2); | ||
pretty("Capacity", fmt.value.c_str(), 1, NUMBER, 0, fmt.unit.c_str()); | ||
|
||
pretty("Used", format_percent(fs.used, fs.nonroot_total, 0).c_str(), 1, PERCENT, 4); | ||
break; | ||
} | ||
} else { | ||
pretty("Name", fs.name.c_str(), 2, STRING, 5, "", true); | ||
pretty("Path", fs.path.c_str(), 2, STRING, 5); | ||
|
||
fmt = format_storage(fs.capacity, 2); | ||
pretty("Capacity", fmt.value.c_str(), 2, NUMBER, 1, fmt.unit.c_str()); | ||
|
||
fmt = format_storage(fs.free, 2); | ||
pretty("Free", fmt.value.c_str(), 2, NUMBER, 5, fmt.unit.c_str()); | ||
|
||
fmt = format_storage(fs.available, 2); | ||
pretty("Available", fmt.value.c_str(), 2, NUMBER, 0, fmt.unit.c_str()); | ||
|
||
pretty("Used", format_percent(fs.used, fs.nonroot_total, 0).c_str(), 2, PERCENT, 5); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/dev/mmcblk0p1 / ext4 rw,relatime,data=ordered 0 0 | ||
proc /proc proc rw,relatime 0 0 | ||
sysfs /sys sysfs rw,relatime 0 0 | ||
none /dev devtmpfs rw,relatime,size=1784284k,nr_inodes=446071,mode=755 0 0 | ||
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 | ||
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 | ||
tmpfs /run tmpfs rw,nosuid,nodev,mode=755 0 0 | ||
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0 | ||
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0 | ||
cgroup /sys/fs/cgroup/unified cgroup2 rw,nosuid,nodev,noexec,relatime 0 0 | ||
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,name=systemd 0 0 | ||
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 | ||
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0 | ||
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0 | ||
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0 | ||
cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0 | ||
cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 | ||
cgroup /sys/fs/cgroup/debug cgroup rw,nosuid,nodev,noexec,relatime,debug 0 0 | ||
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0 | ||
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_cls,net_prio 0 0 | ||
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0 | ||
cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0 | ||
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0 | ||
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=27,pgrp=1,timeout=0,minproto=5,maxproto=5,direct 0 0 | ||
hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0 | ||
sunrpc /run/rpc_pipefs rpc_pipefs rw,relatime 0 0 | ||
mqueue /dev/mqueue mqueue rw,relatime 0 0 | ||
debugfs /sys/kernel/debug debugfs rw,relatime 0 0 | ||
configfs /sys/kernel/config configfs rw,relatime 0 0 | ||
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=405924k,mode=700,uid=1000,gid=1000 0 0 | ||
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0 |