libosmocore  0.9.6-14.20170220git32ee5af8.fc33
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_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 
90 void osmo_stats_init(void *ctx);
91 int osmo_stats_report();
92 
93 int osmo_stats_set_interval(int interval);
94 
95 struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
96  const char *name);
97 void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
98 
99 struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
100  const char *name);
101 
102 int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
103 int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
104 int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
105 int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
106 int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
107  enum osmo_stats_class class_id);
108 int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
109 int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
110 int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
111 
112 /* reporter creation */
113 struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
114 struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
115 
116 /* helper functions for reporter implementations */
117 int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
118  int data_len);
119 int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep);
120 int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep);
121 int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep);
rate_ctr_desc
rate counter description
Definition: rate_ctr.h:39
osmo_stat_item_group
One instance of a counter group class.
Definition: stat_item.h:58
osmo_stats_reporter
Definition: stats.h:45
osmo_stats_config
Definition: stats.h:84
msgb
Osmocom message buffer.
Definition: msgb.h:43
rate_ctr_group
One instance of a counter group class.
Definition: rate_ctr.h:59
llist_head
(double) linked list header structure
Definition: linuxlist.h:47
osmo_stat_item_desc
statistics value description
Definition: stat_item.h:35
linuxlist.h
Simple doubly linked list implementation.