libosmocore  0.9.6.270-38c0
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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 /* a bit of a crude way to disable building/using this on (bare iron)
23  * embedded systems. We cannot use the autoconf-defined HAVE_... macros
24  * here, as that only works at library compile time, not at application
25  * compile time */
26 #ifdef unix
27 
28 #include <sys/socket.h>
29 #include <arpa/inet.h>
30 
31 #include <osmocom/core/linuxlist.h>
32 
33 #include <stdint.h>
34 
35 struct msgb;
37 struct osmo_stat_item_desc;
38 struct rate_ctr_group;
39 struct rate_ctr_desc;
40 
41 enum osmo_stats_class {
42  OSMO_STATS_CLASS_UNKNOWN,
43  OSMO_STATS_CLASS_GLOBAL,
44  OSMO_STATS_CLASS_PEER,
45  OSMO_STATS_CLASS_SUBSCRIBER,
46 };
47 
48 enum osmo_stats_reporter_type {
49  OSMO_STATS_REPORTER_LOG,
50  OSMO_STATS_REPORTER_STATSD,
51 };
52 
53 struct osmo_stats_reporter {
54  enum osmo_stats_reporter_type type;
55  char *name;
56 
57  unsigned int have_net_config : 1;
58 
59  /* config */
60  int enabled;
61  char *name_prefix;
62  char *dest_addr_str;
63  char *bind_addr_str;
64  int dest_port;
65  int mtu;
66  enum osmo_stats_class max_class;
67 
68  /* state */
69  int running;
70  struct sockaddr dest_addr;
71  int dest_addr_len;
72  struct sockaddr bind_addr;
73  int bind_addr_len;
74  int fd;
75  struct msgb *buffer;
76  int agg_enabled;
77  int force_single_flush;
78 
79  struct llist_head list;
80  int (*open)(struct osmo_stats_reporter *srep);
81  int (*close)(struct osmo_stats_reporter *srep);
82  int (*send_counter)(struct osmo_stats_reporter *srep,
83  const struct rate_ctr_group *ctrg,
84  const struct rate_ctr_desc *desc,
85  int64_t value, int64_t delta);
86  int (*send_item)(struct osmo_stats_reporter *srep,
87  const struct osmo_stat_item_group *statg,
88  const struct osmo_stat_item_desc *desc,
89  int64_t value);
90 };
91 
92 struct osmo_stats_config {
93  int interval;
94 };
95 
96 extern struct osmo_stats_config *osmo_stats_config;
97 
98 void osmo_stats_init(void *ctx);
99 int osmo_stats_report();
100 
101 int osmo_stats_set_interval(int interval);
102 
103 struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
104  const char *name);
105 void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
106 
107 struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
108  const char *name);
109 
110 int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
111 int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
112 int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
113 int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
114 int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
115  enum osmo_stats_class class_id);
116 int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
117 int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
118 int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
119 
120 /* reporter creation */
121 struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
122 struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
123 
124 /* helper functions for reporter implementations */
125 int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
126  int data_len);
127 int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep);
128 int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep);
129 int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep);
130 
131 #endif /* unix */
One instance of a counter group class.
Definition: rate_ctr.h:59
Osmocom message buffer.
Definition: msgb.h:37
Simple doubly linked list implementation.
(double) linked list header structure
Definition: linuxlist.h:47
One instance of a counter group class.
Definition: stat_item.h:58
statistics value description
Definition: stat_item.h:35
rate counter description
Definition: rate_ctr.h:39