blob: 9ee9f10612540aa79642c8657037df71a910dba0 [file] [log] [blame]
Jacob Erlbeck95bf82802015-10-20 19:05:52 +02001/* (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
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010025struct msgb;
26
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020027enum stats_reporter_type {
28 STATS_REPORTER_STATSD,
29};
30
31struct stats_reporter {
32 enum stats_reporter_type type;
33 char *name;
34
Jacob Erlbecked197fd2015-10-27 14:43:24 +010035 unsigned int have_net_config : 1;
36
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020037 /* config */
38 int enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020039 char *name_prefix;
40 char *dest_addr_str;
41 char *bind_addr_str;
42 int dest_port;
43 int mtu;
44
45 /* state */
46 int running;
47 struct sockaddr dest_addr;
48 int dest_addr_len;
49 struct sockaddr bind_addr;
50 int bind_addr_len;
51 int fd;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010052 struct msgb *buffer;
53 int agg_enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020054
55 struct llist_head list;
56};
57
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010058struct stats_config {
59 int interval;
60};
61
62extern struct stats_config *stats_config;
63
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020064void stats_init(void *ctx);
65int stats_report();
66
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010067int stats_set_interval(int interval);
68
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020069struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type,
70 const char *name);
71void stats_reporter_free(struct stats_reporter *srep);
72struct stats_reporter *stats_reporter_create_statsd(const char *name);
73
74struct stats_reporter *stats_reporter_find(enum stats_reporter_type type,
75 const char *name);
76
77int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr);
78int stats_reporter_set_remote_port(struct stats_reporter *srep, int port);
79int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr);
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010080int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020081int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix);
82int stats_reporter_enable(struct stats_reporter *srep);
83int stats_reporter_disable(struct stats_reporter *srep);