1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-05 21:07:52 +00:00

Added support for APC UPS daemon monitoring.

This commit is contained in:
Jaromir Smrcek 2009-05-10 12:58:06 -06:00 committed by Brenden Matthews
parent 7268dd3cc6
commit cf2c61b588
8 changed files with 309 additions and 7 deletions

View File

@ -1,3 +1,6 @@
2009-05-10
* Added support for APC UPS daemon monitoring
2009-05-09
* Allow the use of '#' for comments within text area (can be escaped with
'\#'

View File

@ -213,6 +213,26 @@ dnl
dnl Math
dnl
dnl
dnl Apcupsd
dnl
AC_ARG_ENABLE([apcupsd],
AC_HELP_STRING([--disable-apcupsd],
[disable if you do not want apcupsd support @<:@default=yes@:>@]),
[want_apcupsd="$enableval"], [want_apcupsd=yes])
AM_CONDITIONAL(BUILD_APCUPSD, test x$want_apcupsd = xyes)
if test x$want_apcupsd = xyes; then
if test x"$uname" != xLinux; then
AC_MSG_NOTICE([apcupsd not supported on $uname... disabling])
want_apcupsd=no
else
AC_DEFINE(APCUPSD, 1, [Define if you want apcupsd support])
fi
fi
AC_ARG_ENABLE([math],
AC_HELP_STRING([--disable-math], [disable if you do not want math support @<:@default=yes@:>@]),
[want_math="$enableval"], [want_math=yes])
@ -767,4 +787,5 @@ $PACKAGE $VERSION configured successfully:
eve-online: $want_eve
config-output: $want_config_output
ALSA mixer: $want_alsa
apcupsd: $want_apcupsd
EOF

View File

@ -85,6 +85,134 @@
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd</option></command>
<option>host</option>
<option>port</option>
</term>
<listitem>
Sets up the connection to apcupsd daemon. Prints nothing, defaults to localhost:3551
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_name</option></command>
</term>
<listitem>
Prints the UPS user-defined name.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_model</option></command>
</term>
<listitem>
Prints the model of the UPS.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_upsmode</option></command>
</term>
<listitem>
Prints the UPS mode (e.g. standalone).
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_cable</option></command>
</term>
<listitem>
Prints the UPS connection type.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_status</option></command>
</term>
<listitem>
Prints current status (on-line, on-battery).
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_linev</option></command>
</term>
<listitem>
Nominal input voltage.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_load</option></command>
</term>
<listitem>
Current load in percent.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_loadbar</option></command>
</term>
<listitem>
Bar showing current load.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_loadgraph</option></command>
</term>
<listitem>
History graph of current load.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_charge</option></command>
</term>
<listitem>
Current battery capacity in percent.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_timeleft</option></command>
</term>
<listitem>
Time left to run on battery.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_temp</option></command>
</term>
<listitem>
Current internal temperature.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apcupsd_lastxfer</option></command>
</term>
<listitem>
Reason for last transfer from line to battery.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>apm_adapter</option></command>

View File

@ -111,6 +111,10 @@ if BUILD_NVIDIA
nvidia = nvidia.c nvidia.h
endif
if BUILD_APCUPSD
apcupsd = apcupsd.c apcupsd.h
endif
conky_SOURCES = \
$(config_output) \
$(config_cookie) \
@ -124,6 +128,7 @@ conky_SOURCES = \
$(freebsd) \
fs.c \
$(hddtemp) \
$(apcupsd) \
$(linux) \
logging.h \
$(nvidia) \
@ -175,6 +180,8 @@ EXTRA_DIST = \
fs.h \
hddtemp.c \
hddtemp.h \
apcupsd.c \
apcupsd.h \
linux.c \
linux.h \
libmpdclient.c \

View File

@ -323,7 +323,7 @@ static double last_fs_update;
unsigned long long need_mask;
int no_buffers;
#define NEED(a) ((need_mask & (1 << a)) && ((info.mask & (1 << a)) == 0))
#define NEED(a) ((need_mask & (1ULL << a)) && ((info.mask & (1ULL << a)) == 0))
void update_stuff(void)
{
@ -456,6 +456,11 @@ void update_stuff(void)
if (NEED(INFO_DNS)) {
update_dns_data();
}
#ifdef APCUPSD
if (NEED(INFO_APCUPSD)) {
update_apcupsd();
}
#endif
}
int round_to_int(float f)

View File

@ -214,6 +214,9 @@ static void print_version(void)
#ifdef MIXER_IS_ALSA
" * ALSA mixer support\n"
#endif /* MIXER_IS_ALSA */
#ifdef APCUPSD
" * apcupsd\n"
#endif /* APCUPSD */
);
exit(0);
@ -969,6 +972,23 @@ static void free_text_objects(struct text_object *root)
free_text_objects(obj->sub);
free(obj->sub);
break;
#ifdef APCUPSD
case OBJ_apcupsd:
case OBJ_apcupsd_name:
case OBJ_apcupsd_model:
case OBJ_apcupsd_upsmode:
case OBJ_apcupsd_cable:
case OBJ_apcupsd_status:
case OBJ_apcupsd_linev:
case OBJ_apcupsd_load:
case OBJ_apcupsd_loadbar:
case OBJ_apcupsd_loadgraph:
case OBJ_apcupsd_charge:
case OBJ_apcupsd_timeleft:
case OBJ_apcupsd_temp:
case OBJ_apcupsd_lastxfer:
break;
#endif /* APCUPSD */
}
free(obj);
}
@ -1022,12 +1042,12 @@ static struct text_object *construct_text_object(const char *s,
obj->line = line;
#define OBJ(a, n) if (strcmp(s, #a) == 0) { \
obj->type = OBJ_##a; need_mask |= (1 << n); {
obj->type = OBJ_##a; need_mask |= (1ULL << n); {
#define OBJ_IF(a, n) if (strcmp(s, #a) == 0) { \
obj->type = OBJ_##a; need_mask |= (1 << n); \
obj->type = OBJ_##a; need_mask |= (1ULL << n); \
obj_be_ifblock_if(ifblock_opaque, obj); {
#define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
obj->type = OBJ_##a; need_mask |= (1 << n); {
obj->type = OBJ_##a; need_mask |= (1ULL << n); {
#define END } } else
#ifdef X11
@ -2578,6 +2598,38 @@ static struct text_object *construct_text_object(const char *s,
" specified: '%s'\n", arg);
}
#endif /* NVIDIA */
#ifdef APCUPSD
init_apcupsd();
END OBJ(apcupsd, INFO_APCUPSD)
if (arg) {
char host[64];
int port;
if (sscanf(arg, "%63s %d", host, &port) != 2) {
CRIT_ERR("apcupsd needs arguments: <host> <port>");
} else {
info.apcupsd.port = htons(port);
strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
}
} else {
CRIT_ERR("apcupsd needs arguments: <host> <port>");
}
END OBJ(apcupsd_name, INFO_APCUPSD)
END OBJ(apcupsd_model, INFO_APCUPSD)
END OBJ(apcupsd_upsmode, INFO_APCUPSD)
END OBJ(apcupsd_cable, INFO_APCUPSD)
END OBJ(apcupsd_status, INFO_APCUPSD)
END OBJ(apcupsd_linev, INFO_APCUPSD)
END OBJ(apcupsd_load, INFO_APCUPSD)
END OBJ(apcupsd_loadbar, INFO_APCUPSD)
scan_bar(arg, &obj->a, &obj->b);
END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e, &obj->showaslog);
if (buf) free(buf);
END OBJ(apcupsd_charge, INFO_APCUPSD)
END OBJ(apcupsd_timeleft, INFO_APCUPSD)
END OBJ(apcupsd_temp, INFO_APCUPSD)
END OBJ(apcupsd_lastxfer, INFO_APCUPSD)
#endif /* APCUPSD */
END {
char buf[256];
@ -5019,7 +5071,66 @@ static void generate_text_internal(char *p, int p_max_size,
snprintf(p, p_max_size, "%d", value);
}
#endif /* NVIDIA */
#ifdef APCUPSD
OBJ(apcupsd) {
/* This is just a meta-object to set host:port */
}
OBJ(apcupsd_name) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_NAME]);
}
OBJ(apcupsd_model) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_MODEL]);
}
OBJ(apcupsd_upsmode) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_UPSMODE]);
}
OBJ(apcupsd_cable) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_CABLE]);
}
OBJ(apcupsd_status) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_STATUS]);
}
OBJ(apcupsd_linev) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_LINEV]);
}
OBJ(apcupsd_load) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_LOAD]);
}
OBJ(apcupsd_loadbar) {
double progress;
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
new_bar(p, obj->a, obj->b, (int)progress);
}
OBJ(apcupsd_loadgraph) {
double progress;
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
new_graph(p, obj->a, obj->b, obj->c, obj->d,
(int)progress, 100, 1, obj->showaslog);
}
OBJ(apcupsd_charge) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_CHARGE]);
}
OBJ(apcupsd_timeleft) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_TIMELEFT]);
}
OBJ(apcupsd_temp) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_TEMP]);
}
OBJ(apcupsd_lastxfer) {
snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_LASTXFER]);
}
#endif /* APCUPSD */
break;
}
#undef DO_JUMP

