1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#pragma once
#include <stdio.h>
#include "fieldstat.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
* Create fieldstat exporter.
* The operation should be executed in single-threaded fashion.
* @param name The fieldstat exporter name.
* @param tags The fieldstat exporter tags array.
* @param n_tags The number of fieldstat exporter tags.
* @return Exporter ptr. NULL failed, Not NULL successd.
*/
struct fieldstat_exporter *fieldstat_exporter_new(const char *name,
const struct fieldstat_tag *tags,
size_t n_tags);
/**
* fieldstat exporter free.
* @param instance The fieldstat exporter need to free.
*/
void fieldstat_exporter_free(struct fieldstat_exporter *exporter);
/**
* Create prometheus endpoint.
* The operation should be executed in single-threaded fashion.
* @param listen_port The endpoint listen port. i.e., 80,8080
* @param url_path The endpoint url path. url path is "/metrics" when url path is NULL.
* @return -1 is failed. 0 is success.
*/
int fieldstat_exporter_global_enable_prometheus_endpoint(unsigned short listen_port,
const char *url_path);
/**
* Disable fieldstat prometheus exporter.
*/
void fieldstat_exporter_global_disable_prometheus_endpoint();
/**
* Enable fieldstat prometheus exporter
* The operation should be executed in single-threaded fashion.
* @param instance The fieldstat instance.
* @return -1 is failed. 0 is success.
*/
int fieldstat_exporter_enable_prometheus_exporter(struct fieldstat_exporter *exporter);
/**
* Enable local file exporter.
* The operation should be executed in single-threaded fashion.
* @param instance The fieldstat exporter.
* @param filename The output target filename.
* @return -1 is failed. 0 is success.
*/
int fieldstat_exporter_set_local_exporter(struct fieldstat_exporter *exporter,
const char *filename);
/**
* Enable start fieldstat exporter.
* The operation should be executed in single-threaded fashion.
* @param exporter The fieldstat exporter.
*/
void fieldstat_exporter_start(struct fieldstat_exporter *exporter);
/**
* Merge fieldstat instance into fieldstat exporter.
* @param exporter The fieldstat exporter.
* @param instances The fieldstat point array.
* @param n_instances The sizeof of fieldstat point array.
* @return -1 is failed. 0 is success.
*/
int fieldstat_exporter_merge_fieldstat(struct fieldstat_exporter *exporter,
struct fieldstat *instances[],
size_t n_instances);
/**
* Local file exporter.
* @param exporter The fieldstat exporter.
* @return -1 is failed. 0 is success.
*/
int fieldstat_exporter_local_export(struct fieldstat_exporter *exporter);
/* -------------------------------------------------------------------------- */
/* fieldstat_json_exporter */
/* -------------------------------------------------------------------------- */
struct fieldstat_json_exporter;
struct fieldstat_json_exporter *fieldstat_json_exporter_new(const struct fieldstat *instance);
void fieldstat_json_exporter_set_global_tag(struct fieldstat_json_exporter *exporter, const struct fieldstat_tag tag_list[], size_t n_tag);
void fieldstat_json_exporter_set_name(struct fieldstat_json_exporter *exporter, const char *name);
void fieldstat_json_exporter_free(struct fieldstat_json_exporter *exporter);
/*
Output the fieldstat instance to json string array. User must free the output string.
*/
char *fieldstat_json_exporter_export(const struct fieldstat_json_exporter *exporter);
/*
after call fieldstat_json_exporter_export_array, user must free the output array and each string.
*/
void fieldstat_json_exporter_export_array(const struct fieldstat_json_exporter *exporter, char ***output, size_t *output_size);
#ifdef __cplusplus
}
#endif
|