libosmocore  0.9.6.311-c977
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stats.h
Go to the documentation of this file.
1 
2 /*
3  * (C) 2015 by Sysmocom s.f.m.c. GmbH
4  *
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22 #pragma once
23 
24 /* a bit of a crude way to disable building/using this on (bare iron)
25  * embedded systems. We cannot use the autoconf-defined HAVE_... macros
26  * here, as that only works at library compile time, not at application
27  * compile time */
28 #ifdef unix
29 
30 #include <sys/socket.h>
31 #include <arpa/inet.h>
32 
33 #include <osmocom/core/linuxlist.h>
34 
35 #include <stdint.h>
36 
37 struct msgb;
39 struct osmo_stat_item_desc;
40 struct rate_ctr_group;
41 struct rate_ctr_desc;
42 
43 enum osmo_stats_class {
44  OSMO_STATS_CLASS_UNKNOWN,
45  OSMO_STATS_CLASS_GLOBAL,
46  OSMO_STATS_CLASS_PEER,
47  OSMO_STATS_CLASS_SUBSCRIBER,
48 };
49 
50 enum osmo_stats_reporter_type {
51  OSMO_STATS_REPORTER_LOG,
52  OSMO_STATS_REPORTER_STATSD,
53 };
54 
55 struct osmo_stats_reporter {
56  enum osmo_stats_reporter_type type;
57  char *name;
58 
59  unsigned int have_net_config : 1;
60 
61  /* config */
62  int enabled;
63  char *name_prefix;
64  char *dest_addr_str;
65  char *bind_addr_str;
66  int dest_port;
67  int mtu;
68  enum osmo_stats_class max_class;
69 
70  /* state */
71  int running;
72  struct sockaddr dest_addr;
73  int dest_addr_len;
74  struct sockaddr bind_addr;
75  int bind_addr_len;
76  int fd;
77  struct msgb *buffer;
78  int agg_enabled;
79  int force_single_flush;
80 
81  struct llist_head list;
82  int (*open)(struct osmo_stats_reporter *srep);
83  int (*close)(struct osmo_stats_reporter *srep);
84  int (*send_counter)(struct osmo_stats_reporter *srep,
85  const struct rate_ctr_group *ctrg,
86  const struct rate_ctr_desc *desc,
87  int64_t value, int64_t delta);
88  int (*send_item)(struct osmo_stats_reporter *srep,
89  const struct osmo_stat_item_group *statg,
90  const struct osmo_stat_item_desc *desc,
91  int64_t value);
92 };
93 
94 struct osmo_stats_config {
95  int interval;
96 };
97 
99 
100 void osmo_stats_init(void *ctx);
101 int osmo_stats_report();
102 
103 int osmo_stats_set_interval(int interval);
104 
105 struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
106  const char *name);
107 void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
108 
109 struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
110  const char *name);
111 
112 int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
113 int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
114 int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
115 int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
116 int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
117  enum osmo_stats_class class_id);
118 int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
119 int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
120 int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
121 
122 /* reporter creation */
123 struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
124 struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
125 
126 /* helper functions for reporter implementations */
127 int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
128  int data_len);
129 int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep);
130 int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep);
131 int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep);
132 
133 #endif /* unix */
struct osmo_stats_reporter * osmo_stats_reporter_create_statsd(const char *name)
Definition: stats_statsd.c:49
int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep)
Definition: stats.c:286
struct osmo_stats_reporter * osmo_stats_reporter_find(enum osmo_stats_reporter_type type, const char *name)
Definition: stats.c:156
int osmo_stats_set_interval(int interval)
Definition: stats.c:265
int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix)
Definition: stats.c:277
One instance of a counter group class.
Definition: rate_ctr.h:57
Osmocom message buffer.
Definition: msgb.h:35
struct osmo_stats_config * osmo_stats_config
Definition: stats.c:63
char name[32]
source file name
Definition: gsmtap.h:122
int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep)
Definition: stats.c:293
int osmo_stats_report()
Definition: stats.c:614
Simple doubly linked list implementation.
(double) linked list header structure
Definition: linuxlist.h:46
int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep, enum osmo_stats_class class_id)
Definition: stats.c:254
void osmo_stats_init(void *ctx)
Definition: stats.c:147
One instance of a counter group class.
Definition: stat_item.h:56
uint8_t type
see GSMTAP_TYPE_*
Definition: gsmtap.h:113
void osmo_stats_reporter_free(struct osmo_stats_reporter *srep)
Definition: stats.c:140
statistics value description
Definition: stat_item.h:33
rate counter description
Definition: rate_ctr.h:37
struct osmo_stats_reporter * osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type, const char *name)
Definition: stats.c:124
struct osmo_stats_reporter * osmo_stats_reporter_create_log(const char *name)
Definition: stats.c:400