blob: f754e41df3b281f13fe069963dd90321a219f220 [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
Holger Hans Peter Freytherc3376932015-08-21 19:56:54 +000025#include <stdint.h>
26
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010027struct msgb;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010028struct osmo_stat_item_group;
29struct osmo_stat_item_desc;
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010030struct rate_ctr_group;
31struct rate_ctr_desc;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010032
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +010033enum osmo_stats_class {
34 OSMO_STATS_CLASS_UNKNOWN,
35 OSMO_STATS_CLASS_GLOBAL,
36 OSMO_STATS_CLASS_PEER,
37 OSMO_STATS_CLASS_SUBSCRIBER,
38};
39
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010040enum osmo_stats_reporter_type {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010041 OSMO_STATS_REPORTER_LOG,
Jacob Erlbeckb6e6bea2015-11-09 15:33:44 +010042 OSMO_STATS_REPORTER_STATSD,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020043};
44
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010045struct osmo_stats_reporter {
46 enum osmo_stats_reporter_type type;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020047 char *name;
48
Jacob Erlbecked197fd2015-10-27 14:43:24 +010049 unsigned int have_net_config : 1;
50
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020051 /* config */
52 int enabled;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020053 char *name_prefix;
54 char *dest_addr_str;
55 char *bind_addr_str;
56 int dest_port;
57 int mtu;
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +010058 enum osmo_stats_class max_class;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020059
60 /* state */
61 int running;
62 struct sockaddr dest_addr;
63 int dest_addr_len;
64 struct sockaddr bind_addr;
65 int bind_addr_len;
66 int fd;
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +010067 struct msgb *buffer;
68 int agg_enabled;
Jacob Erlbeckaed7c122015-11-09 11:25:12 +010069 int force_single_flush;
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020070
71 struct llist_head list;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010072 int (*open)(struct osmo_stats_reporter *srep);
73 int (*close)(struct osmo_stats_reporter *srep);
74 int (*send_counter)(struct osmo_stats_reporter *srep,
Jacob Erlbeck490b38f2015-10-27 15:10:28 +010075 const struct rate_ctr_group *ctrg,
76 const struct rate_ctr_desc *desc,
77 int64_t value, int64_t delta);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010078 int (*send_item)(struct osmo_stats_reporter *srep,
79 const struct osmo_stat_item_group *statg,
80 const struct osmo_stat_item_desc *desc,
Harald Welte1554f802016-11-11 15:06:06 +010081 int64_t value);
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020082};
83
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010084struct osmo_stats_config {
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010085 int interval;
86};
87
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010088extern struct osmo_stats_config *osmo_stats_config;
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010089
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010090void osmo_stats_init(void *ctx);
91int osmo_stats_report();
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020092
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010093int osmo_stats_set_interval(int interval);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +010094
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010095struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type,
Jacob Erlbeck95bf82802015-10-20 19:05:52 +020096 const char *name);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010097void osmo_stats_reporter_free(struct osmo_stats_reporter *srep);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +010098
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);
Jacob Erlbeckb6e6bea2015-11-09 15:33:44 +0100111
112/* reporter creation */
113struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
114struct osmo_stats_reporter *osmo_stats_reporter_create_statsd(const char *name);
115
116/* helper functions for reporter implementations */
117int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
118 int data_len);
119int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep);
120int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep);
121int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep);