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