2 * collectd - src/aquaero.c
3 * Copyright (C) 2013 Alex Deymo
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "utils/common/common.h"
27 #include <libaquaero5.h>
32 /* Default values for contacting daemon */
33 static char *conf_device;
35 static int aquaero_config(oconfig_item_t *ci) {
36 for (int i = 0; i < ci->children_num; i++) {
37 oconfig_item_t *child = ci->children + i;
39 if (strcasecmp("Device", child->key))
40 cf_util_get_string(child, &conf_device);
42 ERROR("aquaero plugin: Unknown config option \"%s\".", child->key);
49 static int aquaero_shutdown(void) {
52 } /* int aquaero_shutdown */
54 static void aquaero_submit(const char *type, const char *type_instance,
56 const char *instance = conf_device ? conf_device : "default";
57 value_list_t vl = VALUE_LIST_INIT;
59 /* Don't report undefined values. */
60 if (value == AQ5_FLOAT_UNDEF)
63 vl.values = &(value_t){.gauge = value};
66 sstrncpy(vl.plugin, "aquaero", sizeof(vl.plugin));
67 sstrncpy(vl.plugin_instance, instance, sizeof(vl.plugin_instance));
68 sstrncpy(vl.type, type, sizeof(vl.type));
69 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
71 plugin_dispatch_values(&vl);
72 } /* int aquaero_submit */
74 /* aquaero_submit_array submits every value of a given array of values */
75 static void aquaero_submit_array(const char *type,
76 const char *type_instance_prefix,
77 double *value_array, int len) {
78 char type_instance[DATA_MAX_NAME_LEN];
80 for (int i = 0; i < len; i++) {
81 if (value_array[i] == AQ5_FLOAT_UNDEF)
84 snprintf(type_instance, sizeof(type_instance), "%s%d", type_instance_prefix,
86 aquaero_submit(type, type_instance, value_array[i]);
90 static int aquaero_read(void) {
92 aq5_settings_t aq_sett;
94 char type_instance[DATA_MAX_NAME_LEN];
96 if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0) {
97 ERROR("aquaero plugin: Failed to poll device \"%s\": %s (%s)",
98 conf_device ? conf_device : "default", err_msg, STRERRNO);
102 if (libaquaero5_getsettings(conf_device, &aq_sett, &err_msg) < 0) {
103 ERROR("aquaero plugin: Failed to get settings "
104 "for device \"%s\": %s (%s)",
105 conf_device ? conf_device : "default", err_msg, STRERRNO);
109 /* CPU Temperature sensor */
110 aquaero_submit("temperature", "cpu", aq_data.cpu_temp[0]);
112 /* Temperature sensors */
113 aquaero_submit_array("temperature", "sensor", aq_data.temp, AQ5_NUM_TEMP);
115 /* Virtual temperature sensors */
116 aquaero_submit_array("temperature", "virtual", aq_data.vtemp,
117 AQ5_NUM_VIRT_SENSORS);
119 /* Software temperature sensors */
120 aquaero_submit_array("temperature", "software", aq_data.stemp,
121 AQ5_NUM_SOFT_SENSORS);
123 /* Other temperature sensors */
124 aquaero_submit_array("temperature", "other", aq_data.otemp,
125 AQ5_NUM_OTHER_SENSORS);
128 for (int i = 0; i < AQ5_NUM_FAN; i++) {
129 if ((aq_sett.fan_data_source[i] == NONE) ||
130 (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF))
133 snprintf(type_instance, sizeof(type_instance), "fan%d", i + 1);
135 aquaero_submit("fanspeed", type_instance, aq_data.fan_rpm[i]);
136 aquaero_submit("percent", type_instance, aq_data.fan_duty[i]);
137 aquaero_submit("voltage", type_instance, aq_data.fan_voltage[i]);
138 aquaero_submit("current", type_instance, aq_data.fan_current[i]);
140 /* Report the voltage reglator module (VRM) temperature with a
141 * different type instance. */
142 snprintf(type_instance, sizeof(type_instance), "fan%d-vrm", i + 1);
143 aquaero_submit("temperature", type_instance, aq_data.fan_vrm_temp[i]);
147 aquaero_submit_array("flow", "sensor", aq_data.flow, AQ5_NUM_FLOW);
150 aquaero_submit_array("percent", "waterlevel", aq_data.level, AQ5_NUM_LEVEL);
155 void module_register(void) {
156 plugin_register_complex_config("aquaero", aquaero_config);
157 plugin_register_read("aquaero", aquaero_read);
158 plugin_register_shutdown("aquaero", aquaero_shutdown);
159 } /* void module_register */