Storage info
This commit is contained in:
@@ -18,6 +18,9 @@
|
|||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#include <NetworkManager.h>
|
#include <NetworkManager.h>
|
||||||
#include <libvirt/libvirt.h>
|
#include <libvirt/libvirt.h>
|
||||||
|
#include <mntent.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
bool process_input(); // Returns true when the program needs to exit
|
bool process_input(); // Returns true when the program needs to exit
|
||||||
@@ -27,15 +30,17 @@ void app_deinit();
|
|||||||
|
|
||||||
struct App_Data
|
struct App_Data
|
||||||
{
|
{
|
||||||
f64 glib_iteration_t = 0;
|
f64 glib_iteration_t = -1;
|
||||||
f64 system_sample_t = 0;
|
f64 system_sample_t = -1;
|
||||||
f64 network_sample_t = 0;
|
f64 network_sample_t = -1;
|
||||||
f64 virt_sample_t = 0;
|
f64 virt_sample_t = -1;
|
||||||
|
f64 fs_sample_t = -1;
|
||||||
|
|
||||||
f64 glib_iteration_delta = 0.1;
|
f64 glib_iteration_delta = 0.1;
|
||||||
f64 system_sample_delta = 0.2;
|
f64 system_sample_delta = 0.2;
|
||||||
f64 network_sample_delta = 0.2;
|
f64 network_sample_delta = 0.2;
|
||||||
f64 virt_sample_delta = 0.5;
|
f64 virt_sample_delta = 0.5;
|
||||||
|
f64 fs_sample_delta = 1.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct System_Info
|
struct System_Info
|
||||||
@@ -90,9 +95,25 @@ struct Virt_Info
|
|||||||
Virt_Domain domains[32];
|
Virt_Domain domains[32];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FS_Entry
|
||||||
|
{
|
||||||
|
char device[256];
|
||||||
|
char directory[256];
|
||||||
|
char type[128];
|
||||||
|
u64 bytes_total;
|
||||||
|
u64 bytes_available;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FS_Info
|
||||||
|
{
|
||||||
|
s32 fs_count;
|
||||||
|
FS_Entry fs[32];
|
||||||
|
};
|
||||||
|
|
||||||
System_Info system_info;
|
System_Info system_info;
|
||||||
Network_Info network_info;
|
Network_Info network_info;
|
||||||
Virt_Info virt_info;
|
Virt_Info virt_info;
|
||||||
|
FS_Info fs_info;
|
||||||
App_Data app_data;
|
App_Data app_data;
|
||||||
|
|
||||||
|
|
||||||
@@ -250,7 +271,7 @@ bool process_input()
|
|||||||
|
|
||||||
void system_info_window()
|
void system_info_window()
|
||||||
{
|
{
|
||||||
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, v2{40,10}*engine.gui_scaling, 3, 6, 0.4*engine.gui_scaling);
|
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, v2{40,6}*engine.gui_scaling, 3, 4, 0.2*engine.gui_scaling);
|
||||||
gui_window_start(Rect{0.1*engine.gui_scaling, 0.1*engine.gui_scaling, layout.window_size.x, layout.window_size.y}, 0xabcdef01);
|
gui_window_start(Rect{0.1*engine.gui_scaling, 0.1*engine.gui_scaling, layout.window_size.x, layout.window_size.y}, 0xabcdef01);
|
||||||
|
|
||||||
// Host date and time
|
// Host date and time
|
||||||
@@ -281,8 +302,8 @@ void system_info_window()
|
|||||||
|
|
||||||
void network_window()
|
void network_window()
|
||||||
{
|
{
|
||||||
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, v2{40,12}*engine.gui_scaling, 3, 7, 0.4*engine.gui_scaling);
|
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, v2{40,18}*engine.gui_scaling, 3, 12, 0.2*engine.gui_scaling);
|
||||||
gui_window_start(Rect{0.1*engine.gui_scaling, 11*engine.gui_scaling, layout.window_size.x, layout.window_size.y}, 0xabcdef02);
|
gui_window_start(Rect{0.1*engine.gui_scaling, 7*engine.gui_scaling, layout.window_size.x, layout.window_size.y}, 0xabcdef02);
|
||||||
|
|
||||||
Gui_Context *ctx = &global_gui_state.default_context;
|
Gui_Context *ctx = &global_gui_state.default_context;
|
||||||
|
|
||||||
@@ -331,8 +352,8 @@ void network_window()
|
|||||||
|
|
||||||
void vm_window()
|
void vm_window()
|
||||||
{
|
{
|
||||||
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, v2{40,7}*engine.gui_scaling, 6, 4, 0.4*engine.gui_scaling);
|
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, v2{40,6}*engine.gui_scaling, 4, 4, 0.2*engine.gui_scaling);
|
||||||
gui_window_start(Rect{0.1*engine.gui_scaling, 24*engine.gui_scaling, layout.window_size.x, layout.window_size.y}, 0xabcdef03);
|
gui_window_start(Rect{0.1*engine.gui_scaling, 26*engine.gui_scaling, layout.window_size.x, layout.window_size.y}, 0xabcdef03);
|
||||||
|
|
||||||
Gui_Context *ctx = &global_gui_state.default_context;
|
Gui_Context *ctx = &global_gui_state.default_context;
|
||||||
|
|
||||||
@@ -392,6 +413,33 @@ void vm_window()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void fs_window()
|
||||||
|
{
|
||||||
|
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, v2{16,30}*engine.gui_scaling, 2, 20, 0.2*engine.gui_scaling);
|
||||||
|
gui_window_start(Rect{41*engine.gui_scaling, 0.1*engine.gui_scaling, layout.window_size.x, layout.window_size.y}, 0xabcdef04);
|
||||||
|
|
||||||
|
Gui_Context *ctx = &global_gui_state.default_context;
|
||||||
|
|
||||||
|
|
||||||
|
for(s32 i = 0; i < fs_info.fs_count; i++)
|
||||||
|
{
|
||||||
|
gui_id_stack_push(ctx, gui_id_from_pointer(ctx, fs_info.fs[i].device));
|
||||||
|
|
||||||
|
gui_button(layout.cell(2), fs_info.fs[i].device);
|
||||||
|
gui_button(layout.cell(1), fs_info.fs[i].directory);
|
||||||
|
gui_button(layout.cell(1), fs_info.fs[i].type);
|
||||||
|
char space[64]; snprintf(space, 64, "%.1f/%.1f GiB", (f32)(fs_info.fs[i].bytes_total - fs_info.fs[i].bytes_available) / (1024*1024*1024), (f32)fs_info.fs[i].bytes_total / (1024*1024*1024));
|
||||||
|
char percentage[64]; snprintf(percentage, 64, "%.1f%%", (f32)(fs_info.fs[i].bytes_total - fs_info.fs[i].bytes_available) / fs_info.fs[i].bytes_total * 100);
|
||||||
|
gui_button(layout.cell(1), space);
|
||||||
|
gui_button(layout.cell(1), percentage);
|
||||||
|
|
||||||
|
gui_id_stack_pop(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
gui_window_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NMClient *nmclient;
|
NMClient *nmclient;
|
||||||
virConnectPtr virt_connection;
|
virConnectPtr virt_connection;
|
||||||
|
|
||||||
@@ -500,6 +548,34 @@ void collect_new_data_if_needed()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(engine.time - app_data.fs_sample_t >= app_data.fs_sample_delta)
|
||||||
|
{
|
||||||
|
FILE *file = setmntent("/proc/mounts", "r");
|
||||||
|
|
||||||
|
fs_info.fs_count = 0;
|
||||||
|
for(struct mntent *ent = getmntent(file); ent != NULL; ent = getmntent(file))
|
||||||
|
{
|
||||||
|
strncpy(fs_info.fs[fs_info.fs_count].device, ent->mnt_fsname, 256);
|
||||||
|
strncpy(fs_info.fs[fs_info.fs_count].directory, ent->mnt_dir, 256);
|
||||||
|
strncpy(fs_info.fs[fs_info.fs_count].type, ent->mnt_type, 128);
|
||||||
|
fs_info.fs[fs_info.fs_count].bytes_total = 0;
|
||||||
|
fs_info.fs[fs_info.fs_count].bytes_available = 0;
|
||||||
|
|
||||||
|
struct stat s;
|
||||||
|
if(stat(ent->mnt_fsname, &s) != 0 || !S_ISBLK(s.st_mode))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
struct statvfs svfs;
|
||||||
|
if(statvfs(ent->mnt_dir, &svfs) == 0)
|
||||||
|
{
|
||||||
|
fs_info.fs[fs_info.fs_count].bytes_total = svfs.f_frsize * svfs.f_blocks;
|
||||||
|
fs_info.fs[fs_info.fs_count].bytes_available = svfs.f_frsize * svfs.f_bavail;
|
||||||
|
}
|
||||||
|
fs_info.fs_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
endmntent(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_gui()
|
void process_gui()
|
||||||
@@ -510,6 +586,7 @@ void process_gui()
|
|||||||
system_info_window();
|
system_info_window();
|
||||||
network_window();
|
network_window();
|
||||||
vm_window();
|
vm_window();
|
||||||
|
fs_window();
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_init()
|
void app_init()
|
||||||
|
|||||||
Reference in New Issue
Block a user