xref: /openbsd-src/usr.sbin/bgpctl/ometric.h (revision 81b1a5f567e3c330c826411b75b8cf197bb8da4b)
1 /*	$OpenBSD: ometric.h,v 1.6 2023/01/06 13:26:57 tb Exp $ */
2 
3 /*
4  * Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 enum ometric_type {
20 	OMT_UNKNOWN,
21 	OMT_GAUGE,
22 	OMT_COUNTER,
23 	OMT_STATESET,
24 	OMT_HISTOGRAM,
25 	OMT_SUMMARY,
26 	OMT_INFO,
27 };
28 
29 struct ometric;
30 struct olabels;
31 
32 struct ometric	*ometric_new(enum ometric_type, const char *, const char *);
33 struct ometric	*ometric_new_state(const char * const *, size_t, const char *,
34 		    const char *);
35 void		 ometric_free_all(void);
36 struct olabels	*olabels_new(const char * const *, const char **);
37 void		 olabels_free(struct olabels *);
38 
39 int		 ometric_output_all(FILE *);
40 
41 /* functions to set gauge and counter metrics */
42 void	ometric_set_int(struct ometric *, uint64_t, struct olabels *);
43 void	ometric_set_float(struct ometric *, double, struct olabels *);
44 void	ometric_set_timespec(struct ometric *, const struct timespec *,
45 	    struct olabels *);
46 void	ometric_set_info(struct ometric *, const char **, const char **,
47 	    struct olabels *);
48 void	ometric_set_state(struct ometric *, const char *, struct olabels *);
49 void	ometric_set_int_with_labels(struct ometric *, uint64_t, const char **,
50 	    const char **, struct olabels *);
51 void	ometric_set_timespec_with_labels(struct ometric *, struct timespec *,
52 	    const char **, const char **, struct olabels *);
53 #define OKV(...)		(const char *[]){ __VA_ARGS__, NULL }
54