Skip to content

Commit

Permalink
Add support to return CPU and fans data in live stats
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Oct 26, 2024
1 parent 851f348 commit d8f212a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 9 deletions.
8 changes: 4 additions & 4 deletions authentic-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ sub get_sysinfo_vars
($cpucores > 1 ? ($theme_text{'theme_global_core'} . ' ' . (int($t->{'core'}) + 1) . ': ') : '')
.
( get_module_config_data('system-status', 'collect_units') ?
(int(($t->{'temp'} * 9.0 / 5) + 32) . "°F") :
(int($t->{'temp'}) . '°C ')
(int(($t->{'temp'} * 9.0 / 5) + 32) . " °F") :
(int($t->{'temp'}) . ' °C ')
) .
'</span>';
}
Expand Down Expand Up @@ -935,8 +935,8 @@ sub get_sysinfo_vars
$hdd_temperature .= '<span class="badge-custom badge-drivestatus" data-stats="drive">' . $short . ': '
.
( get_module_config_data('system-status', 'collect_units') ?
(int(($t->{'temp'} * 9.0 / 5) + 32) . "&#176;F") :
(int($t->{'temp'}) . '&#176;C ')
(int(($t->{'temp'} * 9.0 / 5) + 32) . " &#176;F") :
(int($t->{'temp'}) . ' &#176;C ')
) .
$emsg . '</span>';
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/stats/stats.min.js

Large diffs are not rendered by default.

Binary file modified extensions/stats/stats.min.js.gz
Binary file not shown.
83 changes: 83 additions & 0 deletions extensions/stats/stats.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const stats = {
dashboard: "system-status",
slider: "info-container",
piechart: "piechart",
defaultClassLabel: "bg-semi-transparent",
defaultSliderClassLabel: "bg-semi-transparent-dark",
},
// Get current data to submit to the socket
getSocketDefs: function () {
Expand Down Expand Up @@ -289,6 +291,87 @@ const stats = {
}
}

// Update sensors data
if (target === "sensors" && vo) {
// Iterate through sensors
Object.entries(vo).forEach(([sensor, value]) => {
let this_ = this,
$lb1 = $(`#${this.selector.dashboard} span[data-stats="${sensor}"]`),
$lb2 = $(`.${this.selector.slider} span[data-stats="${sensor}"]`);

if ($lb1 && $lb1.length) {
let lb_count1 = $lb1.length,
lb_count2 = $lb2.length;

// Sort the values based on 'fan' or 'core' field
value.sort((a, b) =>
sensor === "fans" ? a.fan - b.fan : a.core - b.core
);

// Function to update individual label
const updateLabel = function ($label, data, isSingleLabel, sideSlider) {
// Update the label text based on count condition
if (isSingleLabel) {
// Replace only the numeric part, preserving unit (°C or RPM)
$label.html(function (_, html) {
const iSFahrenheit = html.includes("°F");
return html.replace(
/\d+/,
sensor === "fans"
? data.rpm
: (iSFahrenheit ? Math.round((data.temp * 9) / 5 + 32) : data.temp));
});
} else {
// Replace the numeric part after the colon, preserving prefix and unit
$label.html(function (_, html) {
const iSFahrenheit = html.includes("°F");
return html.replace(
/: \d+/,
`: ${sensor === "fans" ? data.rpm :
(iSFahrenheit ? Math.round((data.temp * 9) / 5 + 32) : data.temp)}`
);
});
}

const label_text = $label.text().replace(/.*?\d+:\s*/, "");
let className =
HTML.label.textMaxLevels(sensor, label_text) ||
(sideSlider
? this_.selector.defaultSliderClassLabel
: this_.selector.defaultClassLabel);
if (sideSlider && className === this_.selector.defaultClassLabel) {
className = this_.selector.defaultSliderClassLabel;
}
// Update class based on current label text
$label
.removeClass((i, c) => (c.match(/\bbg-\S+/g) || []).join(" "))
.addClass(className);
};
// Handle $lb1 labels
if (lb_count1 === 1) {
updateLabel($lb1, value[0], true);
} else {
// Handle multiple labels for $lb1
$lb1.each((index, el) => {
if (value[index]) {
updateLabel($(el), value[index], false);
}
});
}
// Handle $lb2 labels similarly
if (lb_count2 === 1) {
updateLabel($lb2, value[0], true, true);
} else {
$lb2.each((index, el) => {
if (value[index]) {
updateLabel($(el), value[index], false, true);
}
});
}
}
});
}

// Draw history graphs
if (cached) {
let lds = `${this.selector.chart.container.parent}-${this.selector.collapse}`,
Expand Down
3 changes: 1 addition & 2 deletions stats-lib-funcs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ sub get_stats_now
my ($cpu, $fans) = defined(&proc::get_current_cpu_data) ?
proc::get_current_cpu_data() : (undef, undef);
if ($cpu || $fans) {
$data{'temp'} = [{c => $cpu, f => $fans}];
# $gadd->('temp', [{c => $cpu, f => $fans}]);
$data{'sensors'} = [{cpu => $cpu, fans => $fans}];
}
}
# Reverse output for LTR users
Expand Down
2 changes: 1 addition & 1 deletion unauthenticated/css/bundle.min.css

Large diffs are not rendered by default.

Binary file modified unauthenticated/css/bundle.min.css.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion unauthenticated/js/bundle.min.js

Large diffs are not rendered by default.

Binary file modified unauthenticated/js/bundle.min.js.gz
Binary file not shown.

0 comments on commit d8f212a

Please sign in to comment.