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
28 #include <libaquaero5.h>
33 /* Default values for contacting daemon */
34 static char *conf_device = NULL;
36 static const char *config_keys[] =
40 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
43 static int aquaero_config (const char *key, const char *value)
45 if (strcasecmp (key, "Device") == 0)
47 if (conf_device != NULL)
54 if ((conf_device = strdup (value)) == NULL)
62 } /* int aquaero_config */
64 static int aquaero_shutdown (void)
68 } /* int aquaero_shutdown */
70 static void aquaero_submit (const char *type, const char *type_instance, double value)
72 const char *instance = conf_device?conf_device:"default";
74 value_list_t vl = VALUE_LIST_INIT;
76 /* Don't report undefined values. */
77 if (value == AQ5_FLOAT_UNDEF)
80 values[0].gauge = value;
85 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
86 sstrncpy (vl.plugin, "aquaero", sizeof (vl.plugin));
87 sstrncpy (vl.plugin_instance, instance, sizeof (vl.plugin_instance));
88 sstrncpy (vl.type, type, sizeof (vl.type));
89 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
91 plugin_dispatch_values (&vl);
92 } /* int aquaero_submit */
94 /* aquaero_submit_array submits every value of a given array of values */
95 static void aquaero_submit_array (const char *type, 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++)
101 if (value_array[i] != AQ5_FLOAT_UNDEF)
103 snprintf(type_instance, sizeof(type_instance), "%s%d", type_instance_prefix, i+1);
104 aquaero_submit(type, type_instance, value_array[i]);
108 static int aquaero_read (void)
111 aq5_settings_t aq_sett;
112 char *err_msg = NULL;
113 char type_instance[DATA_MAX_NAME_LEN];
117 if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0)
119 sstrerror(errno, errbuf, sizeof (errbuf));
120 ERROR ("Failed to poll device '%s': %s (%s)",
121 conf_device?conf_device:"default", err_msg, errbuf);
125 if (libaquaero5_getsettings(conf_device, &aq_sett, &err_msg) < 0)
127 sstrerror(errno, errbuf, sizeof (errbuf));
128 ERROR ("Failed to get settings for device '%s': %s (%s)\n",
129 conf_device?conf_device:"default", err_msg, errbuf);
133 /* CPU Temperature sensor */
134 aquaero_submit("temperature", "cpu", aq_data.cpu_temp[0]);
136 /* Temperature sensors */
137 aquaero_submit_array("temperature", "temp", aq_data.temp, AQ5_NUM_TEMP);
139 /* Virtual temperature sensors */
140 aquaero_submit_array("temperature", "virttemp", aq_data.vtemp, AQ5_NUM_VIRT_SENSORS);
142 /* Software temperature sensors */
143 aquaero_submit_array("temperature", "softtemp", aq_data.stemp, AQ5_NUM_SOFT_SENSORS);
145 /* Other temperature sensors */
146 aquaero_submit_array("temperature", "othertemp", aq_data.otemp, AQ5_NUM_OTHER_SENSORS);
149 for (i = 0; i < AQ5_NUM_FAN; i++)
151 if ((aq_sett.fan_data_source[i] != NONE) && (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF))
153 snprintf(type_instance, sizeof(type_instance), "fan%d", i+1);
154 aquaero_submit("fanspeed", type_instance, aq_data.fan_rpm[i]);
155 snprintf(type_instance, sizeof(type_instance), "fan-vrm%d", i+1);
156 aquaero_submit("temperature", type_instance, aq_data.fan_vrm_temp[i]);
158 snprintf(type_instance, sizeof(type_instance), "fan%d", i+1);
159 aquaero_submit("percentage", type_instance, aq_data.fan_duty[i]);
161 snprintf(type_instance, sizeof(type_instance), "fan%d", i+1);
162 aquaero_submit("voltage", type_instance, aq_data.fan_voltage[i]);
163 snprintf(type_instance, sizeof(type_instance), "fan%d", i+1);
164 aquaero_submit("current", type_instance, aq_data.fan_current[i]);
169 aquaero_submit_array("flow", "flow", aq_data.flow, AQ5_NUM_FLOW);
172 aquaero_submit_array("level", "level", aq_data.level, AQ5_NUM_LEVEL);
177 void module_register (void)
179 plugin_register_config ("aquaero", aquaero_config, config_keys,
181 plugin_register_read ("aquaero", aquaero_read);
182 plugin_register_shutdown ("aquaero", aquaero_shutdown);
183 } /* void module_register */