libosmocore  0.12.1
Osmocom core library
stats.h
Go to the documentation of this file.
1 /*
2  * (C) 2015 by sysmocom - s.f.m.c. GmbH
3  *
4  * All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  */
21 #pragma once
22 
27 /* a bit of a crude way to disable building/using this on (bare iron)
28  * embedded systems. We cannot use the autoconf-defined HAVE_... macros
29  * here, as that only works at library compile time, not at application
30  * compile time */
31 #ifdef unix
32 
33 #include <sys/socket.h>
34 #include <arpa/inet.h>
35 
36 #include <osmocom/core/linuxlist.h>
37 
38 #include <stdint.h>
39 
40 struct msgb;
42 struct osmo_stat_item_desc;
43 struct rate_ctr_group;
44 struct rate_ctr_desc;
45 
52 };
53 
58 };
59 
65  char *name;
66 
67  unsigned int have_net_config : 1;
68 
69  /* config */
70  int enabled;
71  char *name_prefix;
72  char *dest_addr_str;
73  char *bind_addr_str;
74  int dest_port;
75  int mtu;
79 
80  /* state */
81 
82  int running;
83  struct sockaddr dest_addr;
85  struct sockaddr bind_addr;
87  int fd;
88  struct msgb *buffer;
91 
92  struct llist_head list;
93  int (*open)(struct osmo_stats_reporter *srep);
94  int (*close)(struct osmo_stats_reporter *srep);
95  int (*send_counter)(struct osmo_stats_reporter *srep,
96  const struct rate_ctr_group *ctrg,
97  const struct rate_ctr_desc *desc,
98  int64_t value, int64_t delta);
99  int (*send_item)(struct osmo_stats_reporter *srep,
100  const struct osmo_stat_item_group *statg,
101  const struct osmo_stat_item_desc *desc,
102  int64_t value);
103 };
104 
106  int interval;
107 };
108 
109 extern struct osmo_stats_config *osmo_stats_config;
110 
111 void osmo_stats_init(void *ctx);
112 int osmo_stats_report();
113 
115 
117  const char *name);
119 
121  const char *name);
122 
123 int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
124 int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
125 int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
128  enum osmo_stats_class class_id);
129 int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
132 
133 /* reporter creation */
136 
137 /* helper functions for reporter implementations */
138 int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
139  int data_len);
143 
144 #endif /* unix */
145 
void osmo_stats_reporter_free(struct osmo_stats_reporter *srep)
Destroy a given stats_reporter.
Definition: stats.c:182
unsigned int have_net_config
Definition: stats.h:67
int dest_port
destination (UDP) port
Definition: stats.h:74
char * dest_addr_str
destination IP address
Definition: stats.h:72
int bind_addr_len
length of bind_addr in bytes
Definition: stats.h:86
struct osmo_stats_reporter * osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type, const char *name)
Definition: stats.c:164
int(* send_item)(struct osmo_stats_reporter *srep, const struct osmo_stat_item_group *statg, const struct osmo_stat_item_desc *desc, int64_t value)
Definition: stats.h:99
osmo_stats_class
Statistics Class definitions.
Definition: stats.h:47
enum osmo_stats_reporter_type type
Type of the reporter (log, statsd)
Definition: stats.h:63
statsd backend
Definition: stats.h:57
One instance of a counter group class.
Definition: rate_ctr.h:57
char * name_prefix
prefix for counter names
Definition: stats.h:71
int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr)
Osmocom message buffer.
Definition: msgb.h:35
int interval
Definition: stats.h:106
global counter/stat_item
Definition: stats.h:49
int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep)
int running
is this reporter running
Definition: stats.h:82
libosmocore logging
Definition: stats.h:56
Definition: stats.h:105
struct osmo_stats_reporter * osmo_stats_reporter_create_statsd(const char *name)
Create a stats_reporter reporting to statsd.
Definition: stats_statsd.c:56
int(* send_counter)(struct osmo_stats_reporter *srep, const struct rate_ctr_group *ctrg, const struct rate_ctr_desc *desc, int64_t value, int64_t delta)
Definition: stats.h:95
int(* close)(struct osmo_stats_reporter *srep)
Definition: stats.h:94
struct osmo_stats_reporter * osmo_stats_reporter_find(enum osmo_stats_reporter_type type, const char *name)
Find a stats_reporter of given type and name.
Definition: stats.c:204
int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep)
int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep, enum osmo_stats_class class_id)
Definition: stats.c:318
struct sockaddr bind_addr
local bind address of socket
Definition: stats.h:85
int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep)
Enable the given stats_reporter.
Definition: stats.c:362
One statistics reporter instance.
Definition: stats.h:61
Simple doubly linked list implementation.
struct osmo_stats_config * osmo_stats_config
Definition: stats.c:103
enum osmo_stats_class max_class
Maximum class/index to report.
Definition: stats.h:78
(double) linked list header structure
Definition: linuxlist.h:46
int fd
file descriptor of socket
Definition: stats.h:87
unknown class
Definition: stats.h:48
peer in a communications link
Definition: stats.h:50
int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix)
Set the name prefix of a given stats_reporter.
Definition: stats.c:349
int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr)
int mtu
Maximum Transmission Unit.
Definition: stats.h:75
int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu)
int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep)
int agg_enabled
is aggregation enabled?
Definition: stats.h:89
int force_single_flush
Definition: stats.h:90
osmo_stats_reporter_type
Statistics Reporter Type.
Definition: stats.h:55
struct osmo_stats_reporter * osmo_stats_reporter_create_log(const char *name)
Create a stats_reporter that logs via libosmocore logging.
Definition: stats.c:500
One instance of a counter group class.
Definition: stat_item.h:58
subscriber
Definition: stats.h:51
int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port)
int dest_addr_len
length of dest_addr in bytes
Definition: stats.h:84
char * name
Human-readable name of this reporter.
Definition: stats.h:65
int osmo_stats_report()
Definition: stats.c:714
struct sockaddr dest_addr
destination address of socket
Definition: stats.h:83
int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data, int data_len)
struct llist_head list
Definition: stats.h:92
int(* open)(struct osmo_stats_reporter *srep)
Definition: stats.h:93
void osmo_stats_init(void *ctx)
Initilize the stats reporting module; call this once in your program.
Definition: stats.c:191
int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep)
Disable the given stats_reporter.
Definition: stats.c:372
struct msgb * buffer
message buffer for log output
Definition: stats.h:88
Statistics item description.
Definition: stat_item.h:35
int osmo_stats_set_interval(int interval)
Set the reporting interval of a given stats_reporter (in seconds).
Definition: stats.c:333
rate counter description
Definition: rate_ctr.h:37
char * bind_addr_str
local bind IP address
Definition: stats.h:73
int enabled
is this reporter enabled
Definition: stats.h:70