Add a write_log output plugin which logs values.
[collectd.git] / src / write_log.c
1 /**
2  * collectd - src/write_log.c
3  * Copyright (C) 2015       Pierre-Yves Ritschard
4  *
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.
8  *
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.
13  *
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
17  *
18  * Authors:
19  *   Pierre-Yves Ritschard <pyr at spootnik.org>
20  *
21  **/
22
23 #include "collectd.h"
24 #include "common.h"
25 #include "plugin.h"
26 #include "configfile.h"
27
28 #include "utils_format_graphite.h"
29
30 /* Folks without pthread will need to disable this plugin. */
31 #include <pthread.h>
32
33 #include <sys/socket.h>
34 #include <netdb.h>
35
36 #define WL_BUF_SIZE 8192
37
38 static int wl_write_messages (const data_set_t *ds, const value_list_t *vl)
39 {
40     char buffer[WL_BUF_SIZE];
41     int status;
42
43     if (0 != strcmp (ds->type, vl->type))
44     {
45         ERROR ("write_log plugin: DS type does not match "
46                 "value list type");
47         return -1;
48     }
49
50     memset (buffer, 0, sizeof (buffer));
51     status = format_graphite (buffer, sizeof (buffer), ds, vl,
52                               NULL, NULL, '_', 0);
53     if (status != 0) /* error message has been printed already. */
54         return (status);
55
56     INFO ("write_log values:\n%s", buffer);
57
58     return (0);
59 } /* int wl_write_messages */
60
61 static int wl_write (const data_set_t *ds, const value_list_t *vl,
62         user_data_t *user_data)
63 {
64     int status;
65
66     status = wl_write_messages (ds, vl);
67
68     return (status);
69 }
70
71 void module_register (void)
72 {
73     plugin_register_write ("write_log", wl_write, NULL);
74 }
75
76 /* vim: set sw=4 ts=4 sts=4 tw=78 et : */