blob: 7b3d0211bfea39ca18fce308ccd58ea318fc25c0 [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 Erlbeckfc9533d2015-10-29 00:55:58 +010026struct osmo_stat_item_group;
27struct osmo_stat_item_desc;
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010028struct rate_ctr_group;
29struct rate_ctr_desc;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010030
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010031enum osmo_stats_reporter_type {
32 OSMO_STATS_REPORTER_STATSD,
33 OSMO_STATS_REPORTER_LOG,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020034};
35
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010036struct osmo_stats_reporter {
37 enum osmo_stats_reporter_type type;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020038 char *name;
39
Jacob Erlbecked197fd2015-10-27 14:43:24 +010040 unsigned int have_net_config : 1;
41
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020042 /* config */
43 int enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020044 char *name_prefix;
45 char *dest_addr_str;
46 char *bind_addr_str;
47 int dest_port;
48 int mtu;
49
50 /* state */
51 int running;
52 struct sockaddr dest_addr;
53 int dest_addr_len;
54 struct sockaddr bind_addr;
55 int bind_addr_len;
56 int fd;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010057 struct msgb *buffer;
58 int agg_enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020059
60 struct llist_head list;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010061 int (*open)(struct osmo_stats_reporter *srep);
62 int (*close)(struct osmo_stats_reporter *srep);
63 int (*send_counter)(struct osmo_stats_reporter *srep,
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010064 const struct rate_ctr_group *ctrg,
65 const struct rate_ctr_desc *desc,
66 int64_t value, int64_t delta);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010067 int (*send_item)(struct osmo_stats_reporter *srep,
68 const struct osmo_stat_item_group *statg,
69 const struct osmo_stat_item_desc *desc,
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010070 int32_t value);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020071};
72
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010073struct osmo_stats_config {
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010074 int interval;
75};
76
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010077extern struct osmo_stats_config *osmo_stats_config;
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010078
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010079void osmo_stats_init(void *ctx);
80int osmo_stats_report();
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020081
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010082int osmo_stats_set_interval(int interval);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010083
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010084struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020085 const char *name);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010086void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +010087
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010088struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
89struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020090
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010091struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020092 const char *name);
93
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010094int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
95int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
96int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
97int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
98int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
99int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
100int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);