2 * collectd - src/utils_format_gcm.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_GCM_H
24 #define UTILS_FORMAT_GCM_H 1
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. */
32 typedef struct gcm_output_s gcm_output_t;
34 /* gcm_resource_t represents a MonitoredResource. */
35 struct gcm_resource_s;
36 typedef struct gcm_resource_s gcm_resource_t;
38 gcm_output_t *gcm_output_create(gcm_resource_t *res);
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);
44 /* gcm_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 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.
54 int gcm_output_add(gcm_output_t *out, data_set_t const *ds,
55 value_list_t const *vl);
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);
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
65 char *gcm_output_reset(gcm_output_t *out);
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,
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,
78 #endif /* UTILS_FORMAT_GCM_H */