blob: 68c2e0161b3374b82d50a038203903bd26137a29 [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,
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +010033 STATS_REPORTER_LOG,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020034};
35
36struct stats_reporter {
37 enum stats_reporter_type type;
38 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 Erlbeck490b38f2015-10-27 15:10:28 +010061 int (*open)(struct stats_reporter *srep);
62 int (*close)(struct stats_reporter *srep);
63 int (*send_counter)(struct stats_reporter *srep,
64 const struct rate_ctr_group *ctrg,
65 const struct rate_ctr_desc *desc,
66 int64_t value, int64_t delta);
67 int (*send_item)(struct stats_reporter *srep,
68 const struct stat_item_group *statg,
69 const struct stat_item_desc *desc,
70 int32_t value);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020071};
72
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010073struct stats_config {
74 int interval;
75};
76
77extern struct stats_config *stats_config;
78
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020079void stats_init(void *ctx);
80int stats_report();
81
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010082int stats_set_interval(int interval);
83
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020084struct stats_reporter *stats_reporter_alloc(enum stats_reporter_type type,
85 const char *name);
86void stats_reporter_free(struct stats_reporter *srep);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +010087
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020088struct stats_reporter *stats_reporter_create_statsd(const char *name);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +010089struct stats_reporter *stats_reporter_create_log(const char *name);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020090
91struct stats_reporter *stats_reporter_find(enum stats_reporter_type type,
92 const char *name);
93
94int stats_reporter_set_remote_addr(struct stats_reporter *srep, const char *addr);
95int stats_reporter_set_remote_port(struct stats_reporter *srep, int port);
96int stats_reporter_set_local_addr(struct stats_reporter *srep, const char *addr);
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010097int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020098int stats_reporter_set_name_prefix(struct stats_reporter *srep, const char *prefix);
99int stats_reporter_enable(struct stats_reporter *srep);
100int stats_reporter_disable(struct stats_reporter *srep);