View File

@ -103,6 +103,10 @@ char *strndup(const char *s, size_t n);
#include "smapi.h"
#endif
#ifdef APCUPSD
#include "apcupsd.h"
#endif
/* sony support */
#include "sony.h"
@ -190,7 +194,10 @@ enum {
#endif
INFO_DNS = 30,
#ifdef MOC
INFO_MOC = 31
INFO_MOC = 31,
#endif
#ifdef APCUPSD
INFO_APCUPSD = 32,
#endif
};
@ -262,6 +269,10 @@ struct information {
struct x11_info x11;
#endif
#ifdef APCUPSD
APCUPSD_S apcupsd;
#endif
short kflags; /* kernel settings, see enum KFLAG */
};

View File

@ -364,7 +364,23 @@ enum text_object_type {
OBJ_combine,
OBJ_entropy_avail,
OBJ_entropy_poolsize,
OBJ_entropy_bar
OBJ_entropy_bar,
#ifdef APCUPSD
OBJ_apcupsd,
OBJ_apcupsd_name,
OBJ_apcupsd_model,
OBJ_apcupsd_upsmode,
OBJ_apcupsd_cable,
OBJ_apcupsd_status,
OBJ_apcupsd_linev,
OBJ_apcupsd_load,
OBJ_apcupsd_loadbar,
OBJ_apcupsd_loadgraph,
OBJ_apcupsd_charge,
OBJ_apcupsd_timeleft,
OBJ_apcupsd_temp,
OBJ_apcupsd_lastxfer,
#endif
};
struct text_object {