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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
/* $OpenBSD: output-ometric.c,v 1.12 2024/11/02 12:30:28 job Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
#include "ometric.h"
#include "version.h"
static struct ometric *rpki_info, *rpki_completion_time, *rpki_duration;
static struct ometric *rpki_repo, *rpki_obj, *rpki_ta_obj;
static struct ometric *rpki_repo_obj, *rpki_repo_duration;
static struct ometric *rpki_repo_state, *rpki_repo_proto;
static const char * const repo_states[2] = { "failed", "synced" };
static const char * const repo_protos[3] = { "rrdp", "rsync", "https" };
static void
set_common_stats(const struct repotalstats *in, struct ometric *metric,
struct olabels *ol)
{
ometric_set_int_with_labels(metric, in->certs,
OKV("type", "state"), OKV("cert", "valid"), ol);
ometric_set_int_with_labels(metric, in->certs_fail,
OKV("type", "state"), OKV("cert", "failed parse"), ol);
ometric_set_int_with_labels(metric, in->mfts,
OKV("type", "state"), OKV("manifest", "valid"), ol);
ometric_set_int_with_labels(metric, in->mfts_fail,
OKV("type", "state"), OKV("manifest", "failed parse"), ol);
ometric_set_int_with_labels(metric, in->mfts_gap,
OKV("type", "state"), OKV("manifest", "sequence gap"), ol);
ometric_set_int_with_labels(metric, in->roas,
OKV("type", "state"), OKV("roa", "valid"), ol);
ometric_set_int_with_labels(metric, in->roas_fail,
OKV("type", "state"), OKV("roa", "failed parse"), ol);
ometric_set_int_with_labels(metric, in->roas_invalid,
OKV("type", "state"), OKV("roa", "invalid"), ol);
ometric_set_int_with_labels(metric, in->aspas,
OKV("type", "state"), OKV("aspa", "valid"), ol);
ometric_set_int_with_labels(metric, in->aspas_fail,
OKV("type", "state"), OKV("aspa", "failed parse"), ol);
ometric_set_int_with_labels(metric, in->aspas_invalid,
OKV("type", "state"), OKV("aspa", "invalid"), ol);
ometric_set_int_with_labels(metric, in->brks,
OKV("type", "state"), OKV("router_key", "valid"), ol);
ometric_set_int_with_labels(metric, in->crls,
OKV("type", "state"), OKV("crl", "valid"), ol);
ometric_set_int_with_labels(metric, in->gbrs,
OKV("type", "state"), OKV("gbr", "valid"), ol);
ometric_set_int_with_labels(metric, in->taks,
OKV("type", "state"), OKV("tak", "valid"), ol);
ometric_set_int_with_labels(metric, in->vrps,
OKV("type", "state"), OKV("vrp", "total"), ol);
ometric_set_int_with_labels(metric, in->vrps_uniqs,
OKV("type", "state"), OKV("vrp", "unique"), ol);
ometric_set_int_with_labels(metric, in->vaps,
OKV("type", "state"), OKV("vap", "total"), ol);
ometric_set_int_with_labels(metric, in->vaps_uniqs,
OKV("type", "state"), OKV("vap", "unique"), ol);
ometric_set_int_with_labels(metric, in->vaps_pas,
OKV("type", "state"), OKV("vap providers", "total"), ol);
ometric_set_int_with_labels(metric, in->vaps_overflowed,
OKV("type", "state"), OKV("vap overflowed"), ol);
if (experimental) {
ometric_set_int_with_labels(metric, in->spls,
OKV("type", "state"), OKV("spl", "valid"), ol);
ometric_set_int_with_labels(metric, in->spls_fail,
OKV("type", "state"), OKV("spl", "failed parse"), ol);
ometric_set_int_with_labels(metric, in->spls_invalid,
OKV("type", "state"), OKV("spl", "invalid"), ol);
}
ometric_set_int_with_labels(metric, in->vsps,
OKV("type", "state"), OKV("vsp", "total"), ol);
ometric_set_int_with_labels(metric, in->vsps_uniqs,
OKV("type", "state"), OKV("vsp", "unique"), ol);
}
static void
ta_stats(int id)
{
struct olabels *ol;
const char *keys[2] = { "name", NULL };
const char *values[2];
values[0] = taldescs[id];
values[1] = NULL;
ol = olabels_new(keys, values);
set_common_stats(&talstats[id], rpki_ta_obj, ol);
olabels_free(ol);
}
static void
repo_tal_stats(const struct repo *rp, const struct repotalstats *in, void *arg)
{
struct olabels *ol;
const char *keys[4] = { "name", "carepo", "notify", NULL };
const char *values[4];
int talid = *(int *)arg;
values[0] = taldescs[talid];
repo_fetch_uris(rp, &values[1], &values[2]);
values[3] = NULL;
ol = olabels_new(keys, values);
set_common_stats(in, rpki_repo_obj, ol);
olabels_free(ol);
}
static void
repo_stats(const struct repo *rp, const struct repostats *in, void *arg)
{
struct olabels *ol;
const char *keys[3] = { "carepo", "notify", NULL };
const char *values[3];
repo_fetch_uris(rp, &values[0], &values[1]);
values[2] = NULL;
ol = olabels_new(keys, values);
ometric_set_timespec(rpki_repo_duration, &in->sync_time, ol);
ometric_set_int_with_labels(rpki_repo_obj, in->new_files,
OKV("type", "state"), OKV("files", "new"), ol);
ometric_set_int_with_labels(rpki_repo_obj, in->del_files,
OKV("type", "state"), OKV("files", "deleted"), ol);
ometric_set_int_with_labels(rpki_repo_obj, in->extra_files,
OKV("type", "state"), OKV("files", "extra"), ol);
ometric_set_int_with_labels(rpki_repo_obj, in->del_extra_files,
OKV("type", "state"), OKV("files", "deleted_extra"), ol);
ometric_set_int_with_labels(rpki_repo_obj, in->del_dirs,
OKV("type", "state"), OKV("dirs", "deleted"), ol);
ometric_set_state(rpki_repo_state, repo_states[repo_synced(rp)], ol);
if (repo_synced(rp))
ometric_set_state(rpki_repo_proto, repo_proto(rp), ol);
olabels_free(ol);
}
int
output_ometric(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks,
struct vap_tree *vaps, struct vsp_tree *vsps, struct stats *st)
{
struct olabels *ol;
const char *keys[4] = { "nodename", "domainname", "release", NULL };
const char *values[4];
char hostname[HOST_NAME_MAX + 1];
char *domainname;
struct timespec now_time;
int rv, i;
rpki_info = ometric_new(OMT_INFO, "rpki_client",
"rpki-client information");
rpki_completion_time = ometric_new(OMT_GAUGE,
"rpki_client_job_completion_time",
"end of this run as epoch timestamp");
rpki_repo = ometric_new(OMT_GAUGE, "rpki_client_repository",
"total number of repositories");
rpki_obj = ometric_new(OMT_GAUGE, "rpki_client_objects",
"total number of objects");
rpki_duration = ometric_new(OMT_GAUGE, "rpki_client_duration",
"duration in seconds");
rpki_ta_obj = ometric_new(OMT_GAUGE, "rpki_client_ta_objects",
"total number of objects per TAL");
rpki_repo_obj = ometric_new(OMT_GAUGE, "rpki_client_repository_objects",
"total number of objects per repository");
rpki_repo_duration = ometric_new(OMT_GAUGE,
"rpki_client_repository_duration",
"duration used to sync this repository in seconds");
rpki_repo_state = ometric_new_state(repo_states,
sizeof(repo_states) / sizeof(repo_states[0]),
"rpki_client_repository_state",
"repository state");
rpki_repo_proto = ometric_new_state(repo_protos,
sizeof(repo_protos) / sizeof(repo_protos[0]),
"rpki_client_repository_protos",
"used protocol to sync repository");
/*
* Dump statistics
*/
if (gethostname(hostname, sizeof(hostname)))
err(1, "gethostname");
if ((domainname = strchr(hostname, '.')))
*domainname++ = '\0';
values[0] = hostname;
values[1] = domainname;
values[2] = RPKI_VERSION;
values[3] = NULL;
ol = olabels_new(keys, values);
ometric_set_info(rpki_info, NULL, NULL, ol);
olabels_free(ol);
for (i = 0; i < talsz; i++) {
repo_tal_stats_collect(repo_tal_stats, i, &i);
ta_stats(i);
}
repo_stats_collect(repo_stats, NULL);
set_common_stats(&st->repo_tal_stats, rpki_obj, NULL);
ometric_set_int_with_labels(rpki_repo, st->rsync_repos,
OKV("type", "state"), OKV("rsync", "synced"), NULL);
ometric_set_int_with_labels(rpki_repo, st->rsync_fails,
OKV("type", "state"), OKV("rsync", "failed"), NULL);
ometric_set_int_with_labels(rpki_repo, st->http_repos,
OKV("type", "state"), OKV("http", "synced"), NULL);
ometric_set_int_with_labels(rpki_repo, st->http_fails,
OKV("type", "state"), OKV("http", "failed"), NULL);
ometric_set_int_with_labels(rpki_repo, st->rrdp_repos,
OKV("type", "state"), OKV("rrdp", "synced"), NULL);
ometric_set_int_with_labels(rpki_repo, st->rrdp_fails,
OKV("type", "state"), OKV("rrdp", "failed"), NULL);
ometric_set_timespec_with_labels(rpki_duration, &st->elapsed_time,
OKV("type"), OKV("elapsed"), NULL);
ometric_set_timespec_with_labels(rpki_duration, &st->user_time,
OKV("type"), OKV("user"), NULL);
ometric_set_timespec_with_labels(rpki_duration, &st->system_time,
OKV("type"), OKV("system"), NULL);
clock_gettime(CLOCK_REALTIME, &now_time);
ometric_set_timespec(rpki_completion_time, &now_time, NULL);
rv = ometric_output_all(out);
ometric_free_all();
return rv;
}
|