forked from ziutek/rrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rrdfunc.c
69 lines (60 loc) · 2.16 KB
/
rrdfunc.c
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
#include <stdlib.h>
#include <rrd.h>
#include <rrd_client.h>
char *rrdError() {
char *err = NULL;
if (rrd_test_error()) {
// RRD error is local for thread so other gorutine can call some RRD
// function in the same thread before we use C.GoString. So we need to
// copy current error before return from C to Go. It need to be freed
// after C.GoString in Go code.
err = strdup(rrd_get_error());
if (err == NULL) {
abort();
}
}
return err;
}
char *rrdCreate(const char *filename, unsigned long step, time_t start, int argc, const char **argv) {
rrd_clear_error();
rrd_create_r(filename, step, start, argc, argv);
return rrdError();
}
char *rrdUpdate(const char *filename, const char *template, int argc, const char **argv) {
rrd_clear_error();
rrd_update_r(filename, template, argc, argv);
return rrdError();
}
char *rrdGraph(rrd_info_t **ret, int argc, char **argv) {
rrd_clear_error();
*ret = rrd_graph_v(argc, argv);
return rrdError();
}
char *rrdInfo(rrd_info_t **ret, char *filename) {
rrd_clear_error();
*ret = rrd_info_r(filename);
return rrdError();
}
char *rrdDaemonFetch(int *ret, char *daemon, char *filename, const char *cf, time_t *start, time_t *end, unsigned long *step, unsigned long *ds_cnt, char ***ds_namv, double **data) {
rrd_clear_error();
rrdc_connect(daemon);
if (rrdc_is_connected(daemon)){
*ret = rrdc_fetch(filename, cf, start, end, step, ds_cnt, ds_namv, data);
} else {
*ret = rrd_fetch_r(filename, cf, start, end, step, ds_cnt, ds_namv, data);
}
return rrdError();
}
char *rrdFetch(int *ret, char *filename, const char *cf, time_t *start, time_t *end, unsigned long *step, unsigned long *ds_cnt, char ***ds_namv, double **data) {
rrd_clear_error();
*ret = rrd_fetch_r(filename, cf, start, end, step, ds_cnt, ds_namv, data);
return rrdError();
}
char *rrdXport(int *ret, int argc, char **argv, int *xsize, time_t *start, time_t *end, unsigned long *step, unsigned long *col_cnt, char ***legend_v, double **data) {
rrd_clear_error();
*ret = rrd_xport(argc, argv, xsize, start, end, step, col_cnt, legend_v, data);
return rrdError();
}
char *arrayGetCString(char **values, int i) {
return values[i];
}