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
27 #include <libaquaero5.h>
32 /* Default values for contacting daemon */
33 static char *conf_device = NULL;
35 static int aquaero_config (oconfig_item_t *ci)
39 for (i = 0; i < ci->children_num; i++)
41 oconfig_item_t *child = ci->children + i;
43 if (strcasecmp ("Device", child->key))
44 cf_util_get_string (child, &conf_device);
47 ERROR ("aquaero plugin: Unknown config option \"%s\".",
55 static int aquaero_shutdown (void)
59 } /* int aquaero_shutdown */
61 static void aquaero_submit (const char *type, const char *type_instance,
64 const char *instance = conf_device?conf_device:"default";
66 value_list_t vl = VALUE_LIST_INIT;
68 /* Don't report undefined values. */
69 if (value == AQ5_FLOAT_UNDEF)
72 values[0].gauge = value;
77 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
78 sstrncpy (vl.plugin, "aquaero", sizeof (vl.plugin));
79 sstrncpy (vl.plugin_instance, instance, sizeof (vl.plugin_instance));
80 sstrncpy (vl.type, type, sizeof (vl.type));
81 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
83 plugin_dispatch_values (&vl);
84 } /* int aquaero_submit */
86 /* aquaero_submit_array submits every value of a given array of values */
87 static void aquaero_submit_array (const char *type,
88 const char *type_instance_prefix, double *value_array, int len)
90 char type_instance[DATA_MAX_NAME_LEN];
93 for (i = 0; i < len; i++)
95 if (value_array[i] == AQ5_FLOAT_UNDEF)
98 snprintf (type_instance, sizeof (type_instance), "%s%d",
99 type_instance_prefix, i + 1);
100 aquaero_submit (type, type_instance, value_array[i]);
104 static int aquaero_read (void)
107 aq5_settings_t aq_sett;
108 char *err_msg = NULL;
109 char type_instance[DATA_MAX_NAME_LEN];
112 if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0)
115 ERROR ("aquaero plugin: Failed to poll device \"%s\": %s (%s)",
116 conf_device ? conf_device : "default", err_msg,
117 sstrerror (errno, errbuf, sizeof (errbuf)));
121 if (libaquaero5_getsettings(conf_device, &aq_sett, &err_msg) < 0)
124 ERROR ("aquaero plugin: Failed to get settings "
125 "for device \"%s\": %s (%s)",
126 conf_device ? conf_device : "default", err_msg,
127 sstrerror (errno, errbuf, sizeof (errbuf)));
131 /* CPU Temperature sensor */
132 aquaero_submit("temperature", "cpu", aq_data.cpu_temp[0]);
134 /* Temperature sensors */
135 aquaero_submit_array("temperature", "sensor", aq_data.temp,
138 /* Virtual temperature sensors */
139 aquaero_submit_array("temperature", "virtual", aq_data.vtemp,
140 AQ5_NUM_VIRT_SENSORS);
142 /* Software temperature sensors */
143 aquaero_submit_array("temperature", "software", aq_data.stemp,
144 AQ5_NUM_SOFT_SENSORS);
146 /* Other temperature sensors */
147 aquaero_submit_array("temperature", "other", aq_data.otemp,
148 AQ5_NUM_OTHER_SENSORS);
151 for (i = 0; i < AQ5_NUM_FAN; i++)
153 if ((aq_sett.fan_data_source[i] == NONE)
154 || (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF))
157 snprintf (type_instance, sizeof (type_instance),
160 aquaero_submit ("fanspeed", type_instance,
162 aquaero_submit ("percent", type_instance,
163 aq_data.fan_duty[i]);
164 aquaero_submit ("voltage", type_instance,
165 aq_data.fan_voltage[i]);
166 aquaero_submit ("current", type_instance,
167 aq_data.fan_current[i]);
169 /* Report the voltage reglator module (VRM) temperature with a
170 * different type instance. */
171 snprintf (type_instance, sizeof (type_instance),
173 aquaero_submit ("temperature", type_instance,
174 aq_data.fan_vrm_temp[i]);
178 aquaero_submit_array("flow", "sensor", aq_data.flow, AQ5_NUM_FLOW);
181 aquaero_submit_array("percent", "waterlevel",
182 aq_data.level, AQ5_NUM_LEVEL);
187 void module_register (void)
189 plugin_register_complex_config ("aquaero", aquaero_config);
190 plugin_register_read ("aquaero", aquaero_read);
191 plugin_register_shutdown ("aquaero", aquaero_shutdown);
192 } /* void module_register */
194 /* vim: set sw=8 sts=8 noet : */