libosmocore  0.9.0
Osmocom core library
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>
23 #include <osmocom/core/linuxlist.h>
24 
25 #include <stdint.h>
26 
27 struct msgb;
29 struct osmo_stat_item_desc;
30 struct rate_ctr_group;
31 struct rate_ctr_desc;
32 
33 enum 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 
40 enum osmo_stats_reporter_type {
41  OSMO_STATS_REPORTER_STATSD,
42  OSMO_STATS_REPORTER_LOG,
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 
70  struct llist_head list;
71  int (*open)(struct osmo_stats_reporter *srep);
72  int (*close)(struct osmo_stats_reporter *srep);
73  int (*send_counter)(struct osmo_stats_reporter *srep,
74  const struct rate_ctr_group *ctrg,
75  const struct rate_ctr_desc *desc,
76  int64_t value, int64_t delta);
77  int (*send_item)(struct osmo_stats_reporter *srep,
78  const struct osmo_stat_item_group *statg,
79  const struct osmo_stat_item_desc *desc,
80  int32_t value);
81 };
82 
84  int interval;
85 };
86 
88 
89 void osmo_stats_init(void *ctx);
90 int osmo_stats_report();
91 
92 int osmo_stats_set_interval(int interval);
93 
94 struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
95  const char *name);
96 void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
97 
98 struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
99 struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
100 
101 struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
102  const char *name);
103 
104 int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
105 int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
106 int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
107 int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
108 int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
109  enum osmo_stats_class class_id);
110 int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
111 int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
112 int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
One instance of a counter group class.
Definition: rate_ctr.h:59
Osmocom message buffer.
Definition: msgb.h:42
Definition: stats.h:83
Definition: stats.h:45
Definition: linuxlist.h:42
One instance of a counter group class.
Definition: stat_item.h:57
statistics value description
Definition: stat_item.h:34
rate counter description
Definition: rate_ctr.h:39