libosmocore 0.9.6-23.20170220git32ee5af8.fc42
Osmocom core library
Loading...
Searching...
No Matches
stats.h
1/* (C) 2015 by Sysmocom s.f.m.c. GmbH
2 *
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20#pragma once
21
22#include <sys/socket.h>
24
25#include <stdint.h>
26
27struct msgb;
30struct rate_ctr_group;
31struct rate_ctr_desc;
32
33enum osmo_stats_class {
34 OSMO_STATS_CLASS_UNKNOWN,
35 OSMO_STATS_CLASS_GLOBAL,
36 OSMO_STATS_CLASS_PEER,
37 OSMO_STATS_CLASS_SUBSCRIBER,
38};
39
40enum osmo_stats_reporter_type {
41 OSMO_STATS_REPORTER_LOG,
42 OSMO_STATS_REPORTER_STATSD,
43};
44
46 enum osmo_stats_reporter_type type;
47 char *name;
48
49 unsigned int have_net_config : 1;
50
51 /* config */
52 int enabled;
53 char *name_prefix;
54 char *dest_addr_str;
55 char *bind_addr_str;
56 int dest_port;
57 int mtu;
58 enum osmo_stats_class max_class;
59
60 /* state */
61 int running;
62 struct sockaddr dest_addr;
63 int dest_addr_len;
64 struct sockaddr bind_addr;
65 int bind_addr_len;
66 int fd;
67 struct msgb *buffer;
68 int agg_enabled;
69 int force_single_flush;
70
71 struct llist_head list;
72 int (*open)(struct osmo_stats_reporter *srep);
73 int (*close)(struct osmo_stats_reporter *srep);
74 int (*send_counter)(struct osmo_stats_reporter *srep,
75 const struct rate_ctr_group *ctrg,
76 const struct rate_ctr_desc *desc,
77 int64_t value, int64_t delta);
78 int (*send_item)(struct osmo_stats_reporter *srep,
79 const struct osmo_stat_item_group *statg,
80 const struct osmo_stat_item_desc *desc,
81 int64_t value);
82};
83
85 int interval;
86};
87
89
90void osmo_stats_init(void *ctx);
91int osmo_stats_report();
92
93int osmo_stats_set_interval(int interval);
94
95struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
96 const char *name);
97void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
98
99struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
100 const char *name);
101
102int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
103int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
104int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
105int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
106int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
107 enum osmo_stats_class class_id);
108int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
109int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
110int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
111
112/* reporter creation */
113struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
114struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
115
116/* helper functions for reporter implementations */
117int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
118 int data_len);
119int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep);
120int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep);
121int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep);
Simple doubly linked list implementation.
(double) linked list header structure
Definition linuxlist.h:47
Osmocom message buffer.
Definition msgb.h:43
statistics value description
Definition stat_item.h:35
One instance of a counter group class.
Definition stat_item.h:58
Definition stats.h:84
Definition stats.h:45
rate counter description
Definition rate_ctr.h:39
One instance of a counter group class.
Definition rate_ctr.h:59