Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2015 by Sysmocom s.f.m.c. GmbH |
| 3 | * |
| 4 | * Author: Jacob Erlbeck <jerlbeck@sysmocom.de> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 24 | #include "config.h" |
| 25 | #if !defined(EMBEDDED) |
| 26 | |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 27 | #include <osmocom/core/byteswap.h> |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 28 | #include <osmocom/core/stats.h> |
| 29 | |
| 30 | #include <unistd.h> |
| 31 | #include <string.h> |
| 32 | #include <stdint.h> |
| 33 | #include <errno.h> |
| 34 | #include <stdio.h> |
Holger Hans Peter Freyther | c337693 | 2015-08-21 19:56:54 +0000 | [diff] [blame] | 35 | #include <sys/types.h> |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 36 | |
| 37 | #ifdef HAVE_SYS_SOCKET_H |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 38 | #include <sys/socket.h> |
Holger Hans Peter Freyther | c337693 | 2015-08-21 19:56:54 +0000 | [diff] [blame] | 39 | #include <netinet/in.h> |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 40 | #include <arpa/inet.h> |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 41 | #endif |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 42 | |
| 43 | #include <osmocom/core/utils.h> |
| 44 | #include <osmocom/core/logging.h> |
| 45 | #include <osmocom/core/rate_ctr.h> |
| 46 | #include <osmocom/core/stat_item.h> |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 47 | #include <osmocom/core/timer.h> |
Jacob Erlbeck | c8f47b6 | 2015-10-26 14:42:05 +0100 | [diff] [blame] | 48 | #include <osmocom/core/statistics.h> |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 49 | #include <osmocom/core/msgb.h> |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 50 | |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 51 | #define STATS_DEFAULT_INTERVAL 5 /* secs */ |
Jacob Erlbeck | b6e6bea | 2015-11-09 15:33:44 +0100 | [diff] [blame] | 52 | #define STATS_DEFAULT_BUFLEN 256 |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 53 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 54 | static LLIST_HEAD(osmo_stats_reporter_list); |
| 55 | static void *osmo_stats_ctx = NULL; |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 56 | static int is_initialised = 0; |
| 57 | static int32_t current_stat_item_index = 0; |
| 58 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 59 | static struct osmo_stats_config s_stats_config = { |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 60 | .interval = STATS_DEFAULT_INTERVAL, |
| 61 | }; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 62 | struct osmo_stats_config *osmo_stats_config = &s_stats_config; |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 63 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 64 | static struct osmo_timer_list osmo_stats_timer; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 65 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 66 | static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep, |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 67 | const struct rate_ctr_group *ctrg, |
| 68 | const struct rate_ctr_desc *desc, |
| 69 | int64_t value, int64_t delta); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 70 | static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep, |
| 71 | const struct osmo_stat_item_group *statg, |
Harald Welte | 1554f80 | 2016-11-11 15:06:06 +0100 | [diff] [blame] | 72 | const struct osmo_stat_item_desc *desc, int64_t value); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 73 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 74 | static int update_srep_config(struct osmo_stats_reporter *srep) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 75 | { |
| 76 | int rc = 0; |
| 77 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 78 | if (srep->running) { |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame] | 79 | if (srep->close) |
| 80 | rc = srep->close(srep); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 81 | srep->running = 0; |
| 82 | } |
| 83 | |
| 84 | if (!srep->enabled) |
| 85 | return rc; |
| 86 | |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame] | 87 | if (srep->open) |
| 88 | rc = srep->open(srep); |
| 89 | else |
| 90 | rc = 0; |
| 91 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 92 | if (rc < 0) |
| 93 | srep->enabled = 0; |
| 94 | else |
| 95 | srep->running = 1; |
| 96 | |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 97 | srep->force_single_flush = 1; |
| 98 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 99 | return rc; |
| 100 | } |
| 101 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 102 | static void osmo_stats_timer_cb(void *data) |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 103 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 104 | int interval = osmo_stats_config->interval; |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 105 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 106 | if (!llist_empty(&osmo_stats_reporter_list)) |
| 107 | osmo_stats_report(); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 108 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 109 | osmo_timer_schedule(&osmo_stats_timer, interval, 0); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static int start_timer() |
| 113 | { |
| 114 | if (!is_initialised) |
| 115 | return -ESRCH; |
| 116 | |
Pablo Neira Ayuso | 44f423f | 2017-05-08 18:00:28 +0200 | [diff] [blame] | 117 | osmo_timer_setup(&osmo_stats_timer, osmo_stats_timer_cb, NULL); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 118 | osmo_timer_schedule(&osmo_stats_timer, 0, 1); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 123 | struct osmo_stats_reporter *osmo_stats_reporter_alloc(enum osmo_stats_reporter_type type, |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 124 | const char *name) |
| 125 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 126 | struct osmo_stats_reporter *srep; |
| 127 | srep = talloc_zero(osmo_stats_ctx, struct osmo_stats_reporter); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 128 | OSMO_ASSERT(srep); |
| 129 | srep->type = type; |
| 130 | if (name) |
| 131 | srep->name = talloc_strdup(srep, name); |
| 132 | srep->fd = -1; |
| 133 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 134 | llist_add(&srep->list, &osmo_stats_reporter_list); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 135 | |
| 136 | return srep; |
| 137 | } |
| 138 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 139 | void osmo_stats_reporter_free(struct osmo_stats_reporter *srep) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 140 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 141 | osmo_stats_reporter_disable(srep); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 142 | llist_del(&srep->list); |
| 143 | talloc_free(srep); |
| 144 | } |
| 145 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 146 | void osmo_stats_init(void *ctx) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 147 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 148 | osmo_stats_ctx = ctx; |
| 149 | osmo_stat_item_discard_all(¤t_stat_item_index); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 150 | |
| 151 | is_initialised = 1; |
| 152 | start_timer(); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 155 | struct osmo_stats_reporter *osmo_stats_reporter_find(enum osmo_stats_reporter_type type, |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 156 | const char *name) |
| 157 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 158 | struct osmo_stats_reporter *srep; |
| 159 | llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 160 | if (srep->type != type) |
| 161 | continue; |
| 162 | if (srep->name != name) { |
| 163 | if (name == NULL || srep->name == NULL || |
| 164 | strcmp(name, srep->name) != 0) |
| 165 | continue; |
| 166 | } |
| 167 | return srep; |
| 168 | } |
| 169 | return NULL; |
| 170 | } |
| 171 | |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 172 | #ifdef HAVE_SYS_SOCKET_H |
| 173 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 174 | int osmo_stats_reporter_set_remote_addr(struct osmo_stats_reporter *srep, const char *addr) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 175 | { |
| 176 | int rc; |
| 177 | struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr; |
| 178 | struct in_addr inaddr; |
| 179 | |
Jacob Erlbeck | ed197fd | 2015-10-27 14:43:24 +0100 | [diff] [blame] | 180 | if (!srep->have_net_config) |
| 181 | return -ENOTSUP; |
| 182 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 183 | OSMO_ASSERT(addr != NULL); |
| 184 | |
| 185 | rc = inet_pton(AF_INET, addr, &inaddr); |
| 186 | if (rc <= 0) |
| 187 | return -EINVAL; |
| 188 | |
| 189 | sock_addr->sin_addr = inaddr; |
| 190 | sock_addr->sin_family = AF_INET; |
| 191 | srep->dest_addr_len = sizeof(*sock_addr); |
| 192 | |
| 193 | talloc_free(srep->dest_addr_str); |
| 194 | srep->dest_addr_str = talloc_strdup(srep, addr); |
| 195 | |
| 196 | return update_srep_config(srep); |
| 197 | } |
| 198 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 199 | int osmo_stats_reporter_set_remote_port(struct osmo_stats_reporter *srep, int port) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 200 | { |
| 201 | struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr; |
| 202 | |
Jacob Erlbeck | ed197fd | 2015-10-27 14:43:24 +0100 | [diff] [blame] | 203 | if (!srep->have_net_config) |
| 204 | return -ENOTSUP; |
| 205 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 206 | srep->dest_port = port; |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 207 | sock_addr->sin_port = osmo_htons(port); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 208 | |
| 209 | return update_srep_config(srep); |
| 210 | } |
| 211 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 212 | int osmo_stats_reporter_set_local_addr(struct osmo_stats_reporter *srep, const char *addr) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 213 | { |
| 214 | int rc; |
| 215 | struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->bind_addr; |
| 216 | struct in_addr inaddr; |
| 217 | |
Jacob Erlbeck | ed197fd | 2015-10-27 14:43:24 +0100 | [diff] [blame] | 218 | if (!srep->have_net_config) |
| 219 | return -ENOTSUP; |
| 220 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 221 | if (addr) { |
| 222 | rc = inet_pton(AF_INET, addr, &inaddr); |
| 223 | if (rc <= 0) |
| 224 | return -EINVAL; |
| 225 | } else { |
Holger Hans Peter Freyther | 7921975 | 2015-11-02 15:50:32 +0100 | [diff] [blame] | 226 | inaddr.s_addr = INADDR_ANY; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | sock_addr->sin_addr = inaddr; |
| 230 | sock_addr->sin_family = AF_INET; |
| 231 | srep->bind_addr_len = addr ? sizeof(*sock_addr) : 0; |
| 232 | |
| 233 | talloc_free(srep->bind_addr_str); |
| 234 | srep->bind_addr_str = addr ? talloc_strdup(srep, addr) : NULL; |
| 235 | |
| 236 | return update_srep_config(srep); |
| 237 | } |
| 238 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 239 | int osmo_stats_reporter_set_mtu(struct osmo_stats_reporter *srep, int mtu) |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 240 | { |
Jacob Erlbeck | ed197fd | 2015-10-27 14:43:24 +0100 | [diff] [blame] | 241 | if (!srep->have_net_config) |
| 242 | return -ENOTSUP; |
| 243 | |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 244 | if (mtu < 0) |
| 245 | return -EINVAL; |
| 246 | |
| 247 | srep->mtu = mtu; |
| 248 | |
| 249 | return update_srep_config(srep); |
| 250 | } |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 251 | #endif /* HAVE_SYS_SOCKETS_H */ |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 252 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 253 | int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep, |
| 254 | enum osmo_stats_class class_id) |
| 255 | { |
| 256 | if (class_id == OSMO_STATS_CLASS_UNKNOWN) |
| 257 | return -EINVAL; |
| 258 | |
| 259 | srep->max_class = class_id; |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 264 | int osmo_stats_set_interval(int interval) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 265 | { |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 266 | if (interval <= 0) |
| 267 | return -EINVAL; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 268 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 269 | osmo_stats_config->interval = interval; |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 270 | if (is_initialised) |
| 271 | start_timer(); |
| 272 | |
| 273 | return 0; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 276 | int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 277 | { |
| 278 | talloc_free(srep->name_prefix); |
Jacob Erlbeck | 916423e | 2015-11-09 10:52:19 +0100 | [diff] [blame] | 279 | srep->name_prefix = prefix && strlen(prefix) > 0 ? |
| 280 | talloc_strdup(srep, prefix) : NULL; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 281 | |
| 282 | return update_srep_config(srep); |
| 283 | } |
| 284 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 285 | int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 286 | { |
| 287 | srep->enabled = 1; |
| 288 | |
| 289 | return update_srep_config(srep); |
| 290 | } |
| 291 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 292 | int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 293 | { |
| 294 | srep->enabled = 0; |
| 295 | |
| 296 | return update_srep_config(srep); |
| 297 | } |
| 298 | |
Jacob Erlbeck | 2e8f9ed | 2015-11-09 15:48:25 +0100 | [diff] [blame] | 299 | /*** i/o helper functions ***/ |
| 300 | |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 301 | #ifdef HAVE_SYS_SOCKET_H |
| 302 | |
Jacob Erlbeck | 2e8f9ed | 2015-11-09 15:48:25 +0100 | [diff] [blame] | 303 | int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep) |
| 304 | { |
| 305 | int sock; |
| 306 | int rc; |
| 307 | int buffer_size = STATS_DEFAULT_BUFLEN; |
| 308 | |
| 309 | if (srep->fd != -1 && srep->close) |
| 310 | srep->close(srep); |
| 311 | |
| 312 | sock = socket(AF_INET, SOCK_DGRAM, 0); |
| 313 | if (sock == -1) |
| 314 | return -errno; |
| 315 | |
Arran Cudbard-Bell | cc3694b | 2016-05-18 16:02:19 -0400 | [diff] [blame] | 316 | #if defined(__APPLE__) && !defined(MSG_NOSIGNAL) |
| 317 | { |
| 318 | static int val = 1; |
| 319 | |
| 320 | rc = setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void*)&val, sizeof(val)); |
| 321 | goto failed; |
| 322 | } |
| 323 | #endif |
Jacob Erlbeck | 2e8f9ed | 2015-11-09 15:48:25 +0100 | [diff] [blame] | 324 | if (srep->bind_addr_len > 0) { |
| 325 | rc = bind(sock, &srep->bind_addr, srep->bind_addr_len); |
| 326 | if (rc == -1) |
| 327 | goto failed; |
| 328 | } |
| 329 | |
| 330 | srep->fd = sock; |
| 331 | |
| 332 | if (srep->mtu > 0) { |
| 333 | buffer_size = srep->mtu - 20 /* IP */ - 8 /* UDP */; |
| 334 | srep->agg_enabled = 1; |
| 335 | } |
| 336 | |
| 337 | srep->buffer = msgb_alloc(buffer_size, "stats buffer"); |
| 338 | |
| 339 | return 0; |
| 340 | |
| 341 | failed: |
| 342 | rc = -errno; |
| 343 | close(sock); |
| 344 | |
| 345 | return rc; |
| 346 | } |
| 347 | |
| 348 | int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep) |
| 349 | { |
| 350 | int rc; |
| 351 | if (srep->fd == -1) |
| 352 | return -EBADF; |
| 353 | |
| 354 | osmo_stats_reporter_send_buffer(srep); |
| 355 | |
| 356 | rc = close(srep->fd); |
| 357 | srep->fd = -1; |
| 358 | msgb_free(srep->buffer); |
| 359 | srep->buffer = NULL; |
| 360 | return rc == -1 ? -errno : 0; |
| 361 | } |
| 362 | |
Jacob Erlbeck | b6e6bea | 2015-11-09 15:33:44 +0100 | [diff] [blame] | 363 | int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data, |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 364 | int data_len) |
| 365 | { |
| 366 | int rc; |
| 367 | |
Arran Cudbard-Bell | cc3694b | 2016-05-18 16:02:19 -0400 | [diff] [blame] | 368 | rc = sendto(srep->fd, data, data_len, |
| 369 | #ifdef MSG_NOSIGNAL |
| 370 | MSG_NOSIGNAL | |
| 371 | #endif |
| 372 | MSG_DONTWAIT, |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 373 | &srep->dest_addr, srep->dest_addr_len); |
| 374 | |
| 375 | if (rc == -1) |
| 376 | rc = -errno; |
| 377 | |
| 378 | return rc; |
| 379 | } |
| 380 | |
Jacob Erlbeck | b6e6bea | 2015-11-09 15:33:44 +0100 | [diff] [blame] | 381 | int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep) |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 382 | { |
| 383 | int rc; |
| 384 | |
| 385 | if (!srep->buffer || msgb_length(srep->buffer) == 0) |
| 386 | return 0; |
| 387 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 388 | rc = osmo_stats_reporter_send(srep, |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 389 | (const char *)msgb_data(srep->buffer), msgb_length(srep->buffer)); |
| 390 | |
| 391 | msgb_trim(srep->buffer, 0); |
| 392 | |
| 393 | return rc; |
| 394 | } |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 395 | #endif /* HAVE_SYS_SOCKET_H */ |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 396 | |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 397 | /*** log reporter ***/ |
| 398 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 399 | struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name) |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 400 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 401 | struct osmo_stats_reporter *srep; |
| 402 | srep = osmo_stats_reporter_alloc(OSMO_STATS_REPORTER_LOG, name); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 403 | |
| 404 | srep->have_net_config = 0; |
| 405 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 406 | srep->send_counter = osmo_stats_reporter_log_send_counter; |
| 407 | srep->send_item = osmo_stats_reporter_log_send_item; |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 408 | |
| 409 | return srep; |
| 410 | } |
| 411 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 412 | static int osmo_stats_reporter_log_send(struct osmo_stats_reporter *srep, |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 413 | const char *type, |
Jacob Erlbeck | 16fe8da | 2015-11-02 11:30:01 +0100 | [diff] [blame] | 414 | const char *name1, unsigned int index1, const char *name2, int value, |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 415 | const char *unit) |
| 416 | { |
Jacob Erlbeck | 79125ec | 2015-11-02 15:17:50 +0100 | [diff] [blame] | 417 | LOGP(DLSTATS, LOGL_INFO, |
Jacob Erlbeck | 16fe8da | 2015-11-02 11:30:01 +0100 | [diff] [blame] | 418 | "stats t=%s p=%s g=%s i=%u n=%s v=%d u=%s\n", |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 419 | type, srep->name_prefix ? srep->name_prefix : "", |
| 420 | name1 ? name1 : "", index1, |
| 421 | name2, value, unit ? unit : ""); |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 427 | static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep, |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 428 | const struct rate_ctr_group *ctrg, |
| 429 | const struct rate_ctr_desc *desc, |
| 430 | int64_t value, int64_t delta) |
| 431 | { |
| 432 | if (ctrg) |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 433 | return osmo_stats_reporter_log_send(srep, "c", |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 434 | ctrg->desc->group_name_prefix, |
| 435 | ctrg->idx, |
| 436 | desc->name, value, NULL); |
| 437 | else |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 438 | return osmo_stats_reporter_log_send(srep, "c", |
Jacob Erlbeck | 16fe8da | 2015-11-02 11:30:01 +0100 | [diff] [blame] | 439 | NULL, 0, |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 440 | desc->name, value, NULL); |
| 441 | } |
| 442 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 443 | static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep, |
| 444 | const struct osmo_stat_item_group *statg, |
Harald Welte | 1554f80 | 2016-11-11 15:06:06 +0100 | [diff] [blame] | 445 | const struct osmo_stat_item_desc *desc, int64_t value) |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 446 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 447 | return osmo_stats_reporter_log_send(srep, "i", |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 448 | statg->desc->group_name_prefix, statg->idx, |
| 449 | desc->name, value, desc->unit); |
| 450 | } |
| 451 | |
Jacob Erlbeck | 2e8f9ed | 2015-11-09 15:48:25 +0100 | [diff] [blame] | 452 | /*** helper for reporting ***/ |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 453 | |
Jacob Erlbeck | 2e8f9ed | 2015-11-09 15:48:25 +0100 | [diff] [blame] | 454 | static int osmo_stats_reporter_check_config(struct osmo_stats_reporter *srep, |
| 455 | unsigned int index, int class_id) |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 456 | { |
Jacob Erlbeck | 2e8f9ed | 2015-11-09 15:48:25 +0100 | [diff] [blame] | 457 | if (class_id == OSMO_STATS_CLASS_UNKNOWN) |
| 458 | class_id = index != 0 ? |
| 459 | OSMO_STATS_CLASS_SUBSCRIBER : OSMO_STATS_CLASS_GLOBAL; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 460 | |
Jacob Erlbeck | 2e8f9ed | 2015-11-09 15:48:25 +0100 | [diff] [blame] | 461 | return class_id <= srep->max_class; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 462 | } |
| 463 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 464 | /*** generic rate counter support ***/ |
| 465 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 466 | static int osmo_stats_reporter_send_counter(struct osmo_stats_reporter *srep, |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 467 | const struct rate_ctr_group *ctrg, |
| 468 | const struct rate_ctr_desc *desc, |
| 469 | int64_t value, int64_t delta) |
| 470 | { |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame] | 471 | if (!srep->send_counter) |
| 472 | return 0; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 473 | |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame] | 474 | return srep->send_counter(srep, ctrg, desc, value, delta); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static int rate_ctr_handler( |
| 478 | struct rate_ctr_group *ctrg, struct rate_ctr *ctr, |
| 479 | const struct rate_ctr_desc *desc, void *sctx_) |
| 480 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 481 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 482 | int64_t delta = rate_ctr_difference(ctr); |
| 483 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 484 | llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 485 | if (!srep->running) |
| 486 | continue; |
| 487 | |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 488 | if (delta == 0 && !srep->force_single_flush) |
| 489 | continue; |
| 490 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 491 | if (!osmo_stats_reporter_check_config(srep, |
| 492 | ctrg->idx, ctrg->desc->class_id)) |
Jacob Erlbeck | 8a97cb9 | 2015-11-09 11:39:42 +0100 | [diff] [blame] | 493 | continue; |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 494 | |
Holger Hans Peter Freyther | 837e940 | 2015-11-02 15:44:26 +0100 | [diff] [blame] | 495 | osmo_stats_reporter_send_counter(srep, ctrg, desc, |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 496 | ctr->current, delta); |
| 497 | |
Holger Hans Peter Freyther | 837e940 | 2015-11-02 15:44:26 +0100 | [diff] [blame] | 498 | /* TODO: handle result (log?, inc counter(!)?) or remove it */ |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static int rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_) |
| 505 | { |
| 506 | rate_ctr_for_each_counter(ctrg, rate_ctr_handler, sctx_); |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 511 | /*** stat item support ***/ |
| 512 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 513 | static int osmo_stats_reporter_send_item(struct osmo_stats_reporter *srep, |
| 514 | const struct osmo_stat_item_group *statg, |
| 515 | const struct osmo_stat_item_desc *desc, |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 516 | int32_t value) |
| 517 | { |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame] | 518 | if (!srep->send_item) |
| 519 | return 0; |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 520 | |
Jacob Erlbeck | 490b38f | 2015-10-27 15:10:28 +0100 | [diff] [blame] | 521 | return srep->send_item(srep, statg, desc, value); |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 522 | } |
| 523 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 524 | static int osmo_stat_item_handler( |
| 525 | struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_) |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 526 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 527 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 528 | int32_t idx = current_stat_item_index; |
| 529 | int32_t value; |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 530 | int have_value; |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 531 | |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 532 | have_value = osmo_stat_item_get_next(item, &idx, &value) > 0; |
| 533 | if (!have_value) |
| 534 | /* Send the last value in case a flush is requested */ |
| 535 | value = osmo_stat_item_get_last(item); |
| 536 | |
| 537 | do { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 538 | llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 539 | if (!srep->running) |
| 540 | continue; |
| 541 | |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 542 | if (!have_value && !srep->force_single_flush) |
| 543 | continue; |
| 544 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 545 | if (!osmo_stats_reporter_check_config(srep, |
| 546 | statg->idx, statg->desc->class_id)) |
Jacob Erlbeck | 8a97cb9 | 2015-11-09 11:39:42 +0100 | [diff] [blame] | 547 | continue; |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 548 | |
Holger Hans Peter Freyther | 837e940 | 2015-11-02 15:44:26 +0100 | [diff] [blame] | 549 | osmo_stats_reporter_send_item(srep, statg, |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 550 | item->desc, value); |
| 551 | } |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 552 | |
| 553 | if (!have_value) |
| 554 | break; |
| 555 | |
| 556 | have_value = osmo_stat_item_get_next(item, &idx, &value) > 0; |
| 557 | } while (have_value); |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 562 | static int osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_) |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 563 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 564 | osmo_stat_item_for_each_item(statg, osmo_stat_item_handler, sctx_); |
Jacob Erlbeck | c27671c | 2015-10-26 12:32:07 +0100 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 568 | |
Jacob Erlbeck | c8f47b6 | 2015-10-26 14:42:05 +0100 | [diff] [blame] | 569 | /*** osmo counter support ***/ |
| 570 | |
| 571 | static int handle_counter(struct osmo_counter *counter, void *sctx_) |
| 572 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 573 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | c8f47b6 | 2015-10-26 14:42:05 +0100 | [diff] [blame] | 574 | struct rate_ctr_desc desc = {0}; |
| 575 | /* Fake a rate counter description */ |
| 576 | desc.name = counter->name; |
| 577 | desc.description = counter->description; |
| 578 | |
| 579 | int delta = osmo_counter_difference(counter); |
| 580 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 581 | llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { |
Jacob Erlbeck | c8f47b6 | 2015-10-26 14:42:05 +0100 | [diff] [blame] | 582 | if (!srep->running) |
| 583 | continue; |
| 584 | |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 585 | if (delta == 0 && !srep->force_single_flush) |
| 586 | continue; |
| 587 | |
Holger Hans Peter Freyther | 837e940 | 2015-11-02 15:44:26 +0100 | [diff] [blame] | 588 | osmo_stats_reporter_send_counter(srep, NULL, &desc, |
Jacob Erlbeck | c8f47b6 | 2015-10-26 14:42:05 +0100 | [diff] [blame] | 589 | counter->value, delta); |
| 590 | |
Holger Hans Peter Freyther | 837e940 | 2015-11-02 15:44:26 +0100 | [diff] [blame] | 591 | /* TODO: handle result (log?, inc counter(!)?) */ |
Jacob Erlbeck | c8f47b6 | 2015-10-26 14:42:05 +0100 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 598 | /*** main reporting function ***/ |
| 599 | |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 600 | static void flush_all_reporters() |
| 601 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 602 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 603 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 604 | llist_for_each_entry(srep, &osmo_stats_reporter_list, list) { |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 605 | if (!srep->running) |
| 606 | continue; |
| 607 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 608 | osmo_stats_reporter_send_buffer(srep); |
Jacob Erlbeck | aed7c12 | 2015-11-09 11:25:12 +0100 | [diff] [blame] | 609 | srep->force_single_flush = 0; |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 613 | int osmo_stats_report() |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 614 | { |
Jacob Erlbeck | 01e8c91 | 2015-11-09 14:13:23 +0100 | [diff] [blame] | 615 | /* per group actions */ |
Jacob Erlbeck | c8f47b6 | 2015-10-26 14:42:05 +0100 | [diff] [blame] | 616 | osmo_counters_for_each(handle_counter, NULL); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 617 | rate_ctr_for_each_group(rate_ctr_group_handler, NULL); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 618 | osmo_stat_item_for_each_group(osmo_stat_item_group_handler, NULL); |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 619 | |
Jacob Erlbeck | 01e8c91 | 2015-11-09 14:13:23 +0100 | [diff] [blame] | 620 | /* global actions */ |
| 621 | osmo_stat_item_discard_all(¤t_stat_item_index); |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 622 | flush_all_reporters(); |
| 623 | |
Jacob Erlbeck | 95bf8280 | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 624 | return 0; |
| 625 | } |
Harald Welte | 67bdd80 | 2017-01-15 17:56:11 +0100 | [diff] [blame] | 626 | |
| 627 | #endif /* !EMBEDDED */ |