write_gcm plugin: Build only when libyajl 2 is avaiable.
[collectd.git] / src / utils_format_gcm.h
1 /**
2  * collectd - src/utils_format_gcm.h
3  * ISC license
4  *
5  * Copyright (C) 2017  Florian Forster
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  *
19  * Authors:
20  *   Florian Forster <octo at collectd.org>
21  **/
22
23 #ifndef UTILS_FORMAT_GCM_H
24 #define UTILS_FORMAT_GCM_H 1
25
26 #include "collectd.h"
27 #include "plugin.h"
28
29 /* gcm_output_t is a buffer to which value_list_t* can be added and from which
30  * an appropriately formatted char* can be read. */
31 struct gcm_output_s;
32 typedef struct gcm_output_s gcm_output_t;
33
34 /* gcm_resource_t represents a MonitoredResource. */
35 struct gcm_resource_s;
36 typedef struct gcm_resource_s gcm_resource_t;
37
38 gcm_output_t *gcm_output_create(gcm_resource_t *res);
39
40 /* gcm_output_destroy frees all memory used by out, including the
41  * gcm_resource_t* passed to gcm_output_create. */
42 void gcm_output_destroy(gcm_output_t *out);
43
44 /* gcm_output_add adds a value_list_t* to "out".
45  *
46  * Return values:
47  *   - 0        Success
48  *   - ENOBUFS  Success, but the buffer should be flushed soon.
49  *   - EEXIST   The value list is already encoded in the buffer.
50  *              Flush the buffer, then call gcm_output_add again.
51  *   - ENOENT   First time we encounter this metric. Create a metric descriptor
52  *              using the GCM API and then call gcm_output_register_metric.
53  */
54 int gcm_output_add(gcm_output_t *out, data_set_t const *ds,
55                    value_list_t const *vl);
56
57 /* gcm_output_register_metric adds the metric descriptor which vl maps to, to
58  * the list of known metric descriptors. */
59 int gcm_output_register_metric(gcm_output_t *out, data_set_t const *ds,
60                                value_list_t const *vl);
61
62 /* gcm_output_reset resets the output and returns the previous content of the
63  * buffer. It is the caller's responsibility to call free() with the returned
64  * pointer. */
65 char *gcm_output_reset(gcm_output_t *out);
66
67 gcm_resource_t *gcm_resource_create(char const *type);
68 void gcm_resource_destroy(gcm_resource_t *res);
69 int gcm_resource_add_label(gcm_resource_t *res, char const *key,
70                            char const *value);
71
72 /* gcm_format_metric_descriptor creates the payload for a
73  * projects.metricDescriptors.create() request. */
74 int gcm_format_metric_descriptor(char *buffer, size_t buffer_size,
75                                  data_set_t const *ds, value_list_t const *vl,
76                                  int ds_index);
77
78 #endif /* UTILS_FORMAT_GCM_H */