- Temperature sensors can now set a 'max_threshold' value to color the

output red if exceeded.
This commit is contained in:
jasper 2012-10-09 17:12:31 +00:00
parent d7a52cacbb
commit 92c08b2ccf
5 changed files with 124 additions and 19 deletions

View File

@ -1,11 +1,11 @@
# $OpenBSD: Makefile,v 1.23 2012/10/09 16:02:07 jasper Exp $
# $OpenBSD: Makefile,v 1.24 2012/10/09 17:12:31 jasper Exp $
ONLY_FOR_ARCHS= ${APM_ARCHS}
COMMENT= generate a statusbar for use with i3/xmobar/dzen2
DISTNAME= i3status-2.6
REVISION= 14
REVISION= 15
CATEGORIES= x11 sysutils
HOMEPAGE= http://i3wm.org/i3status/

View File

@ -0,0 +1,24 @@
$OpenBSD: patch-i3status_c,v 1.1 2012/10/09 17:12:31 jasper Exp $
- Temperature sensors can now set a 'max_threshold' value to color the
output red if exceeded.
--- i3status.c.orig Tue Oct 9 20:35:06 2012
+++ i3status.c Tue Oct 9 20:35:15 2012
@@ -243,6 +243,7 @@ int main(int argc, char *argv[]) {
cfg_opt_t temp_opts[] = {
CFG_STR("format", "%degrees C", CFGF_NONE),
CFG_STR("path", NULL, CFGF_NONE),
+ CFG_INT("max_threshold", 75, CFGF_NONE),
CFG_END()
};
@@ -460,7 +461,7 @@ int main(int argc, char *argv[]) {
CASE_SEC_TITLE("cpu_temperature") {
SEC_OPEN_MAP("cpu_temperature");
- print_cpu_temperature_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"));
+ print_cpu_temperature_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getint(sec, "max_threshold"));
SEC_CLOSE_MAP;
}

View File

@ -1,14 +1,17 @@
$OpenBSD: patch-include_i3status_h,v 1.6 2012/10/09 16:02:07 jasper Exp $
$OpenBSD: patch-include_i3status_h,v 1.7 2012/10/09 17:12:31 jasper Exp $
Default to acpitz(4) for temperature readings, instead of cpu(4).
The acpitz(4) values are eventually used by the kernel to determine if the machine
is getting too hot.
- Default to acpitz(4) for temperature readings, instead of cpu(4).
The acpitz(4) values are eventually used by the kernel to determine if the machine
is getting too hot.
Other devices can be used by setting 'path' in the config file to the sysctl(3)
device node.
Other devices can be used by setting 'path' in the config file to the sysctl(3)
device node.
- Temperature sensors can now set a 'max_threshold' value to color the
output red if exceeded.
--- include/i3status.h.orig Wed Oct 3 13:44:44 2012
+++ include/i3status.h Tue Oct 9 19:39:37 2012
+++ include/i3status.h Tue Oct 9 20:36:02 2012
@@ -27,14 +27,8 @@ enum { O_DZEN2, O_XMOBAR, O_I3BAR, O_NONE } output_for
#define BATT_STATE "hw.acpi.battery.state"
@ -26,3 +29,12 @@ device node.
#endif
#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
@@ -143,7 +137,7 @@ void print_ddate(yajl_gen json_gen, char *buffer, cons
const char *get_ip_addr();
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format);
-void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format);
+void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, int);
void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format);
void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
void print_load(yajl_gen json_gen, char *buffer, const char *format);

View File

@ -0,0 +1,24 @@
$OpenBSD: patch-man_i3status_man,v 1.3 2012/10/09 17:12:31 jasper Exp $
- Temperature sensors can now set a 'max_threshold' value to color the
output red if exceeded.
--- man/i3status.man.orig Tue Oct 9 20:35:35 2012
+++ man/i3status.man Tue Oct 9 20:35:43 2012
@@ -224,11 +224,15 @@ colored red. The low_threshold type can be of threshol
=== CPU-Temperature
-Gets the temperature of the given thermal zone.
+Gets the temperature of the given thermal zone. It is possible to
+define a max_threshold that will color the temperature red in case the
+specified thermal zone is getting too hot. Defaults to 75 degrees C.
*Example order*: +cpu_temperature 0+
*Example format*: +T: %degrees °C+
+
+*Example max_threshold*: +42+
=== CPU Usage

View File

@ -1,15 +1,49 @@
$OpenBSD: patch-src_print_cpu_temperature_c,v 1.4 2012/10/09 16:02:07 jasper Exp $
$OpenBSD: patch-src_print_cpu_temperature_c,v 1.5 2012/10/09 17:12:31 jasper Exp $
Default to acpitz(4) for temperature readings, instead of cpu(4).
The acpitz(4) values are eventually used by the kernel to determine if the machine
is getting too hot.
- Default to acpitz(4) for temperature readings, instead of cpu(4).
The acpitz(4) values are eventually used by the kernel to determine if the machine
is getting too hot.
Other devices can be used by setting 'path' in the config file to the sysctl(3)
device node.
Other devices can be used by setting 'path' in the config file to the sysctl(3)
device node.
- Temperature sensors can now set a 'max_threshold' value to color the
output red if exceeded.
--- src/print_cpu_temperature.c.orig Wed Oct 3 13:44:44 2012
+++ src/print_cpu_temperature.c Tue Oct 9 19:41:02 2012
@@ -87,19 +87,17 @@ void print_cpu_temperature_info(yajl_gen json_gen, cha
+++ src/print_cpu_temperature.c Tue Oct 9 20:36:23 2012
@@ -23,6 +23,8 @@
#include <sys/sensors.h>
#include <errno.h>
#include <err.h>
+
+#define MUKTOC(v) ((v - 273150000) / 1000000.0)
#endif
static char *thermal_zone;
@@ -32,11 +34,11 @@ static char *thermal_zone;
* returns the temperature in degree celcius.
*
*/
-void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format) {
+void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, int max_threshold) {
#ifdef THERMAL_ZONE
const char *walk;
char *outwalk = buffer;
- static char buf[16];
+ bool colorful_output;
if (path == NULL)
asprintf(&thermal_zone, THERMAL_ZONE, zone);
@@ -54,6 +56,7 @@ void print_cpu_temperature_info(yajl_gen json_gen, cha
if (BEGINS_WITH(walk+1, "degrees")) {
#if defined(LINUX)
+ static char buf[16];
long int temp;
if (!slurp(path, buf, sizeof(buf)))
goto error;
@@ -87,21 +90,27 @@ void print_cpu_temperature_info(yajl_gen json_gen, cha
break;
goto error;
}
@ -33,9 +67,20 @@ device node.
+ continue;
+ }
}
outwalk += sprintf(outwalk, "%.2f", (sensor.value - 273150000) / 1000000.0 );
- outwalk += sprintf(outwalk, "%.2f", (sensor.value - 273150000) / 1000000.0 );
+ if ((int)MUKTOC(sensor.value) >= max_threshold) {
+ START_COLOR("color_bad");
+ colorful_output = true;
+ }
+
+ outwalk += sprintf(outwalk, "%.2f", MUKTOC(sensor.value));
+
+ if (colorful_output)
+ END_COLOR;
}
@@ -109,9 +107,9 @@ void print_cpu_temperature_info(yajl_gen json_gen, cha
}
}
@@ -109,9 +118,9 @@ void print_cpu_temperature_info(yajl_gen json_gen, cha
walk += strlen("degrees");
}
}