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> |
| 36 | |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 37 | #define CFG_STATS_STR "Configure stats sub-system\n" |
| 38 | #define CFG_REPORTER_STR "Configure a stats reporter\n" |
| 39 | |
| 40 | #define SHOW_STATS_STR "Show statistical values\n" |
| 41 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 42 | struct cmd_node cfg_stats_node = { |
| 43 | CFG_STATS_NODE, |
| 44 | "%s(config-stats)# ", |
| 45 | 1 |
| 46 | }; |
| 47 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 48 | static const struct value_string stats_class_strs[] = { |
| 49 | { OSMO_STATS_CLASS_GLOBAL, "global" }, |
| 50 | { OSMO_STATS_CLASS_PEER, "peer" }, |
| 51 | { OSMO_STATS_CLASS_SUBSCRIBER, "subscriber" }, |
| 52 | { 0, NULL } |
| 53 | }; |
| 54 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 55 | static struct osmo_stats_reporter *osmo_stats_vty2srep(struct vty *vty) |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 56 | { |
| 57 | if (vty->node == CFG_STATS_NODE) |
| 58 | return vty->index; |
| 59 | |
| 60 | return NULL; |
| 61 | } |
| 62 | |
| 63 | static int set_srep_parameter_str(struct vty *vty, |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 64 | int (*fun)(struct osmo_stats_reporter *, const char *), |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 65 | const char *val, const char *param_name) |
| 66 | { |
| 67 | int rc; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 68 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 69 | OSMO_ASSERT(srep); |
| 70 | |
| 71 | rc = fun(srep, val); |
| 72 | if (rc < 0) { |
| 73 | vty_out(vty, "%% Unable to set %s: %s%s", |
| 74 | param_name, strerror(-rc), VTY_NEWLINE); |
| 75 | return CMD_WARNING; |
| 76 | } |
| 77 | |
| 78 | return CMD_SUCCESS; |
| 79 | } |
| 80 | |
| 81 | static int set_srep_parameter_int(struct vty *vty, |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 82 | int (*fun)(struct osmo_stats_reporter *, int), |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 83 | const char *val, const char *param_name) |
| 84 | { |
| 85 | int rc; |
| 86 | int int_val; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 87 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 88 | OSMO_ASSERT(srep); |
| 89 | |
| 90 | int_val = atoi(val); |
| 91 | |
| 92 | rc = fun(srep, int_val); |
| 93 | if (rc < 0) { |
| 94 | vty_out(vty, "%% Unable to set %s: %s%s", |
| 95 | param_name, strerror(-rc), VTY_NEWLINE); |
| 96 | return CMD_WARNING; |
| 97 | } |
| 98 | |
| 99 | return CMD_SUCCESS; |
| 100 | } |
| 101 | |
| 102 | DEFUN(cfg_stats_reporter_local_ip, cfg_stats_reporter_local_ip_cmd, |
| 103 | "local-ip ADDR", |
| 104 | "Set the IP address to which we bind locally\n" |
| 105 | "IP Address\n") |
| 106 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 107 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 108 | argv[0], "local address"); |
| 109 | } |
| 110 | |
| 111 | DEFUN(cfg_no_stats_reporter_local_ip, cfg_no_stats_reporter_local_ip_cmd, |
| 112 | "no local-ip", |
| 113 | NO_STR |
| 114 | "Set the IP address to which we bind locally\n") |
| 115 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 116 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 117 | NULL, "local address"); |
| 118 | } |
| 119 | |
| 120 | DEFUN(cfg_stats_reporter_remote_ip, cfg_stats_reporter_remote_ip_cmd, |
| 121 | "remote-ip ADDR", |
| 122 | "Set the remote IP address to which we connect\n" |
| 123 | "IP Address\n") |
| 124 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 125 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_remote_addr, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 126 | argv[0], "remote address"); |
| 127 | } |
| 128 | |
| 129 | DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd, |
| 130 | "remote-port <1-65535>", |
| 131 | "Set the remote port to which we connect\n" |
| 132 | "Remote port number\n") |
| 133 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 134 | return set_srep_parameter_int(vty, osmo_stats_reporter_set_remote_port, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 135 | argv[0], "remote port"); |
| 136 | } |
| 137 | |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 138 | DEFUN(cfg_stats_reporter_mtu, cfg_stats_reporter_mtu_cmd, |
| 139 | "mtu <100-65535>", |
| 140 | "Set the maximum packet size\n" |
| 141 | "Size in byte\n") |
| 142 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 143 | return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 144 | argv[0], "mtu"); |
| 145 | } |
| 146 | |
| 147 | DEFUN(cfg_no_stats_reporter_mtu, cfg_no_stats_reporter_mtu_cmd, |
| 148 | "no mtu", |
| 149 | NO_STR "Set the maximum packet size\n") |
| 150 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 151 | 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] | 152 | "0", "mtu"); |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 153 | } |
| 154 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 155 | DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, |
| 156 | "prefix PREFIX", |
| 157 | "Set the item name prefix\n" |
| 158 | "The prefix string\n") |
| 159 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 160 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 161 | argv[0], "prefix string"); |
| 162 | } |
| 163 | |
| 164 | DEFUN(cfg_no_stats_reporter_prefix, cfg_no_stats_reporter_prefix_cmd, |
| 165 | "no prefix", |
| 166 | NO_STR |
| 167 | "Set the item name prefix\n") |
| 168 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 169 | return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 170 | "", "prefix string"); |
| 171 | } |
| 172 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 173 | DEFUN(cfg_stats_reporter_level, cfg_stats_reporter_level_cmd, |
| 174 | "level (global|peer|subscriber)", |
| 175 | "Set the maximum group level\n" |
| 176 | "Report global groups only\n" |
| 177 | "Report global and network peer related groups\n" |
| 178 | "Report global, peer, and subscriber groups\n") |
| 179 | { |
| 180 | int level = get_string_value(stats_class_strs, argv[0]); |
| 181 | int rc; |
| 182 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
| 183 | |
| 184 | OSMO_ASSERT(srep); |
| 185 | rc = osmo_stats_reporter_set_max_class(srep, level); |
| 186 | if (rc < 0) { |
| 187 | vty_out(vty, "%% Unable to set level: %s%s", |
| 188 | strerror(-rc), VTY_NEWLINE); |
| 189 | return CMD_WARNING; |
| 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 195 | DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd, |
| 196 | "enable", |
| 197 | "Enable the reporter\n") |
| 198 | { |
| 199 | int rc; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 200 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 201 | OSMO_ASSERT(srep); |
| 202 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 203 | rc = osmo_stats_reporter_enable(srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 204 | if (rc < 0) { |
| 205 | vty_out(vty, "%% Unable to enable the reporter: %s%s", |
| 206 | strerror(-rc), VTY_NEWLINE); |
| 207 | return CMD_WARNING; |
| 208 | } |
| 209 | |
| 210 | return CMD_SUCCESS; |
| 211 | } |
| 212 | |
| 213 | DEFUN(cfg_stats_reporter_disable, cfg_stats_reporter_disable_cmd, |
| 214 | "disable", |
| 215 | "Disable the reporter\n") |
| 216 | { |
| 217 | int rc; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 218 | struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 219 | OSMO_ASSERT(srep); |
| 220 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 221 | rc = osmo_stats_reporter_disable(srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 222 | if (rc < 0) { |
| 223 | vty_out(vty, "%% Unable to disable the reporter: %s%s", |
| 224 | strerror(-rc), VTY_NEWLINE); |
| 225 | return CMD_WARNING; |
| 226 | } |
| 227 | |
| 228 | return CMD_SUCCESS; |
| 229 | } |
| 230 | |
| 231 | DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd, |
| 232 | "stats reporter statsd", |
| 233 | CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") |
| 234 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 235 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 236 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 237 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 238 | if (!srep) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 239 | srep = osmo_stats_reporter_create_statsd(NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 240 | if (!srep) { |
| 241 | vty_out(vty, "%% Unable to create statsd reporter%s", |
| 242 | VTY_NEWLINE); |
| 243 | return CMD_WARNING; |
| 244 | } |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 245 | srep->max_class = OSMO_STATS_CLASS_GLOBAL; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 246 | /* TODO: if needed, add osmo_stats_add_reporter(srep); */ |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | vty->index = srep; |
| 250 | vty->node = CFG_STATS_NODE; |
| 251 | |
| 252 | return CMD_SUCCESS; |
| 253 | } |
| 254 | |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 255 | DEFUN(cfg_stats_interval, cfg_stats_interval_cmd, |
| 256 | "stats interval <1-65535>", |
| 257 | CFG_STATS_STR "Set the reporting interval\n" |
| 258 | "Interval in seconds\n") |
| 259 | { |
| 260 | int rc; |
| 261 | int interval = atoi(argv[0]); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 262 | rc = osmo_stats_set_interval(interval); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 263 | if (rc < 0) { |
| 264 | vty_out(vty, "%% Unable to set interval: %s%s", |
| 265 | strerror(-rc), VTY_NEWLINE); |
| 266 | return CMD_WARNING; |
| 267 | } |
| 268 | |
| 269 | return CMD_SUCCESS; |
| 270 | } |
| 271 | |
| 272 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 273 | DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd, |
| 274 | "no stats reporter statsd", |
| 275 | NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") |
| 276 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 277 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 278 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 279 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 280 | if (!srep) { |
| 281 | vty_out(vty, "%% No statsd logging active%s", |
| 282 | VTY_NEWLINE); |
| 283 | return CMD_WARNING; |
| 284 | } |
| 285 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 286 | osmo_stats_reporter_free(srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 287 | |
| 288 | return CMD_SUCCESS; |
| 289 | } |
| 290 | |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 291 | DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd, |
| 292 | "stats reporter log", |
| 293 | CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") |
| 294 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 295 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 296 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 297 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 298 | if (!srep) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 299 | srep = osmo_stats_reporter_create_log(NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 300 | if (!srep) { |
| 301 | vty_out(vty, "%% Unable to create log reporter%s", |
| 302 | VTY_NEWLINE); |
| 303 | return CMD_WARNING; |
| 304 | } |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 305 | srep->max_class = OSMO_STATS_CLASS_GLOBAL; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 306 | /* TODO: if needed, add osmo_stats_add_reporter(srep); */ |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | vty->index = srep; |
| 310 | vty->node = CFG_STATS_NODE; |
| 311 | |
| 312 | return CMD_SUCCESS; |
| 313 | } |
| 314 | |
| 315 | DEFUN(cfg_no_stats_reporter_log, cfg_no_stats_reporter_log_cmd, |
| 316 | "no stats reporter log", |
| 317 | NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") |
| 318 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 319 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 320 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 321 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 322 | if (!srep) { |
| 323 | vty_out(vty, "%% No log reporting active%s", |
| 324 | VTY_NEWLINE); |
| 325 | return CMD_WARNING; |
| 326 | } |
| 327 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 328 | osmo_stats_reporter_free(srep); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 329 | |
| 330 | return CMD_SUCCESS; |
| 331 | } |
| 332 | |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 333 | DEFUN(show_stats, |
| 334 | show_stats_cmd, |
| 335 | "show stats", |
| 336 | SHOW_STR SHOW_STATS_STR) |
| 337 | { |
| 338 | vty_out_statistics_full(vty, ""); |
| 339 | |
| 340 | return CMD_SUCCESS; |
| 341 | } |
| 342 | |
Jacob Erlbeck | 59b90bc | 2015-11-03 16:21:40 +0100 | [diff] [blame] | 343 | DEFUN(show_stats_level, |
| 344 | show_stats_level_cmd, |
| 345 | "show stats level (global|peer|subscriber)", |
| 346 | SHOW_STR SHOW_STATS_STR |
Holger Hans Peter Freyther | 8348194 | 2015-11-07 21:10:01 +0100 | [diff] [blame] | 347 | "Set the maximum group level\n" |
Jacob Erlbeck | 59b90bc | 2015-11-03 16:21:40 +0100 | [diff] [blame] | 348 | "Show global groups only\n" |
| 349 | "Show global and network peer related groups\n" |
| 350 | "Show global, peer, and subscriber groups\n") |
| 351 | { |
| 352 | int level = get_string_value(stats_class_strs, argv[0]); |
| 353 | vty_out_statistics_partial(vty, "", level); |
| 354 | |
| 355 | return CMD_SUCCESS; |
| 356 | } |
| 357 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 358 | 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] | 359 | { |
| 360 | if (srep == NULL) |
| 361 | return 0; |
| 362 | |
| 363 | switch (srep->type) { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 364 | case OSMO_STATS_REPORTER_STATSD: |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 365 | vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE); |
| 366 | break; |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 367 | case OSMO_STATS_REPORTER_LOG: |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 368 | vty_out(vty, "stats reporter log%s", VTY_NEWLINE); |
| 369 | break; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | vty_out(vty, " disable%s", VTY_NEWLINE); |
| 373 | |
Jacob Erlbeck | ed197fd | 2015-10-27 14:43:24 +0100 | [diff] [blame] | 374 | if (srep->have_net_config) { |
| 375 | if (srep->dest_addr_str) |
| 376 | vty_out(vty, " remote-ip %s%s", |
| 377 | srep->dest_addr_str, VTY_NEWLINE); |
| 378 | if (srep->dest_port) |
| 379 | vty_out(vty, " remote-port %d%s", |
| 380 | srep->dest_port, VTY_NEWLINE); |
| 381 | if (srep->bind_addr_str) |
| 382 | vty_out(vty, " local-ip %s%s", |
| 383 | srep->bind_addr_str, VTY_NEWLINE); |
| 384 | if (srep->mtu) |
| 385 | vty_out(vty, " mtu %d%s", |
| 386 | srep->mtu, VTY_NEWLINE); |
| 387 | } |
| 388 | |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 389 | if (srep->max_class) |
| 390 | vty_out(vty, " level %s%s", |
| 391 | get_value_string(stats_class_strs, srep->max_class), |
| 392 | VTY_NEWLINE); |
| 393 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 394 | if (srep->name_prefix && *srep->name_prefix) |
| 395 | vty_out(vty, " prefix %s%s", |
| 396 | srep->name_prefix, VTY_NEWLINE); |
| 397 | else |
| 398 | vty_out(vty, " no prefix%s", VTY_NEWLINE); |
| 399 | |
| 400 | if (srep->enabled) |
| 401 | vty_out(vty, " enable%s", VTY_NEWLINE); |
| 402 | |
| 403 | return 1; |
| 404 | } |
| 405 | |
| 406 | static int config_write_stats(struct vty *vty) |
| 407 | { |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 408 | struct osmo_stats_reporter *srep; |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 409 | |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 410 | /* TODO: loop through all reporters */ |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 411 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 412 | config_write_stats_reporter(vty, srep); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 413 | srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 414 | config_write_stats_reporter(vty, srep); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 415 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 416 | 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] | 417 | |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 418 | return 1; |
| 419 | } |
| 420 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 421 | void osmo_stats_vty_add_cmds() |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 422 | { |
| 423 | install_element_ve(&show_stats_cmd); |
Jacob Erlbeck | 59b90bc | 2015-11-03 16:21:40 +0100 | [diff] [blame] | 424 | install_element_ve(&show_stats_level_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 425 | |
| 426 | install_element(CONFIG_NODE, &cfg_stats_reporter_statsd_cmd); |
| 427 | install_element(CONFIG_NODE, &cfg_no_stats_reporter_statsd_cmd); |
Jacob Erlbeck | bc4f7ae | 2015-10-28 21:47:45 +0100 | [diff] [blame] | 428 | install_element(CONFIG_NODE, &cfg_stats_reporter_log_cmd); |
| 429 | install_element(CONFIG_NODE, &cfg_no_stats_reporter_log_cmd); |
Jacob Erlbeck | b1dbfb4 | 2015-10-26 11:58:38 +0100 | [diff] [blame] | 430 | install_element(CONFIG_NODE, &cfg_stats_interval_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 431 | |
| 432 | install_node(&cfg_stats_node, config_write_stats); |
| 433 | vty_install_default(CFG_STATS_NODE); |
| 434 | |
| 435 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_local_ip_cmd); |
| 436 | install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_local_ip_cmd); |
| 437 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_ip_cmd); |
| 438 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_port_cmd); |
Jacob Erlbeck | d01acfc | 2015-10-26 16:22:45 +0100 | [diff] [blame] | 439 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_mtu_cmd); |
| 440 | install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_mtu_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 441 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd); |
| 442 | install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd); |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 443 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_level_cmd); |
Jacob Erlbeck | adc900e | 2015-10-20 19:05:52 +0200 | [diff] [blame] | 444 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd); |
| 445 | install_element(CFG_STATS_NODE, &cfg_stats_reporter_disable_cmd); |
Jacob Erlbeck | 45513e6 | 2015-10-19 15:14:13 +0200 | [diff] [blame] | 446 | } |