2 * collectd - src/utils_format_stackdriver.h
5 * Copyright (C) 2017 Florian Forster
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.
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.
20 * Florian Forster <octo at collectd.org>
23 #ifndef UTILS_FORMAT_STACKDRIVER_H
24 #define UTILS_FORMAT_STACKDRIVER_H 1
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. */
32 typedef struct sd_output_s sd_output_t;
34 /* sd_resource_t represents a MonitoredResource. */
36 typedef struct sd_resource_s sd_resource_t;
38 sd_output_t *sd_output_create(sd_resource_t *res);
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);
44 /* sd_output_add adds a value_list_t* to "out".
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.
55 int sd_output_add(sd_output_t *out, data_set_t const *ds,
56 value_list_t const *vl);
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);
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
66 char *sd_output_reset(sd_output_t *out);
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,
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,
79 #endif /* UTILS_FORMAT_STACKDRIVER_H */