Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 1 | /* OpenBSC stats helper for the VTY */ |
| 2 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
| 3 | * (C) 2009-2014 by Holger Hans Peter Freyther |
| 4 | * (C) 2015 by Sysmocom s.f.m.c. GmbH |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | |
| 26 | #include "../../config.h" |
| 27 | |
| 28 | #include <osmocom/vty/command.h> |
| 29 | #include <osmocom/vty/buffer.h> |
| 30 | #include <osmocom/vty/vty.h> |
| 31 | #include <osmocom/vty/telnet_interface.h> |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 32 | #include <osmocom/vty/telnet_interface.h> |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 33 | #include <osmocom/vty/misc.h> |
| 34 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 35 | #include <osmocom/core/stats.h> |
Alexander Couzens | ad580ba | 2016-05-16 16:01:45 +0200 | [diff] [blame] | 36 | #include <osmocom/core/statistics.h> |
| 37 | #include <osmocom/core/rate_ctr.h> |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 38 | |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 39 | #define CFG_STATS_STR "Configure stats sub-system\n" |
| 40 | #define CFG_REPORTER_STR "Configure a stats reporter\n" |
| 41 | |
| 42 | #define SHOW_STATS_STR "Show statistical values\n" |
| 43 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 44 | struct cmd_node cfg_stats_node = { |
| 45 | CFG_STATS_NODE, |
| 46 | "%s(config-stats)# ", |
| 47 | 1 |
| 48 | }; |
| 49 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 50 | static const struct value_string stats_class_strs[] = { |
| 51 | { OSMO_STATS_CLASS_GLOBAL, "global" }, |
| 52 | { OSMO_STATS_CLASS_PEER, "peer" }, |
| 53 | { OSMO_STATS_CLASS_SUBSCRIBER, "subscriber" }, |
| 54 | { 0, NULL } |
| 55 | }; |
| 56 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 57 | static struct osmo_stats_reporter *osmo_stats_vty2srep(struct vty *vty) |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 58 | { |
| 59 | if (vty->node == CFG_STATS_NODE) |
| 60 | return vty->index; |
| 61 | |
| 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | static int set_srep_parameter_str(struct vty *vty, |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 66 | int (*fun)(struct osmo_stats_reporter *, const char *), |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 67 | const char *val, const char *param_name) |
| 68 | { |
| 69 | int rc; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 70 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 71 | OSMO_ASSERT(srep); |
| 72 | |
| 73 | rc = fun(srep, val); |
| 74 | if (rc < 0) { |
| 75 | vty_out(vty, "%% Unable to set %s: %s%s", |
| 76 | param_name, strerror(-rc), VTY_NEWLINE); |
| 77 | return CMD_WARNING; |
| 78 | } |
| 79 | |
| 80 | return CMD_SUCCESS; |
| 81 | } |
| 82 | |
| 83 | static int set_srep_parameter_int(struct vty *vty, |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 84 | int (*fun)(struct osmo_stats_reporter *, int), |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 85 | const char *val, const char *param_name) |
| 86 | { |
| 87 | int rc; |
| 88 | int int_val; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 89 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 90 | OSMO_ASSERT(srep); |
| 91 | |
| 92 | int_val = atoi(val); |
| 93 | |
| 94 | rc = fun(srep, int_val); |
| 95 | if (rc < 0) { |
| 96 | vty_out(vty, "%% Unable to set %s: %s%s", |
| 97 | param_name, strerror(-rc), VTY_NEWLINE); |
| 98 | return CMD_WARNING; |
| 99 | } |
| 100 | |
| 101 | return CMD_SUCCESS; |
| 102 | } |
| 103 | |
| 104 | DEFUN(cfg_stats_reporter_local_ip, cfg_stats_reporter_local_ip_cmd, |
| 105 | "local-ip ADDR", |
| 106 | "Set the IP address to which we bind locally\n" |
| 107 | "IP Address\n") |
| 108 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 109 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 110 | argv[0], "local address"); |
| 111 | } |
| 112 | |
| 113 | DEFUN(cfg_no_stats_reporter_local_ip, cfg_no_stats_reporter_local_ip_cmd, |
| 114 | "no local-ip", |
| 115 | NO_STR |
| 116 | "Set the IP address to which we bind locally\n") |
| 117 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 118 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 119 | NULL, "local address"); |
| 120 | } |
| 121 | |
| 122 | DEFUN(cfg_stats_reporter_remote_ip, cfg_stats_reporter_remote_ip_cmd, |
| 123 | "remote-ip ADDR", |
| 124 | "Set the remote IP address to which we connect\n" |
| 125 | "IP Address\n") |
| 126 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 127 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_remote_addr, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 128 | argv[0], "remote address"); |
| 129 | } |
| 130 | |
| 131 | DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd, |
| 132 | "remote-port <1-65535>", |
| 133 | "Set the remote port to which we connect\n" |
| 134 | "Remote port number\n") |
| 135 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 136 | return set_srep_parameter_int(vty, osmo_stats_reporter_set_remote_port, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 137 | argv[0], "remote port"); |
| 138 | } |
| 139 | |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 140 | DEFUN(cfg_stats_reporter_mtu, cfg_stats_reporter_mtu_cmd, |
| 141 | "mtu <100-65535>", |
| 142 | "Set the maximum packet size\n" |
| 143 | "Size in byte\n") |
| 144 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 145 | return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 146 | argv[0], "mtu"); |
| 147 | } |
| 148 | |
| 149 | DEFUN(cfg_no_stats_reporter_mtu, cfg_no_stats_reporter_mtu_cmd, |
| 150 | "no mtu", |
| 151 | NO_STR "Set the maximum packet size\n") |
| 152 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 153 | return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, |
Holger Hans Peter Freyther | 8f0374f | 2015-11-02 15:53:09 +0100 | [diff] [blame] | 154 | "0", "mtu"); |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 157 | DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, |
| 158 | "prefix PREFIX", |
| 159 | "Set the item name prefix\n" |
| 160 | "The prefix string\n") |
| 161 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 162 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 163 | argv[0], "prefix string"); |
| 164 | } |
| 165 | |
| 166 | DEFUN(cfg_no_stats_reporter_prefix, cfg_no_stats_reporter_prefix_cmd, |
| 167 | "no prefix", |
| 168 | NO_STR |
| 169 | "Set the item name prefix\n") |
| 170 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 171 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 172 | "", "prefix string"); |
| 173 | } |
| 174 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 175 | DEFUN(cfg_stats_reporter_level, cfg_stats_reporter_level_cmd, |
| 176 | "level (global|peer|subscriber)", |
| 177 | "Set the maximum group level\n" |
| 178 | "Report global groups only\n" |
| 179 | "Report global and network peer related groups\n" |
| 180 | "Report global, peer, and subscriber groups\n") |
| 181 | { |
| 182 | int level = get_string_value(stats_class_strs, argv[0]); |
| 183 | int rc; |
| 184 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
| 185 | |
| 186 | OSMO_ASSERT(srep); |
| 187 | rc = osmo_stats_reporter_set_max_class(srep, level); |
| 188 | if (rc < 0) { |
| 189 | vty_out(vty, "%% Unable to set level: %s%s", |
| 190 | strerror(-rc), VTY_NEWLINE); |
| 191 | return CMD_WARNING; |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 197 | DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd, |
| 198 | "enable", |
| 199 | "Enable the reporter\n") |
| 200 | { |
| 201 | int rc; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 202 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 203 | OSMO_ASSERT(srep); |
| 204 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 205 | rc = osmo_stats_reporter_enable(srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 206 | if (rc < 0) { |
| 207 | vty_out(vty, "%% Unable to enable the reporter: %s%s", |
| 208 | strerror(-rc), VTY_NEWLINE); |
| 209 | return CMD_WARNING; |
| 210 | } |
| 211 | |
| 212 | return CMD_SUCCESS; |
| 213 | } |
| 214 | |
| 215 | DEFUN(cfg_stats_reporter_disable, cfg_stats_reporter_disable_cmd, |
| 216 | "disable", |
| 217 | "Disable the reporter\n") |
| 218 | { |
| 219 | int rc; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 220 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 221 | OSMO_ASSERT(srep); |
| 222 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 223 | rc = osmo_stats_reporter_disable(srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 224 | if (rc < 0) { |
| 225 | vty_out(vty, "%% Unable to disable the reporter: %s%s", |
| 226 | strerror(-rc), VTY_NEWLINE); |
| 227 | return CMD_WARNING; |
| 228 | } |
| 229 | |
| 230 | return CMD_SUCCESS; |
| 231 | } |
| 232 | |
| 233 | DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd, |
| 234 | "stats reporter statsd", |
| 235 | CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") |
| 236 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 237 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 238 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 239 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 240 | if (!srep) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 241 | srep = osmo_stats_reporter_create_statsd(NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 242 | if (!srep) { |
| 243 | vty_out(vty, "%% Unable to create statsd reporter%s", |
| 244 | VTY_NEWLINE); |
| 245 | return CMD_WARNING; |
| 246 | } |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 247 | srep->max_class = OSMO_STATS_CLASS_GLOBAL; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 248 | /* TODO: if needed, add osmo_stats_add_reporter(srep); */ |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | vty->index = srep; |
| 252 | vty->node = CFG_STATS_NODE; |
| 253 | |
| 254 | return CMD_SUCCESS; |
| 255 | } |
| 256 | |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 257 | DEFUN(cfg_stats_interval, cfg_stats_interval_cmd, |
| 258 | "stats interval <1-65535>", |
| 259 | CFG_STATS_STR "Set the reporting interval\n" |
| 260 | "Interval in seconds\n") |
| 261 | { |
| 262 | int rc; |
| 263 | int interval = atoi(argv[0]); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 264 | rc = osmo_stats_set_interval(interval); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 265 | if (rc < 0) { |
| 266 | vty_out(vty, "%% Unable to set interval: %s%s", |
| 267 | strerror(-rc), VTY_NEWLINE); |
| 268 | return CMD_WARNING; |
| 269 | } |
| 270 | |
| 271 | return CMD_SUCCESS; |
| 272 | } |
| 273 | |
| 274 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 275 | DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd, |
| 276 | "no stats reporter statsd", |
| 277 | NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") |
| 278 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 279 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 280 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 281 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 282 | if (!srep) { |
| 283 | vty_out(vty, "%% No statsd logging active%s", |
| 284 | VTY_NEWLINE); |
| 285 | return CMD_WARNING; |
| 286 | } |
| 287 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 288 | osmo_stats_reporter_free(srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 289 | |
| 290 | return CMD_SUCCESS; |
| 291 | } |
| 292 | |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 293 | DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd, |
| 294 | "stats reporter log", |
| 295 | CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") |
| 296 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 297 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 298 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 299 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 300 | if (!srep) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 301 | srep = osmo_stats_reporter_create_log(NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 302 | if (!srep) { |
| 303 | vty_out(vty, "%% Unable to create log reporter%s", |
| 304 | VTY_NEWLINE); |
| 305 | return CMD_WARNING; |
| 306 | } |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 307 | srep->max_class = OSMO_STATS_CLASS_GLOBAL; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 308 | /* TODO: if needed, add osmo_stats_add_reporter(srep); */ |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | vty->index = srep; |
| 312 | vty->node = CFG_STATS_NODE; |
| 313 | |
| 314 | return CMD_SUCCESS; |
| 315 | } |
| 316 | |
| 317 | DEFUN(cfg_no_stats_reporter_log, cfg_no_stats_reporter_log_cmd, |
| 318 | "no stats reporter log", |
| 319 | NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") |
| 320 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 321 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 322 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 323 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 324 | if (!srep) { |
| 325 | vty_out(vty, "%% No log reporting active%s", |
| 326 | VTY_NEWLINE); |
| 327 | return CMD_WARNING; |
| 328 | } |
| 329 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 330 | osmo_stats_reporter_free(srep); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 331 | |
| 332 | return CMD_SUCCESS; |
| 333 | } |
| 334 | |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 335 | DEFUN(show_stats, |
| 336 | show_stats_cmd, |
| 337 | "show stats", |
| 338 | SHOW_STR SHOW_STATS_STR) |
| 339 | { |
| 340 | vty_out_statistics_full(vty, ""); |
| 341 | |
| 342 | return CMD_SUCCESS; |
| 343 | } |
| 344 | |
Jacob Erlbeck | 59b90bc | 2015-11-03 16:21:40 +0100 | [diff] [blame] | 345 | DEFUN(show_stats_level, |
| 346 | show_stats_level_cmd, |
| 347 | "show stats level (global|peer|subscriber)", |
| 348 | SHOW_STR SHOW_STATS_STR |
Holger Hans Peter Freyther | 8348194 | 2015-11-07 21:10:01 +0100 | [diff] [blame] | 349 | "Set the maximum group level\n" |
Jacob Erlbeck | 59b90bc | 2015-11-03 16:21:40 +0100 | [diff] [blame] | 350 | "Show global groups only\n" |
| 351 | "Show global and network peer related groups\n" |
| 352 | "Show global, peer, and subscriber groups\n") |
| 353 | { |
| 354 | int level = get_string_value(stats_class_strs, argv[0]); |
| 355 | vty_out_statistics_partial(vty, "", level); |
| 356 | |
| 357 | return CMD_SUCCESS; |
| 358 | } |
| 359 | |
Alexander Couzens | ad580ba | 2016-05-16 16:01:45 +0200 | [diff] [blame] | 360 | static int asciidoc_handle_counter(struct osmo_counter *counter, void *sctx_) |
| 361 | { |
| 362 | struct vty *vty = sctx_; |
| 363 | char *name = osmo_asciidoc_escape(counter->name); |
| 364 | char *description = osmo_asciidoc_escape(counter->description); |
| 365 | |
| 366 | /* | name | This document & | description | */ |
| 367 | vty_out(vty, "| %s | <<ungroup_counter_%s>> | %s%s", |
| 368 | name, |
| 369 | name, |
| 370 | description ? description : "", |
| 371 | VTY_NEWLINE); |
| 372 | |
| 373 | talloc_free(name); |
| 374 | talloc_free(description); |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static void asciidoc_counter_generate(struct vty *vty) |
| 380 | { |
| 381 | vty_out(vty, "// ungrouped osmo_counters%s", VTY_NEWLINE); |
| 382 | vty_out(vty, ".ungrouped osmo counters%s", VTY_NEWLINE); |
| 383 | vty_out(vty, "|===%s", VTY_NEWLINE); |
| 384 | vty_out(vty, "| name | This document & | description%s", VTY_NEWLINE); |
| 385 | osmo_counters_for_each(asciidoc_handle_counter, vty); |
| 386 | vty_out(vty, "|===%s", VTY_NEWLINE); |
| 387 | } |
| 388 | |
| 389 | static int asciidoc_rate_ctr_handler( |
| 390 | struct rate_ctr_group *ctrg, struct rate_ctr *ctr, |
| 391 | const struct rate_ctr_desc *desc, void *sctx_) |
| 392 | { |
| 393 | struct vty *vty = sctx_; |
| 394 | char *name = osmo_asciidoc_escape(desc->name); |
| 395 | char *description = osmo_asciidoc_escape(desc->description); |
| 396 | char *group_name_prefix = osmo_asciidoc_escape(ctrg->desc->group_name_prefix); |
| 397 | |
| 398 | /* | name | This document & | description | */ |
| 399 | vty_out(vty, "| %s | <<%s_%s>> | %s%s", |
| 400 | name, |
| 401 | group_name_prefix, |
| 402 | name, |
| 403 | description ? description : NULL, |
| 404 | VTY_NEWLINE); |
| 405 | |
| 406 | /* description seems to be optional */ |
| 407 | talloc_free(name); |
| 408 | talloc_free(group_name_prefix); |
| 409 | talloc_free(description); |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static int asciidoc_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_) |
| 415 | { |
| 416 | struct vty *vty = sctx_; |
| 417 | |
| 418 | char *group_description = osmo_asciidoc_escape(ctrg->desc->group_description); |
| 419 | char *group_name_prefix = osmo_asciidoc_escape(ctrg->desc->group_name_prefix); |
| 420 | |
| 421 | vty_out(vty, "// rate_ctr_group table %s%s", group_description, VTY_NEWLINE); |
| 422 | vty_out(vty, ".%s - %s %s", group_name_prefix, group_description, VTY_NEWLINE); |
| 423 | vty_out(vty, "|===%s", VTY_NEWLINE); |
| 424 | vty_out(vty, "| name | This document & | description%s", VTY_NEWLINE); |
| 425 | rate_ctr_for_each_counter(ctrg, asciidoc_rate_ctr_handler, sctx_); |
| 426 | vty_out(vty, "|===%s", VTY_NEWLINE); |
| 427 | |
| 428 | talloc_free(group_name_prefix); |
| 429 | talloc_free(group_description); |
| 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | static int asciidoc_osmo_stat_item_handler( |
| 435 | struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_) |
| 436 | { |
| 437 | struct vty *vty = sctx_; |
| 438 | |
| 439 | char *name = osmo_asciidoc_escape(item->desc->name); |
| 440 | char *description = osmo_asciidoc_escape(item->desc->description); |
| 441 | char *group_name_prefix = osmo_asciidoc_escape(statg->desc->group_name_prefix); |
| 442 | char *unit = osmo_asciidoc_escape(item->desc->unit); |
| 443 | |
| 444 | /* | name | This document & | description | unit | */ |
| 445 | vty_out(vty, "| %s | <<%s_%s>> | %s | %s%s", |
| 446 | name, |
| 447 | group_name_prefix, |
| 448 | name, |
| 449 | description ? description : "", |
| 450 | unit ? unit : "", |
| 451 | VTY_NEWLINE); |
| 452 | |
| 453 | talloc_free(name); |
| 454 | talloc_free(group_name_prefix); |
| 455 | talloc_free(description); |
| 456 | talloc_free(unit); |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int asciidoc_osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_) |
| 462 | { |
| 463 | char *group_name_prefix = osmo_asciidoc_escape(statg->desc->group_name_prefix); |
| 464 | char *group_description = osmo_asciidoc_escape(statg->desc->group_description); |
| 465 | |
| 466 | struct vty *vty = sctx_; |
| 467 | vty_out(vty, "%s%s", group_description ? group_description : "" , VTY_NEWLINE); |
| 468 | |
| 469 | vty_out(vty, "// osmo_stat_item_group table %s%s", group_description ? group_description : "", VTY_NEWLINE); |
| 470 | vty_out(vty, ".%s - %s %s", group_name_prefix, group_description ? group_description : "", VTY_NEWLINE); |
| 471 | vty_out(vty, "|===%s", VTY_NEWLINE); |
| 472 | vty_out(vty, "| name | This document & | description | unit%s", VTY_NEWLINE); |
| 473 | osmo_stat_item_for_each_item(statg, asciidoc_osmo_stat_item_handler, sctx_); |
| 474 | vty_out(vty, "|===%s", VTY_NEWLINE); |
| 475 | |
| 476 | talloc_free(group_name_prefix); |
| 477 | talloc_free(group_description); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | DEFUN(show_stats_asciidoc_table, |
| 483 | show_stats_asciidoc_table_cmd, |
| 484 | "show asciidoc counters", |
Harald Welte | f624c33 | 2016-06-15 11:35:16 +0200 | [diff] [blame] | 485 | SHOW_STR "Asciidoc generation\n" "Generate table of all registered counters\n") |
Alexander Couzens | ad580ba | 2016-05-16 16:01:45 +0200 | [diff] [blame] | 486 | { |
| 487 | vty_out(vty, "// generating tables for rate_ctr_group%s", VTY_NEWLINE); |
| 488 | rate_ctr_for_each_group(asciidoc_rate_ctr_group_handler, vty); |
| 489 | |
| 490 | vty_out(vty, "// generating tables for osmo_stat_items%s", VTY_NEWLINE); |
| 491 | osmo_stat_item_for_each_group(asciidoc_osmo_stat_item_group_handler, vty); |
| 492 | |
| 493 | vty_out(vty, "// generating tables for osmo_counters%s", VTY_NEWLINE); |
| 494 | asciidoc_counter_generate(vty); |
| 495 | return CMD_SUCCESS; |
| 496 | } |
| 497 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 498 | static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep) |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 499 | { |
| 500 | if (srep == NULL) |
| 501 | return 0; |
| 502 | |
| 503 | switch (srep->type) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 504 | case OSMO_STATS_REPORTER_STATSD: |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 505 | vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE); |
| 506 | break; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 507 | case OSMO_STATS_REPORTER_LOG: |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 508 | vty_out(vty, "stats reporter log%s", VTY_NEWLINE); |
| 509 | break; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | vty_out(vty, " disable%s", VTY_NEWLINE); |
| 513 | |
Jacob Erlbeck | ed197fd | 2015-10-27 14:43:24 +0100 | [diff] [blame] | 514 | if (srep->have_net_config) { |
| 515 | if (srep->dest_addr_str) |
| 516 | vty_out(vty, " remote-ip %s%s", |
| 517 | srep->dest_addr_str, VTY_NEWLINE); |
| 518 | if (srep->dest_port) |
| 519 | vty_out(vty, " remote-port %d%s", |
| 520 | srep->dest_port, VTY_NEWLINE); |
| 521 | if (srep->bind_addr_str) |
| 522 | vty_out(vty, " local-ip %s%s", |
| 523 | srep->bind_addr_str, VTY_NEWLINE); |
| 524 | if (srep->mtu) |
| 525 | vty_out(vty, " mtu %d%s", |
| 526 | srep->mtu, VTY_NEWLINE); |
| 527 | } |
| 528 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 529 | if (srep->max_class) |
| 530 | vty_out(vty, " level %s%s", |
| 531 | get_value_string(stats_class_strs, srep->max_class), |
| 532 | VTY_NEWLINE); |
| 533 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 534 | if (srep->name_prefix && *srep->name_prefix) |
| 535 | vty_out(vty, " prefix %s%s", |
| 536 | srep->name_prefix, VTY_NEWLINE); |
| 537 | else |
| 538 | vty_out(vty, " no prefix%s", VTY_NEWLINE); |
| 539 | |
| 540 | if (srep->enabled) |
| 541 | vty_out(vty, " enable%s", VTY_NEWLINE); |
| 542 | |
| 543 | return 1; |
| 544 | } |
| 545 | |
| 546 | static int config_write_stats(struct vty *vty) |
| 547 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 548 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 549 | |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 550 | /* TODO: loop through all reporters */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 551 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 552 | config_write_stats_reporter(vty, srep); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 553 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 554 | config_write_stats_reporter(vty, srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 555 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 556 | vty_out(vty, "stats interval %d%s", osmo_stats_config->interval, VTY_NEWLINE); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 557 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 558 | return 1; |
| 559 | } |
| 560 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 561 | void osmo_stats_vty_add_cmds() |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 562 | { |
| 563 | install_element_ve(&show_stats_cmd); |
Jacob Erlbeck | 59b90bc | 2015-11-03 16:21:40 +0100 | [diff] [blame] | 564 | install_element_ve(&show_stats_level_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 565 | |
| 566 | install_element(CONFIG_NODE, &cfg_stats_reporter_statsd_cmd); |
| 567 | install_element(CONFIG_NODE, &cfg_no_stats_reporter_statsd_cmd); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 568 | install_element(CONFIG_NODE, &cfg_stats_reporter_log_cmd); |
| 569 | install_element(CONFIG_NODE, &cfg_no_stats_reporter_log_cmd); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 570 | install_element(CONFIG_NODE, &cfg_stats_interval_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 571 | |
| 572 | install_node(&cfg_stats_node, config_write_stats); |
| 573 | vty_install_default(CFG_STATS_NODE); |
| 574 | |
| 575 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_local_ip_cmd); |
| 576 | install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_local_ip_cmd); |
| 577 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_ip_cmd); |
| 578 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_port_cmd); |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 579 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_mtu_cmd); |
| 580 | install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_mtu_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 581 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd); |
| 582 | install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd); |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 583 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_level_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 584 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd); |
| 585 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_disable_cmd); |
Alexander Couzens | ad580ba | 2016-05-16 16:01:45 +0200 | [diff] [blame] | 586 | |
| 587 | install_element_ve(&show_stats_asciidoc_table_cmd); |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 588 | } |