blob: 2ca436a7f948df1856783265efe7bd06be4bc9bf [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
Alexander Couzense052dc22016-10-04 18:04:37 +020044/* containing version info */
45extern struct host host;
46
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020047struct cmd_node cfg_stats_node = {
48 CFG_STATS_NODE,
49 "%s(config-stats)# ",
50 1
51};
52
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +010053static const struct value_string stats_class_strs[] = {
54 { OSMO_STATS_CLASS_GLOBAL, "global" },
55 { OSMO_STATS_CLASS_PEER, "peer" },
56 { OSMO_STATS_CLASS_SUBSCRIBER, "subscriber" },
57 { 0, NULL }
58};
59
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010060static struct osmo_stats_reporter *osmo_stats_vty2srep(struct vty *vty)
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020061{
62 if (vty->node == CFG_STATS_NODE)
63 return vty->index;
64
65 return NULL;
66}
67
68static int set_srep_parameter_str(struct vty *vty,
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010069 int (*fun)(struct osmo_stats_reporter *, const char *),
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020070 const char *val, const char *param_name)
71{
72 int rc;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010073 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020074 OSMO_ASSERT(srep);
75
76 rc = fun(srep, val);
77 if (rc < 0) {
78 vty_out(vty, "%% Unable to set %s: %s%s",
79 param_name, strerror(-rc), VTY_NEWLINE);
80 return CMD_WARNING;
81 }
82
83 return CMD_SUCCESS;
84}
85
86static int set_srep_parameter_int(struct vty *vty,
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010087 int (*fun)(struct osmo_stats_reporter *, int),
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020088 const char *val, const char *param_name)
89{
90 int rc;
91 int int_val;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +010092 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +020093 OSMO_ASSERT(srep);
94
95 int_val = atoi(val);
96
97 rc = fun(srep, int_val);
98 if (rc < 0) {
99 vty_out(vty, "%% Unable to set %s: %s%s",
100 param_name, strerror(-rc), VTY_NEWLINE);
101 return CMD_WARNING;
102 }
103
104 return CMD_SUCCESS;
105}
106
107DEFUN(cfg_stats_reporter_local_ip, cfg_stats_reporter_local_ip_cmd,
108 "local-ip ADDR",
109 "Set the IP address to which we bind locally\n"
110 "IP Address\n")
111{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100112 return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200113 argv[0], "local address");
114}
115
116DEFUN(cfg_no_stats_reporter_local_ip, cfg_no_stats_reporter_local_ip_cmd,
117 "no local-ip",
118 NO_STR
119 "Set the IP address to which we bind locally\n")
120{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100121 return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200122 NULL, "local address");
123}
124
125DEFUN(cfg_stats_reporter_remote_ip, cfg_stats_reporter_remote_ip_cmd,
126 "remote-ip ADDR",
127 "Set the remote IP address to which we connect\n"
128 "IP Address\n")
129{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100130 return set_srep_parameter_str(vty, osmo_stats_reporter_set_remote_addr,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200131 argv[0], "remote address");
132}
133
134DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd,
135 "remote-port <1-65535>",
136 "Set the remote port to which we connect\n"
137 "Remote port number\n")
138{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100139 return set_srep_parameter_int(vty, osmo_stats_reporter_set_remote_port,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200140 argv[0], "remote port");
141}
142
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +0100143DEFUN(cfg_stats_reporter_mtu, cfg_stats_reporter_mtu_cmd,
144 "mtu <100-65535>",
145 "Set the maximum packet size\n"
146 "Size in byte\n")
147{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100148 return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu,
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +0100149 argv[0], "mtu");
150}
151
152DEFUN(cfg_no_stats_reporter_mtu, cfg_no_stats_reporter_mtu_cmd,
153 "no mtu",
154 NO_STR "Set the maximum packet size\n")
155{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100156 return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu,
Holger Hans Peter Freyther8f0374f2015-11-02 15:53:09 +0100157 "0", "mtu");
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +0100158}
159
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200160DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd,
161 "prefix PREFIX",
162 "Set the item name prefix\n"
163 "The prefix string\n")
164{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100165 return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200166 argv[0], "prefix string");
167}
168
169DEFUN(cfg_no_stats_reporter_prefix, cfg_no_stats_reporter_prefix_cmd,
170 "no prefix",
171 NO_STR
172 "Set the item name prefix\n")
173{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100174 return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix,
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200175 "", "prefix string");
176}
177
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100178DEFUN(cfg_stats_reporter_level, cfg_stats_reporter_level_cmd,
179 "level (global|peer|subscriber)",
180 "Set the maximum group level\n"
181 "Report global groups only\n"
182 "Report global and network peer related groups\n"
183 "Report global, peer, and subscriber groups\n")
184{
185 int level = get_string_value(stats_class_strs, argv[0]);
186 int rc;
187 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
188
189 OSMO_ASSERT(srep);
190 rc = osmo_stats_reporter_set_max_class(srep, level);
191 if (rc < 0) {
192 vty_out(vty, "%% Unable to set level: %s%s",
193 strerror(-rc), VTY_NEWLINE);
194 return CMD_WARNING;
195 }
196
197 return 0;
198}
199
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200200DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd,
201 "enable",
202 "Enable the reporter\n")
203{
204 int rc;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100205 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200206 OSMO_ASSERT(srep);
207
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100208 rc = osmo_stats_reporter_enable(srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200209 if (rc < 0) {
210 vty_out(vty, "%% Unable to enable the reporter: %s%s",
211 strerror(-rc), VTY_NEWLINE);
212 return CMD_WARNING;
213 }
214
215 return CMD_SUCCESS;
216}
217
218DEFUN(cfg_stats_reporter_disable, cfg_stats_reporter_disable_cmd,
219 "disable",
220 "Disable the reporter\n")
221{
222 int rc;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100223 struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200224 OSMO_ASSERT(srep);
225
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100226 rc = osmo_stats_reporter_disable(srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200227 if (rc < 0) {
228 vty_out(vty, "%% Unable to disable the reporter: %s%s",
229 strerror(-rc), VTY_NEWLINE);
230 return CMD_WARNING;
231 }
232
233 return CMD_SUCCESS;
234}
235
236DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd,
237 "stats reporter statsd",
238 CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n")
239{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100240 struct osmo_stats_reporter *srep;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200241
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100242 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200243 if (!srep) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100244 srep = osmo_stats_reporter_create_statsd(NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200245 if (!srep) {
246 vty_out(vty, "%% Unable to create statsd reporter%s",
247 VTY_NEWLINE);
248 return CMD_WARNING;
249 }
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100250 srep->max_class = OSMO_STATS_CLASS_GLOBAL;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100251 /* TODO: if needed, add osmo_stats_add_reporter(srep); */
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200252 }
253
254 vty->index = srep;
255 vty->node = CFG_STATS_NODE;
256
257 return CMD_SUCCESS;
258}
259
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100260DEFUN(cfg_stats_interval, cfg_stats_interval_cmd,
261 "stats interval <1-65535>",
262 CFG_STATS_STR "Set the reporting interval\n"
263 "Interval in seconds\n")
264{
265 int rc;
266 int interval = atoi(argv[0]);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100267 rc = osmo_stats_set_interval(interval);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100268 if (rc < 0) {
269 vty_out(vty, "%% Unable to set interval: %s%s",
270 strerror(-rc), VTY_NEWLINE);
271 return CMD_WARNING;
272 }
273
274 return CMD_SUCCESS;
275}
276
277
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200278DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd,
279 "no stats reporter statsd",
280 NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n")
281{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100282 struct osmo_stats_reporter *srep;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200283
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100284 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200285 if (!srep) {
286 vty_out(vty, "%% No statsd logging active%s",
287 VTY_NEWLINE);
288 return CMD_WARNING;
289 }
290
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100291 osmo_stats_reporter_free(srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200292
293 return CMD_SUCCESS;
294}
295
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100296DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd,
297 "stats reporter log",
298 CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n")
299{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100300 struct osmo_stats_reporter *srep;
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100301
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100302 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100303 if (!srep) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100304 srep = osmo_stats_reporter_create_log(NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100305 if (!srep) {
306 vty_out(vty, "%% Unable to create log reporter%s",
307 VTY_NEWLINE);
308 return CMD_WARNING;
309 }
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100310 srep->max_class = OSMO_STATS_CLASS_GLOBAL;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100311 /* TODO: if needed, add osmo_stats_add_reporter(srep); */
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100312 }
313
314 vty->index = srep;
315 vty->node = CFG_STATS_NODE;
316
317 return CMD_SUCCESS;
318}
319
320DEFUN(cfg_no_stats_reporter_log, cfg_no_stats_reporter_log_cmd,
321 "no stats reporter log",
322 NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n")
323{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100324 struct osmo_stats_reporter *srep;
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100325
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100326 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100327 if (!srep) {
328 vty_out(vty, "%% No log reporting active%s",
329 VTY_NEWLINE);
330 return CMD_WARNING;
331 }
332
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100333 osmo_stats_reporter_free(srep);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100334
335 return CMD_SUCCESS;
336}
337
Jacob Erlbeck45513e62015-10-19 15:14:13 +0200338DEFUN(show_stats,
339 show_stats_cmd,
340 "show stats",
341 SHOW_STR SHOW_STATS_STR)
342{
343 vty_out_statistics_full(vty, "");
344
345 return CMD_SUCCESS;
346}
347
Jacob Erlbeck59b90bc2015-11-03 16:21:40 +0100348DEFUN(show_stats_level,
349 show_stats_level_cmd,
350 "show stats level (global|peer|subscriber)",
351 SHOW_STR SHOW_STATS_STR
Holger Hans Peter Freyther83481942015-11-07 21:10:01 +0100352 "Set the maximum group level\n"
Jacob Erlbeck59b90bc2015-11-03 16:21:40 +0100353 "Show global groups only\n"
354 "Show global and network peer related groups\n"
355 "Show global, peer, and subscriber groups\n")
356{
357 int level = get_string_value(stats_class_strs, argv[0]);
358 vty_out_statistics_partial(vty, "", level);
359
360 return CMD_SUCCESS;
361}
362
Alexander Couzensad580ba2016-05-16 16:01:45 +0200363static int asciidoc_handle_counter(struct osmo_counter *counter, void *sctx_)
364{
365 struct vty *vty = sctx_;
366 char *name = osmo_asciidoc_escape(counter->name);
367 char *description = osmo_asciidoc_escape(counter->description);
368
369 /* | name | This document & | description | */
370 vty_out(vty, "| %s | <<ungroup_counter_%s>> | %s%s",
371 name,
372 name,
373 description ? description : "",
374 VTY_NEWLINE);
375
376 talloc_free(name);
377 talloc_free(description);
378
379 return 0;
380}
381
382static void asciidoc_counter_generate(struct vty *vty)
383{
384 vty_out(vty, "// ungrouped osmo_counters%s", VTY_NEWLINE);
385 vty_out(vty, ".ungrouped osmo counters%s", VTY_NEWLINE);
386 vty_out(vty, "|===%s", VTY_NEWLINE);
387 vty_out(vty, "| name | This document & | description%s", VTY_NEWLINE);
388 osmo_counters_for_each(asciidoc_handle_counter, vty);
389 vty_out(vty, "|===%s", VTY_NEWLINE);
390}
391
392static int asciidoc_rate_ctr_handler(
393 struct rate_ctr_group *ctrg, struct rate_ctr *ctr,
394 const struct rate_ctr_desc *desc, void *sctx_)
395{
396 struct vty *vty = sctx_;
397 char *name = osmo_asciidoc_escape(desc->name);
398 char *description = osmo_asciidoc_escape(desc->description);
399 char *group_name_prefix = osmo_asciidoc_escape(ctrg->desc->group_name_prefix);
400
401 /* | name | This document & | description | */
402 vty_out(vty, "| %s | <<%s_%s>> | %s%s",
403 name,
404 group_name_prefix,
405 name,
406 description ? description : NULL,
407 VTY_NEWLINE);
408
409 /* description seems to be optional */
410 talloc_free(name);
411 talloc_free(group_name_prefix);
412 talloc_free(description);
413
414 return 0;
415}
416
417static int asciidoc_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_)
418{
419 struct vty *vty = sctx_;
420
421 char *group_description = osmo_asciidoc_escape(ctrg->desc->group_description);
422 char *group_name_prefix = osmo_asciidoc_escape(ctrg->desc->group_name_prefix);
423
424 vty_out(vty, "// rate_ctr_group table %s%s", group_description, VTY_NEWLINE);
425 vty_out(vty, ".%s - %s %s", group_name_prefix, group_description, VTY_NEWLINE);
426 vty_out(vty, "|===%s", VTY_NEWLINE);
427 vty_out(vty, "| name | This document & | description%s", VTY_NEWLINE);
428 rate_ctr_for_each_counter(ctrg, asciidoc_rate_ctr_handler, sctx_);
429 vty_out(vty, "|===%s", VTY_NEWLINE);
430
431 talloc_free(group_name_prefix);
432 talloc_free(group_description);
433
434 return 0;
435}
436
437static int asciidoc_osmo_stat_item_handler(
438 struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_)
439{
440 struct vty *vty = sctx_;
441
442 char *name = osmo_asciidoc_escape(item->desc->name);
443 char *description = osmo_asciidoc_escape(item->desc->description);
444 char *group_name_prefix = osmo_asciidoc_escape(statg->desc->group_name_prefix);
445 char *unit = osmo_asciidoc_escape(item->desc->unit);
446
447 /* | name | This document & | description | unit | */
448 vty_out(vty, "| %s | <<%s_%s>> | %s | %s%s",
449 name,
450 group_name_prefix,
451 name,
452 description ? description : "",
453 unit ? unit : "",
454 VTY_NEWLINE);
455
456 talloc_free(name);
457 talloc_free(group_name_prefix);
458 talloc_free(description);
459 talloc_free(unit);
460
461 return 0;
462}
463
464static int asciidoc_osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_)
465{
466 char *group_name_prefix = osmo_asciidoc_escape(statg->desc->group_name_prefix);
467 char *group_description = osmo_asciidoc_escape(statg->desc->group_description);
468
469 struct vty *vty = sctx_;
470 vty_out(vty, "%s%s", group_description ? group_description : "" , VTY_NEWLINE);
471
472 vty_out(vty, "// osmo_stat_item_group table %s%s", group_description ? group_description : "", VTY_NEWLINE);
473 vty_out(vty, ".%s - %s %s", group_name_prefix, group_description ? group_description : "", VTY_NEWLINE);
474 vty_out(vty, "|===%s", VTY_NEWLINE);
475 vty_out(vty, "| name | This document & | description | unit%s", VTY_NEWLINE);
476 osmo_stat_item_for_each_item(statg, asciidoc_osmo_stat_item_handler, sctx_);
477 vty_out(vty, "|===%s", VTY_NEWLINE);
478
479 talloc_free(group_name_prefix);
480 talloc_free(group_description);
481
482 return 0;
483}
484
485DEFUN(show_stats_asciidoc_table,
486 show_stats_asciidoc_table_cmd,
487 "show asciidoc counters",
Harald Weltef624c332016-06-15 11:35:16 +0200488 SHOW_STR "Asciidoc generation\n" "Generate table of all registered counters\n")
Alexander Couzensad580ba2016-05-16 16:01:45 +0200489{
Alexander Couzense052dc22016-10-04 18:04:37 +0200490 vty_out(vty, "// autogenerated by show asciidoc counters%s", VTY_NEWLINE);
491 vty_out(vty, "These counters and their description based on %s %s (%s).%s%s",
492 host.app_info->name,
493 host.app_info->version,
494 host.app_info->name ? host.app_info->name : "", VTY_NEWLINE, VTY_NEWLINE);
495 /* 2x VTY_NEWLINE are intentional otherwise it would interpret the first table header
496 * as usual text*/
Alexander Couzensad580ba2016-05-16 16:01:45 +0200497 vty_out(vty, "// generating tables for rate_ctr_group%s", VTY_NEWLINE);
498 rate_ctr_for_each_group(asciidoc_rate_ctr_group_handler, vty);
499
500 vty_out(vty, "// generating tables for osmo_stat_items%s", VTY_NEWLINE);
501 osmo_stat_item_for_each_group(asciidoc_osmo_stat_item_group_handler, vty);
502
503 vty_out(vty, "// generating tables for osmo_counters%s", VTY_NEWLINE);
504 asciidoc_counter_generate(vty);
505 return CMD_SUCCESS;
506}
507
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100508static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep)
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200509{
510 if (srep == NULL)
511 return 0;
512
513 switch (srep->type) {
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100514 case OSMO_STATS_REPORTER_STATSD:
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200515 vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE);
516 break;
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100517 case OSMO_STATS_REPORTER_LOG:
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100518 vty_out(vty, "stats reporter log%s", VTY_NEWLINE);
519 break;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200520 }
521
522 vty_out(vty, " disable%s", VTY_NEWLINE);
523
Jacob Erlbecked197fd2015-10-27 14:43:24 +0100524 if (srep->have_net_config) {
525 if (srep->dest_addr_str)
526 vty_out(vty, " remote-ip %s%s",
527 srep->dest_addr_str, VTY_NEWLINE);
528 if (srep->dest_port)
529 vty_out(vty, " remote-port %d%s",
530 srep->dest_port, VTY_NEWLINE);
531 if (srep->bind_addr_str)
532 vty_out(vty, " local-ip %s%s",
533 srep->bind_addr_str, VTY_NEWLINE);
534 if (srep->mtu)
535 vty_out(vty, " mtu %d%s",
536 srep->mtu, VTY_NEWLINE);
537 }
538
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100539 if (srep->max_class)
540 vty_out(vty, " level %s%s",
541 get_value_string(stats_class_strs, srep->max_class),
542 VTY_NEWLINE);
543
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200544 if (srep->name_prefix && *srep->name_prefix)
545 vty_out(vty, " prefix %s%s",
546 srep->name_prefix, VTY_NEWLINE);
547 else
548 vty_out(vty, " no prefix%s", VTY_NEWLINE);
549
550 if (srep->enabled)
551 vty_out(vty, " enable%s", VTY_NEWLINE);
552
553 return 1;
554}
555
556static int config_write_stats(struct vty *vty)
557{
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100558 struct osmo_stats_reporter *srep;
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200559
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100560 /* TODO: loop through all reporters */
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100561 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200562 config_write_stats_reporter(vty, srep);
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100563 srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100564 config_write_stats_reporter(vty, srep);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200565
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100566 vty_out(vty, "stats interval %d%s", osmo_stats_config->interval, VTY_NEWLINE);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100567
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200568 return 1;
569}
570
Jacob Erlbeckfc9533d2015-10-29 00:55:58 +0100571void osmo_stats_vty_add_cmds()
Jacob Erlbeck45513e62015-10-19 15:14:13 +0200572{
573 install_element_ve(&show_stats_cmd);
Jacob Erlbeck59b90bc2015-11-03 16:21:40 +0100574 install_element_ve(&show_stats_level_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200575
576 install_element(CONFIG_NODE, &cfg_stats_reporter_statsd_cmd);
577 install_element(CONFIG_NODE, &cfg_no_stats_reporter_statsd_cmd);
Jacob Erlbeckbc4f7ae2015-10-28 21:47:45 +0100578 install_element(CONFIG_NODE, &cfg_stats_reporter_log_cmd);
579 install_element(CONFIG_NODE, &cfg_no_stats_reporter_log_cmd);
Jacob Erlbeckb1dbfb42015-10-26 11:58:38 +0100580 install_element(CONFIG_NODE, &cfg_stats_interval_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200581
582 install_node(&cfg_stats_node, config_write_stats);
583 vty_install_default(CFG_STATS_NODE);
584
585 install_element(CFG_STATS_NODE, &cfg_stats_reporter_local_ip_cmd);
586 install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_local_ip_cmd);
587 install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_ip_cmd);
588 install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_port_cmd);
Jacob Erlbeckd01acfc2015-10-26 16:22:45 +0100589 install_element(CFG_STATS_NODE, &cfg_stats_reporter_mtu_cmd);
590 install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_mtu_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200591 install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd);
592 install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd);
Jacob Erlbeckbc9d9ac2015-11-02 14:49:35 +0100593 install_element(CFG_STATS_NODE, &cfg_stats_reporter_level_cmd);
Jacob Erlbeckadc900e2015-10-20 19:05:52 +0200594 install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd);
595 install_element(CFG_STATS_NODE, &cfg_stats_reporter_disable_cmd);
Alexander Couzensad580ba2016-05-16 16:01:45 +0200596
597 install_element_ve(&show_stats_asciidoc_table_cmd);
Jacob Erlbeck45513e62015-10-19 15:14:13 +0200598}