blob: 731fdb9b133acfe0ff7b2c91d6ee9a5a11353d6f [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 Erlbeckbc9d9ac2015-11-02 14:49:35 +010031enum osmo_stats_class {
32 OSMO_STATS_CLASS_UNKNOWN,
33 OSMO_STATS_CLASS_GLOBAL,
34 OSMO_STATS_CLASS_PEER,
35 OSMO_STATS_CLASS_SUBSCRIBER,
36};
37
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010038enum osmo_stats_reporter_type {
39 OSMO_STATS_REPORTER_STATSD,
40 OSMO_STATS_REPORTER_LOG,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020041};
42
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010043struct osmo_stats_reporter {
44 enum osmo_stats_reporter_type type;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020045 char *name;
46
Jacob Erlbecked197fd2015-10-27 14:43:24 +010047 unsigned int have_net_config : 1;
48
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020049 /* config */
50 int enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020051 char *name_prefix;
52 char *dest_addr_str;
53 char *bind_addr_str;
54 int dest_port;
55 int mtu;
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +010056 enum osmo_stats_class max_class;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020057
58 /* state */
59 int running;
60 struct sockaddr dest_addr;
61 int dest_addr_len;
62 struct sockaddr bind_addr;
63 int bind_addr_len;
64 int fd;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010065 struct msgb *buffer;
66 int agg_enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020067
68 struct llist_head list;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010069 int (*open)(struct osmo_stats_reporter *srep);
70 int (*close)(struct osmo_stats_reporter *srep);
71 int (*send_counter)(struct osmo_stats_reporter *srep,
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010072 const struct rate_ctr_group *ctrg,
73 const struct rate_ctr_desc *desc,
74 int64_t value, int64_t delta);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010075 int (*send_item)(struct osmo_stats_reporter *srep,
76 const struct osmo_stat_item_group *statg,
77 const struct osmo_stat_item_desc *desc,
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010078 int32_t value);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020079};
80
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010081struct osmo_stats_config {
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010082 int interval;
83};
84
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010085extern struct osmo_stats_config *osmo_stats_config;
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010086
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010087void osmo_stats_init(void *ctx);
88int osmo_stats_report();
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020089
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010090int osmo_stats_set_interval(int interval);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010091
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010092struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020093 const char *name);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010094void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +010095
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010096struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
97struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020098
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010099struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +0200100 const char *name);
101
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100102int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr);
103int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port);
104int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr);
105int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu);
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100106int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
107 enum osmo_stats_class class_id);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100108int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
109int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
110int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);