-
Notifications
You must be signed in to change notification settings - Fork 5
/
rrdtest.c
117 lines (99 loc) · 3.38 KB
/
rrdtest.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (c) 2016 Citrix
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <assert.h>
#include <inttypes.h>
#include "librrd.h"
static int64_t numbers[] =
{ 2, 16, 28, 29, 29, 34, 40, 48, 49, 52, 54, 55, 55, 57, 66, 67, 83,
85, 90, 97
};
/*
* Return the next value from the numbers array. sample keeps an internal
* index into the array that wraps around when it reaches the end.
*/
static rrd_value_t
sample(void *userdata)
{
rrd_value_t v;
static size_t i = 0;
RRD_SOURCE *src = (RRD_SOURCE*) userdata;
v.int64 = numbers[i++ % (sizeof(numbers) / sizeof(numbers[0]))];
printf("sample called: %"PRId64" from %s\n", v.int64, src->name);
return v;
}
static RRD_SOURCE src[2];
int
main(int argc, char **argv)
{
RRD_PLUGIN *plugin;
int rc;
if (argc != 1) {
fprintf(stderr, "usage: %s\n", basename(argv[0]));
exit(1);
}
plugin = rrd_open("rrdtest", RRD_LOCAL_DOMAIN, "rrdtest.rrd");
assert(plugin);
src[0].name = "first";
src[0].description = "description";
src[0].owner = RRD_HOST;
src[0].owner_uuid = "4cc1f2e0-5405-11e6-8c2f-572fc76ac144";
src[0].rrd_units = "points";
src[0].scale = RRD_GAUGE;
src[0].type = RRD_INT64;
src[0].min = "-inf";
src[0].max = "inf";
src[0].rrd_default = 1;
src[0].sample = sample;
src[0].userdata = &src[0];
printf("adding source: %s\n", src[0].name);
rrd_add_src(plugin, &src[0]);
rc = rrd_sample(plugin, NULL);
assert(rc == RRD_OK);
src[1].name = "second";
src[1].description = "description";
src[1].owner = RRD_HOST;
src[1].owner_uuid = "e8969702-5414-11e6-8cf5-47824be728c3";
src[1].rrd_units = "points";
src[1].scale = RRD_ABSOLUTE;
src[1].type = RRD_INT64;
src[1].min = "-inf";
src[1].max = "inf";
src[1].rrd_default = 1;
src[1].sample = sample;
src[1].userdata = &src[1];
printf("adding source: %s\n", src[1].name);
rrd_add_src(plugin, &src[1]);
rc = rrd_sample(plugin, NULL);
assert(rc == RRD_OK);
printf("removing source: %s\n", src[0].name);
rrd_del_src(plugin, &src[0]);
rc = rrd_sample(plugin, NULL);
assert(rc == RRD_OK);
printf("removing source: %s\n", src[1].name);
rrd_del_src(plugin, &src[1]);
rrd_close(plugin);
return 0;
}