Merge branch 'collectd-5.8'
[collectd.git] / src / utils_format_stackdriver.h
1 /**
2  * collectd - src/utils_format_stackdriver.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_STACKDRIVER_H
24 #define UTILS_FORMAT_STACKDRIVER_H 1
25
26 #include "collectd.h"
27 #include "plugin.h"
28
29 /* sd_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 sd_output_s;
32 typedef struct sd_output_s sd_output_t;
33
34 /* sd_resource_t represents a MonitoredResource. */
35 struct sd_resource_s;
36 typedef struct sd_resource_s sd_resource_t;
37
38 sd_output_t *sd_output_create(sd_resource_t *res);
39
40 /* sd_output_destroy frees all memory used by out, including the
41  * sd_resource_t* passed to sd_output_create. */
42 void sd_output_destroy(sd_output_t *out);
43
44 /* sd_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 sd_output_add again.
51  *   - ENOENT   First time we encounter this metric. Create a metric descriptor
52  *              using the Stackdriver API and then call
53  *              sd_output_register_metric.
54  */
55 int sd_output_add(sd_output_t *out, data_set_t const *ds,
56                   value_list_t const *vl);
57
58 /* sd_output_register_metric adds the metric descriptor which vl maps to, to
59  * the list of known metric descriptors. */
60 int sd_output_register_metric(sd_output_t *out, data_set_t const *ds,
61                               value_list_t const *vl);
62
63 /* sd_output_reset resets the output and returns the previous content of the
64  * buffer. It is the caller's responsibility to call free() with the returned
65  * pointer. */
66 char *sd_output_reset(sd_output_t *out);
67
68 sd_resource_t *sd_resource_create(char const *type);
69 void sd_resource_destroy(sd_resource_t *res);
70 int sd_resource_add_label(sd_resource_t *res, char const *key,
71                           char const *value);
72
73 /* sd_format_metric_descriptor creates the payload for a
74  * projects.metricDescriptors.create() request. */
75 int sd_format_metric_descriptor(char *buffer, size_t buffer_size,
76                                 data_set_t const *ds, value_list_t const *vl,
77                                 int ds_index);
78
79 #endif /* UTILS_FORMAT_STACKDRIVER_H */