blob: beeee16ecf569088ef4846ce295f4d8a7a1e412c [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;
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010026struct stat_item_group;
27struct stat_item_desc;
28struct rate_ctr_group;
29struct rate_ctr_desc;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010030
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020031enum stats_reporter_type {
32 STATS_REPORTER_STATSD,
33};
34
35struct stats_reporter {
36 enum stats_reporter_type type;
37 char *name;
38
Jacob Erlbecked197fd2015-10-27 14:43:24 +010039 unsigned int have_net_config : 1;
40
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020041 /* config */
42 int enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020043 char *name_prefix;
44 char *dest_addr_str;
45 char *bind_addr_str;
46 int dest_port;
47 int mtu;
48
49 /* state */
50 int running;
51 struct sockaddr dest_addr;
52 int dest_addr_len;
53 struct sockaddr bind_addr;
54 int bind_addr_len;
55 int fd;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010056 struct msgb *buffer;
57 int agg_enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020058
59 struct llist_head list;
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010060 int (*open)(struct stats_reporter *srep);
61 int (*close)(struct stats_reporter *srep);
62 int (*send_counter)(struct stats_reporter *srep,
63 const struct rate_ctr_group *ctrg,
64 const struct rate_ctr_desc *desc,
65 int64_t value, int64_t delta);
66 int (*send_item)(struct stats_reporter *srep,
67 const struct stat_item_group *statg,
68 const struct stat_item_desc *desc,
69 int32_t value);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020070};
71
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010072struct stats_config {
73 int interval;
74};
75
76extern struct stats_config *stats_config;
77
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020078void stats_init(void *ctx);
79int stats_report();
80
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010081int stats_set_interval(int interval);
82
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020083struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type,
84 const char *name);
85void stats_reporter_free(struct stats_reporter *srep);
86struct stats_reporter *stats_reporter_create_statsd(const char *name);
87
88struct stats_reporter *stats_reporter_find(enum stats_reporter_type type,
89 const char *name);
90
91int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr);
92int stats_reporter_set_remote_port(struct stats_reporter *srep, int port);
93int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr);
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010094int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020095int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix);
96int stats_reporter_enable(struct stats_reporter *srep);
97int stats_reporter_disable(struct stats_reporter *srep);