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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
* Exercise libpcp_import
*
* Copyright (c) 2009 Ken McDonell. All Rights Reserved.
*/
#include <pcp/pmapi.h>
#include <pcp/impl.h>
#include <pcp/import.h>
static void
check(int sts, char *name)
{
if (sts < 0) fprintf(stderr, "%s: Error: %s\n", name, pmiErrStr(sts));
else {
fprintf(stderr, "%s: OK", name);
if (sts != 0) fprintf(stderr, " ->%d", sts);
fputc('\n', stderr);
}
}
int
main(int argc, char **argv)
{
int sts;
int ctx1;
int ctx2;
int hdl1;
int hdl2;
int errflag = 0;
int c;
#ifdef PCP_DEBUG
static char *debug = "[-D N] ";
#else
static char *debug = "";
#endif
static char *usage = "";
__pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "D:")) != EOF) {
switch (c) {
#ifdef PCP_DEBUG
case 'D': /* debug flag */
sts = __pmParseDebug(optarg);
if (sts < 0) {
fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
pmProgname, optarg);
errflag++;
}
else
pmDebug |= sts;
break;
#endif
case '?':
default:
errflag++;
break;
}
}
if (errflag) {
printf("Usage: %s %s%s\n", pmProgname, debug, usage);
exit(1);
}
pmiDump();
ctx1 = pmiStart("myarchive", 0);
check(ctx1, "pmiStart");
pmiDump();
sts = pmiSetHostname("somehost.com");
check(sts, "pmiSetHostname");
sts = pmiSetTimezone("GMT-12");
check(sts, "pmiSetTimezone");
sts = pmiUseContext(3);
check(sts, "pmiUseContext");
sts = pmiUseContext(ctx1);
check(sts, "pmiUseContext");
sts = pmiAddMetric("my.metric.foo", pmid_build(245,0,1), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT, pmiUnits(1,-1,0,PM_SPACE_MBYTE,PM_TIME_SEC,0));
check(sts, "pmiAddMetric");
sts = pmiAddMetric("my.metric.bar", PM_ID_NULL, PM_TYPE_U64, pmInDom_build(245,1), PM_SEM_INSTANT, pmiUnits(1,-1,0,PM_SPACE_MBYTE,PM_TIME_SEC,0));
check(sts, "pmiAddMetric");
sts = pmiAddMetric("my.metric.foo", 1, 2, 3, 4, pmiUnits(0,0,0,0,0,0));
check(sts, "pmiAddMetric");
sts = pmiAddMetric("my.metric.long", PM_ID_NULL, PM_TYPE_64, PM_INDOM_NULL, PM_SEM_INSTANT, pmiUnits(0,0,0,0,0,0));
check(sts, "pmiAddMetric");
sts = pmiAddMetric("my.metric.double", PM_ID_NULL, PM_TYPE_DOUBLE, PM_INDOM_NULL, PM_SEM_INSTANT, pmiUnits(0,0,0,0,0,0));
check(sts, "pmiAddMetric");
sts = pmiAddMetric("my.metric.string", PM_ID_NULL, PM_TYPE_STRING, PM_INDOM_NULL, PM_SEM_INSTANT, pmiUnits(0,0,0,0,0,0));
check(sts, "pmiAddMetric");
sts = pmiAddMetric("my.dup.pmid", pmid_build(245,0,3), PM_TYPE_32, PM_INDOM_NULL, PM_SEM_INSTANT, pmiUnits(0,0,0,0,0,0));
check(sts, "pmiAddMetric");
sts = pmiAddMetric("my.metric.float", PM_ID_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_DISCRETE, pmiUnits(0,0,0,0,0,0));
check(sts, "pmiAddMetric");
sts = pmiAddInstance(pmInDom_build(245,1), "eek really", 1);
check(sts, "pmiAddInstance");
sts = pmiAddInstance(pmInDom_build(245,1), "eek", 2);
check(sts, "pmiAddInstance");
sts = pmiAddInstance(pmInDom_build(245,1), "blah", 3);
check(sts, "pmiAddInstance");
sts = pmiAddInstance(pmInDom_build(245,1), "not-blah-again", 3);
check(sts, "pmiAddInstance");
sts = pmiPutValue("my.metric.foo", NULL, "123");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.foo", "should be null", "1234");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.bar", "eek", "4567890123456");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.bar", "blah", "4567890123457");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.bar", "not-blah", "4567890123457");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.bar", NULL, "42");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.string", "", "a new string value");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.long", "", "123456789012345");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.double", "", "1.23456789012");
check(sts, "pmiPutValue");
sts = pmiPutValue("my.metric.float", "", "-1.234567");
check(sts, "pmiPutValue");
hdl1 = pmiGetHandle("my.metric.foo", "");
check(hdl1, "pmiGetHandle");
sts = pmiGetHandle("my.bad", "");
check(sts, "pmiGetHandle");
sts = pmiPutValueHandle(hdl1, "321");
check(sts, "pmiPutValueHandle");
sts = pmiPutValueHandle(0, "error");
check(sts, "pmiPutValueHandle");
pmiDump();
sts = pmiWrite((int)(365.25*30*24*60*60), 0);
check(sts, "pmiWrite");
sts = pmiPutValueHandle(hdl1, "4321");
check(sts, "pmiPutValueHandle");
sts = pmiPutValue("my.metric.string", "", "a second string value");
check(sts, "pmiPutValue");
sts = pmiWrite(-1, -1);
check(sts, "pmiWrite");
sts = pmiPutValue("my.metric.string", "", "a third string value");
check(sts, "pmiPutValue");
sts = pmiWrite(-1, -1);
check(sts, "pmiWrite");
sts = pmiWrite(-1, -1);
check(sts, "pmiWrite");
sts = pmiEnd();
check(sts, "pmiEnd");
ctx2 = pmiStart("myotherarchive", 1);
check(ctx2, "pmiStart");
sts = pmiAddInstance(pmInDom_build(245,1), "other", 2);
check(sts, "pmiAddInstance");
hdl2 = pmiGetHandle("my.metric.bar", "eek");
check(hdl2, "pmiGetHandle");
sts = pmiPutValueHandle(hdl2, "6543210987654");
check(sts, "pmiPutValueHandle");
sts = pmiPutValueHandle(3, "error");
check(sts, "pmiPutValueHandle");
pmiDump();
exit(0);
}
|