Computes HDD activity (use) and storage (use)

This commit is contained in:
Raymundo Cassani 2020-05-31 10:02:22 -04:00
parent 4cac0ce8f8
commit 55686f931c

View File

@ -82,6 +82,8 @@ MyDesklet.prototype = {
this.values = new Array(this.n_values).fill(0.0); this.values = new Array(this.n_values).fill(0.0);
this.cpu_cpu_tot = 0; this.cpu_cpu_tot = 0;
this.cpu_cpu_idl = 0; this.cpu_cpu_idl = 0;
this.hdd_cpu_tot = 0;
this.hdd_hdd_tot = 0;
// set colors // set colors
switch (this.type) { switch (this.type) {
case "cpu": case "cpu":
@ -143,12 +145,12 @@ MyDesklet.prototype = {
let dir_path = decodeURIComponent(this.filesystem.replace("file://", "").trim()); let dir_path = decodeURIComponent(this.filesystem.replace("file://", "").trim());
if(dir_path == null || dir_path == "") dir_path = "/"; if(dir_path == null || dir_path == "") dir_path = "/";
let hdd_values = this.get_hdd_values(dir_path); let hdd_values = this.get_hdd_values(dir_path);
let hdd_use = hdd_values[0]; //already in % let hdd_use = Math.min(hdd_values[1], 100); //already in %
value = hdd_use / 100; value = hdd_use / 100;
text1 = "HDD"; text1 = hdd_values[0];
text2 = Math.round(hdd_use).toString() + "% " text2 = Math.round(hdd_use).toString() + "% "
+ hdd_values[2].toFixed(1) + " GB free of " + hdd_values[3].toFixed(1) + " GB free of "
+ hdd_values[1].toFixed(1) + " GB"; + hdd_values[2].toFixed(1) + " GB";
break; break;
} }
@ -278,32 +280,42 @@ MyDesklet.prototype = {
get_hdd_values: function(dir_path) { get_hdd_values: function(dir_path) {
let subprocess = new Gio.Subprocess({ let subprocess = new Gio.Subprocess({
argv: ['/bin/sh', '-c', '/bin/df ' + dir_path + ' | grep Filesystem -w -A1'], argv: ['/bin/df', dir_path],
flags: Gio.SubprocessFlags.STDOUT_PIPE, flags: Gio.SubprocessFlags.STDOUT_PIPE,
}); });
subprocess.init(null); subprocess.init(null);
let gb = 1048576; // 1 GB = 1,048,576 kB
let [, out] = subprocess.communicate_utf8(null, null); // get full output from stdout let [, out] = subprocess.communicate_utf8(null, null); // get full output from stdout
let df_line = out.split(/\r?\n/)[1]; // get only one line let df_line = out.match(/.+/g)[1];
let df_values = df_line.split(/\s+/); // split by space let df_values = df_line.split(/\s+/); // split by space
// values for partition space // values for partition space
let hdd_tot = (parseFloat(df_values[3]) + parseFloat(df_values[2]) ) / gb; let hdd_tot = (parseFloat(df_values[3]) + parseFloat(df_values[2]) ) / GB_TO_KB;
let hdd_fre = parseFloat(df_values[3]) / gb; let hdd_fre = parseFloat(df_values[3]) / GB_TO_KB;
// utilization of partition // utilization of partition
let fs = df_values[0]; let dev_fs = df_values[0];
let subprocess2 = new Gio.Subprocess({ let fs = dev_fs.split(/\/+/)[2];
argv: ['/bin/sh', '-c', 'iostat ' + fs + ' -ydx 1 1 | grep Device -w -A1'], let hdd_use = this.get_hdd_use(fs);
flags: Gio.SubprocessFlags.STDOUT_PIPE, return [fs, hdd_use, hdd_tot, hdd_fre];
}); },
subprocess2.init(null);
let [, out2] = subprocess2.communicate_utf8(null, null); // get full output from stdout get_hdd_use: function(fs) {
global.log(out2) let cpu_line = Cinnamon.get_file_contents_utf8_sync("/proc/stat").match(/cpu\s.+/)[0];
let iostat_line = out2.split(/\r?\n/)[1]; // get only one line let re = new RegExp(fs + '.+');
let iostat_values = iostat_line.split(/\s+/); // split by space let hdd_line = Cinnamon.get_file_contents_utf8_sync("/proc/diskstats").match(re)[0];
let hdd_use = parseFloat(iostat_values[iostat_values.length-1]); // get total CPU time
//let hdd_use = 10; let cpu_values = cpu_line.split(/\s+/);
//global.log(hdd_use) let hdd_cpu_tot = 0;
return [hdd_use, hdd_tot, hdd_fre]; for (let i = 1; i<10; i++){
hdd_cpu_tot += parseFloat(cpu_values[i])
}
// get total of IO times
let hdd_hdd_tot = hdd_line.split(/\s+/)[10];
// update HHD use
let hdd_use = 100 * (hdd_hdd_tot - this.hdd_hdd_tot) / (hdd_cpu_tot - this.hdd_cpu_tot);
// update global values
this.hdd_cpu_tot = hdd_cpu_tot;
this.hdd_hdd_tot = hdd_hdd_tot;
return hdd_use;
}, },
parse_rgba_seetings: function(color_str) { parse_rgba_seetings: function(color_str) {