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
26 #include <libaquaero5.h>
31 /* Default values for contacting daemon */
32 static char *conf_device = NULL;
34 static const char *config_keys[] =
38 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
41 static int aquaero_config (const char *key, const char *value)
43 if (strcasecmp (key, "Device") == 0)
45 if (conf_device != NULL)
52 if ((conf_device = strdup (value)) == NULL)
60 } /* int aquaero_config */
62 static int aquaero_shutdown (void)
66 } /* int aquaero_shutdown */
68 static void aquaero_submit (const char *type, const char *type_instance,
71 const char *instance = conf_device?conf_device:"default";
73 value_list_t vl = VALUE_LIST_INIT;
75 /* Don't report undefined values. */
76 if (value == AQ5_FLOAT_UNDEF)
79 values[0].gauge = value;
84 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
85 sstrncpy (vl.plugin, "aquaero", sizeof (vl.plugin));
86 sstrncpy (vl.plugin_instance, instance, sizeof (vl.plugin_instance));
87 sstrncpy (vl.type, type, sizeof (vl.type));
88 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
90 plugin_dispatch_values (&vl);
91 } /* int aquaero_submit */
93 /* aquaero_submit_array submits every value of a given array of values */
94 static void aquaero_submit_array (const char *type,
95 const char *type_instance_prefix, double *value_array, int len)
97 char type_instance[DATA_MAX_NAME_LEN];
100 for (i = 0; i < len; i++)
102 if (value_array[i] == AQ5_FLOAT_UNDEF)
105 snprintf (type_instance, sizeof (type_instance), "%s%d",
106 type_instance_prefix, i + 1);
107 aquaero_submit (type, type_instance, value_array[i]);
111 static int aquaero_read (void)
114 aq5_settings_t aq_sett;
115 char *err_msg = NULL;
116 char type_instance[DATA_MAX_NAME_LEN];
119 if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0)
122 ERROR ("aquaero plugin: Failed to poll device \"%s\": %s (%s)",
123 conf_device ? conf_device : "default", err_msg,
124 sstrerror (errno, errbuf, sizeof (errbuf)));
128 if (libaquaero5_getsettings(conf_device, &aq_sett, &err_msg) < 0)
131 ERROR ("aquaero plugin: Failed to get settings "
132 "for device \"%s\": %s (%s)",
133 conf_device ? conf_device : "default", err_msg,
134 sstrerror (errno, errbuf, sizeof (errbuf)));
138 /* CPU Temperature sensor */
139 aquaero_submit("temperature", "cpu", aq_data.cpu_temp[0]);
141 /* Temperature sensors */
142 aquaero_submit_array("temperature", "sensor", aq_data.temp,
145 /* Virtual temperature sensors */
146 aquaero_submit_array("temperature", "virtual", aq_data.vtemp,
147 AQ5_NUM_VIRT_SENSORS);
149 /* Software temperature sensors */
150 aquaero_submit_array("temperature", "software", aq_data.stemp,
151 AQ5_NUM_SOFT_SENSORS);
153 /* Other temperature sensors */
154 aquaero_submit_array("temperature", "other", aq_data.otemp,
155 AQ5_NUM_OTHER_SENSORS);
158 for (i = 0; i < AQ5_NUM_FAN; i++)
160 if ((aq_sett.fan_data_source[i] == NONE)
161 || (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF))
164 snprintf (type_instance, sizeof (type_instance),
167 aquaero_submit ("fanspeed", type_instance,
169 aquaero_submit ("percentage", type_instance,
170 aq_data.fan_duty[i]);
171 aquaero_submit ("voltage", type_instance,
172 aq_data.fan_voltage[i]);
173 aquaero_submit ("current", type_instance,
174 aq_data.fan_current[i]);
176 /* Report the voltage reglator module (VRM) temperature with a
177 * different type instance. */
178 snprintf (type_instance, sizeof (type_instance),
180 aquaero_submit ("temperature", type_instance,
181 aq_data.fan_vrm_temp[i]);
185 aquaero_submit_array("flow", "sensor", aq_data.flow, AQ5_NUM_FLOW);
188 aquaero_submit_array("percentage", "waterlevel",
189 aq_data.level, AQ5_NUM_LEVEL);
194 void module_register (void)
196 plugin_register_config ("aquaero", aquaero_config, config_keys,
198 plugin_register_read ("aquaero", aquaero_read);
199 plugin_register_shutdown ("aquaero", aquaero_shutdown);
200 } /* void module_register */
202 /* vim: set sw=8 sts=8 noet : */