-/* $OpenBSD: ometric.c,v 1.7 2022/12/06 17:38:41 claudio Exp $ */
+/* $OpenBSD: ometric.c,v 1.8 2022/12/12 09:51:04 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
enum ovalue_type {
OVT_INTEGER,
OVT_DOUBLE,
- OVT_TIMEVAL,
+ OVT_TIMESPEC,
};
struct ovalue {
union {
unsigned long long i;
double f;
- struct timeval tv;
+ struct timespec ts;
} value;
enum ovalue_type valtype;
};
return fprintf(out, "%llu", ov->value.i);
case OVT_DOUBLE:
return fprintf(out, "%g", ov->value.f);
- case OVT_TIMEVAL:
- return fprintf(out, "%lld.%06ld",
- (long long)ov->value.tv.tv_sec, (long)ov->value.tv.tv_usec);
+ case OVT_TIMESPEC:
+ return fprintf(out, "%lld.%09ld",
+ (long long)ov->value.ts.tv_sec, ov->value.ts.tv_nsec);
}
return -1;
}
}
/*
- * Set an timeval value with label ol. ol can be NULL.
+ * Set an timespec value with label ol. ol can be NULL.
*/
void
-ometric_set_timeval(struct ometric *om, const struct timeval *tv,
+ometric_set_timespec(struct ometric *om, const struct timespec *ts,
struct olabels *ol)
{
struct ovalue *ov;
if ((ov = malloc(sizeof(*ov))) == NULL)
err(1, NULL);
- ov->value.tv = *tv;
- ov->valtype = OVT_TIMEVAL;
+ ov->value.ts = *ts;
+ ov->valtype = OVT_TIMESPEC;
ov->labels = olabels_ref(ol);
STAILQ_INSERT_TAIL(&om->vals, ov, entry);
}
void
-ometric_set_timeval_with_labels(struct ometric *om, struct timeval *tv,
+ometric_set_timespec_with_labels(struct ometric *om, struct timespec *ts,
const char **keys, const char **values, struct olabels *ol)
{
struct olabels *extra;
extra = olabels_add_extras(ol, keys, values);
- ometric_set_timeval(om, tv, extra);
+ ometric_set_timespec(om, ts, extra);
olabels_free(extra);
}
-/* $OpenBSD: ometric.h,v 1.4 2022/12/06 11:27:58 claudio Exp $ */
+/* $OpenBSD: ometric.h,v 1.5 2022/12/12 09:51:04 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
/* functions to set gauge and counter metrics */
void ometric_set_int(struct ometric *, uint64_t, struct olabels *);
void ometric_set_float(struct ometric *, double, struct olabels *);
-void ometric_set_timeval(struct ometric *, const struct timeval *,
+void ometric_set_timespec(struct ometric *, const struct timespec *,
struct olabels *);
void ometric_set_info(struct ometric *, const char **, const char **,
struct olabels *);
void ometric_set_state(struct ometric *, const char *, struct olabels *);
void ometric_set_int_with_labels(struct ometric *, uint64_t, const char **,
const char **, struct olabels *);
-void ometric_set_timeval_with_labels(struct ometric *, struct timeval *,
+void ometric_set_timespec_with_labels(struct ometric *, struct timespec *,
const char **, const char **, struct olabels *);
#define OKV(...) (const char *[]){ __VA_ARGS__, NULL }
-/* $OpenBSD: output_ometric.c,v 1.9 2022/12/08 17:24:39 cheloha Exp $ */
+/* $OpenBSD: output_ometric.c,v 1.10 2022/12/12 09:51:04 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
ometric_tail(void)
{
struct timespec elapsed_time;
- struct timeval tv;
clock_gettime(CLOCK_MONOTONIC, &end_time);
timespecsub(&end_time, &start_time, &elapsed_time);
- TIMESPEC_TO_TIMEVAL(&tv, &elapsed_time);
- ometric_set_timeval(bgpd_scrape_time, &tv, NULL);
+ ometric_set_timespec(bgpd_scrape_time, &elapsed_time, NULL);
ometric_output_all(stdout);
ometric_free_all();