blob: be5a6aa70bae101a0581ab427af1f25e244d68ae [file] [log] [blame]
Jacob Erlbeck45513e62015-10-19 15:14:13 +02001/* 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 Erlbeckadc900e2015-10-20 19:05:52 +020032#include <osmocom/vty/telnet_interface.h>
Jacob Erlbeck45513e62015-10-19 15:14:13 +020033#include <osmocom/vty/misc.h>
34
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020035#include <osmocom/core/stats.h>
Alexander Couzensad580ba2016-05-16 16:01:45 +020036#include <osmocom/core/statistics.h>
37#include <osmocom/core/rate_ctr.h>
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020038
Jacob Erlbeck45513e62015-10-19 15:14:13 +020039#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 Erlbeckadc900e2015-10-20 19:05:52 +020044struct cmd_node cfg_stats_node = {
45 CFG_STATS_NODE,
46 "%s(config-stats)# ",
47 1
48};
49
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +010050static 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 Erlbeckfc9533d2015-10-29 00:55:58 +010057static struct osmo_stats_reporter *osmo_stats_vty2srep(struct vty *vty)
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020058{
59 if (vty->node == CFG_STATS_NODE)
60 return vty->index;
61
62 return NULL;
63}
64
65static int set_srep_parameter_str(struct vty *vty,
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010066 int (*fun)(struct osmo_stats_reporter *, const char *),
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020067 const char *val, const char *param_name)
68{
69 int rc;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010070 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020071 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
83static int set_srep_parameter_int(struct vty *vty,
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010084 int (*fun)(struct osmo_stats_reporter *, int),
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020085 const char *val, const char *param_name)
86{
87 int rc;
88 int int_val;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010089 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020090 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
104DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100109 return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200110 argv[0], "local address");
111}
112
113DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100118 return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200119 NULL, "local address");
120}
121
122DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100127 return set_srep_parameter_str(vty, osmo_stats_reporter_set_remote_addr,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200128 argv[0], "remote address");
129}
130
131DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100136 return set_srep_parameter_int(vty, osmo_stats_reporter_set_remote_port,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200137 argv[0], "remote port");
138}
139
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +0100140DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100145 return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu,
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +0100146 argv[0], "mtu");
147}
148
149DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100153 return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu,
Holger Hans Peter Freyther8f0374f2015-11-02 15:53:09 +0100154 "0", "mtu");
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +0100155}
156
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200157DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100162 return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200163 argv[0], "prefix string");
164}
165
166DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100171 return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200172 "", "prefix string");
173}
174
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100175DEFUN(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 Erlbeckadc900e2015-10-20 19:05:52 +0200197DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd,
198 "enable",
199 "Enable the reporter\n")
200{
201 int rc;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100202 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200203 OSMO_ASSERT(srep);
204
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100205 rc = osmo_stats_reporter_enable(srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200206 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
215DEFUN(cfg_stats_reporter_disable, cfg_stats_reporter_disable_cmd,
216 "disable",
217 "Disable the reporter\n")
218{
219 int rc;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100220 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200221 OSMO_ASSERT(srep);
222
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100223 rc = osmo_stats_reporter_disable(srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200224 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
233DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100237 struct osmo_stats_reporter *srep;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200238
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100239 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200240 if (!srep) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100241 srep = osmo_stats_reporter_create_statsd(NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200242 if (!srep) {
243 vty_out(vty, "%% Unable to create statsd reporter%s",
244 VTY_NEWLINE);
245 return CMD_WARNING;
246 }
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100247 srep->max_class = OSMO_STATS_CLASS_GLOBAL;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100248 /* TODO: if needed, add osmo_stats_add_reporter(srep); */
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200249 }
250
251 vty->index = srep;
252 vty->node = CFG_STATS_NODE;
253
254 return CMD_SUCCESS;
255}
256
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100257DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100264 rc = osmo_stats_set_interval(interval);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100265 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 Erlbeckadc900e2015-10-20 19:05:52 +0200275DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100279 struct osmo_stats_reporter *srep;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200280
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100281 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200282 if (!srep) {
283 vty_out(vty, "%% No statsd logging active%s",
284 VTY_NEWLINE);
285 return CMD_WARNING;
286 }
287
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100288 osmo_stats_reporter_free(srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200289
290 return CMD_SUCCESS;
291}
292
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100293DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100297 struct osmo_stats_reporter *srep;
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100298
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100299 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100300 if (!srep) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100301 srep = osmo_stats_reporter_create_log(NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100302 if (!srep) {
303 vty_out(vty, "%% Unable to create log reporter%s",
304 VTY_NEWLINE);
305 return CMD_WARNING;
306 }
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100307 srep->max_class = OSMO_STATS_CLASS_GLOBAL;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100308 /* TODO: if needed, add osmo_stats_add_reporter(srep); */
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100309 }
310
311 vty->index = srep;
312 vty->node = CFG_STATS_NODE;
313
314 return CMD_SUCCESS;
315}
316
317DEFUN(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 Erlbeckfc9533d2015-10-29 00:55:58 +0100321 struct osmo_stats_reporter *srep;
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100322
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100323 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100324 if (!srep) {
325 vty_out(vty, "%% No log reporting active%s",
326 VTY_NEWLINE);
327 return CMD_WARNING;
328 }
329
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100330 osmo_stats_reporter_free(srep);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100331
332 return CMD_SUCCESS;
333}
334
Jacob Erlbeck45513e62015-10-19 15:14:13 +0200335DEFUN(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 Erlbeck59b90bc2015-11-03 16:21:40 +0100345DEFUN(show_stats_level,
346 show_stats_level_cmd,
347 "show stats level (global|peer|subscriber)",
348 SHOW_STR SHOW_STATS_STR
Holger Hans Peter Freyther83481942015-11-07 21:10:01 +0100349 "Set the maximum group level\n"
Jacob Erlbeck59b90bc2015-11-03 16:21:40 +0100350 "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 Couzensad580ba2016-05-16 16:01:45 +0200360static 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
379static 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
389static 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
414static 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
434static 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
461static 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
482DEFUN(show_stats_asciidoc_table,
483 show_stats_asciidoc_table_cmd,
484 "show asciidoc counters",
485 "Generate an ascii doc table of all registered counters.\n")
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 Erlbeckfc9533d2015-10-29 00:55:58 +0100498static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep)
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200499{
500 if (srep == NULL)
501 return 0;
502
503 switch (srep->type) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100504 case OSMO_STATS_REPORTER_STATSD:
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200505 vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE);
506 break;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100507 case OSMO_STATS_REPORTER_LOG:
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100508 vty_out(vty, "stats reporter log%s", VTY_NEWLINE);
509 break;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200510 }
511
512 vty_out(vty, " disable%s", VTY_NEWLINE);
513
Jacob Erlbecked197fd2015-10-27 14:43:24 +0100514 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 Erlbeckbc9d9ac2015-11-02 14:49:35 +0100529 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 Erlbeckadc900e2015-10-20 19:05:52 +0200534 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
546static int config_write_stats(struct vty *vty)
547{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100548 struct osmo_stats_reporter *srep;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200549
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100550 /* TODO: loop through all reporters */
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100551 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200552 config_write_stats_reporter(vty, srep);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100553 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100554 config_write_stats_reporter(vty, srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200555
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100556 vty_out(vty, "stats interval %d%s", osmo_stats_config->interval, VTY_NEWLINE);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100557
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200558 return 1;
559}
560
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100561void osmo_stats_vty_add_cmds()
Jacob Erlbeck45513e62015-10-19 15:14:13 +0200562{
563 install_element_ve(&show_stats_cmd);
Jacob Erlbeck59b90bc2015-11-03 16:21:40 +0100564 install_element_ve(&show_stats_level_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200565
566 install_element(CONFIG_NODE, &cfg_stats_reporter_statsd_cmd);
567 install_element(CONFIG_NODE, &cfg_no_stats_reporter_statsd_cmd);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100568 install_element(CONFIG_NODE, &cfg_stats_reporter_log_cmd);
569 install_element(CONFIG_NODE, &cfg_no_stats_reporter_log_cmd);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100570 install_element(CONFIG_NODE, &cfg_stats_interval_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200571
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 Erlbeckd01acfc2015-10-26 16:22:45 +0100579 install_element(CFG_STATS_NODE, &cfg_stats_reporter_mtu_cmd);
580 install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_mtu_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200581 install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd);
582 install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd);
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100583 install_element(CFG_STATS_NODE, &cfg_stats_reporter_level_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200584 install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd);
585 install_element(CFG_STATS_NODE, &cfg_stats_reporter_disable_cmd);
Alexander Couzensad580ba2016-05-16 16:01:45 +0200586
587 install_element_ve(&show_stats_asciidoc_table_cmd);
Jacob Erlbeck45513e62015-10-19 15:14:13 +0200588}