2 * Copyright (c) 2022 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <prom/prom.h>
19 unformat_stats_patterns (unformat_input_t *input, va_list *args)
21 u8 ***patterns = va_arg (*args, u8 ***);
24 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
26 if (unformat (input, "%s", &pattern))
27 vec_add1 (*patterns, pattern);
35 prom_patterns_command_fn (vlib_main_t *vm, unformat_input_t *input,
36 vlib_cli_command_t *cmd)
38 unformat_input_t _line_input, *line_input = &_line_input;
39 u8 is_clear = 0, is_show = 0, **pattern = 0;
40 clib_error_t *error = 0;
42 if (!unformat_user (input, unformat_line_input, line_input))
45 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
47 if (unformat (line_input, "show"))
49 else if (unformat (line_input, "clear"))
51 else if (unformat (line_input, "add %U", unformat_stats_patterns,
54 prom_stat_patterns_add (pattern);
59 error = clib_error_return (0, "unknown input `%U'",
60 format_unformat_error, line_input);
64 unformat_free (line_input);
70 prom_stat_patterns_free ();
74 u8 **patterns = prom_stat_patterns_get ();
75 vec_foreach (pattern, patterns)
76 vlib_cli_output (vm, " %v\n", *pattern);
82 VLIB_CLI_COMMAND (prom_patterns_command, static) = {
83 .path = "prom patterns",
84 .short_help = "prom patterns [show] [clear] [add <patterns>...]",
85 .function = prom_patterns_command_fn,
89 prom_command_fn (vlib_main_t *vm, unformat_input_t *input,
90 vlib_cli_command_t *cmd)
92 unformat_input_t _line_input, *line_input = &_line_input;
93 prom_main_t *pm = prom_get_main ();
94 clib_error_t *error = 0;
98 if (!unformat_user (input, unformat_line_input, line_input))
101 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
103 if (unformat (line_input, "enable"))
105 else if (unformat (line_input, "min-scrape-interval %f",
106 &pm->min_scrape_interval))
108 else if (unformat (line_input, "used-only"))
110 else if (unformat (line_input, "stat-patterns %U",
111 unformat_stats_patterns, &patterns))
112 prom_stat_patterns_set (patterns);
115 error = clib_error_return (0, "unknown input `%U'",
116 format_unformat_error, line_input);
121 unformat_free (line_input);
128 if (is_enable && !pm->is_enabled)
134 VLIB_CLI_COMMAND (prom_enable_command, static) = {
136 .short_help = "prom [enable] [min-scrape-interval <n>] [used-only]"
137 "[stat-patterns <patterns>...]",
138 .function = prom_command_fn,
142 * fd.io coding-style-patch-verification: ON
145 * eval: (c-set-style "gnu")