2 * Copyright (c) 2016 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.
18 #include <sys/types.h>
23 #include <netinet/in.h>
30 #include <vppinfra/clib.h>
31 #include <vppinfra/vec.h>
32 #include <vppinfra/hash.h>
33 #include <vppinfra/bitmap.h>
34 #include <vppinfra/fifo.h>
35 #include <vppinfra/time.h>
36 #include <vppinfra/mheap.h>
37 #include <vppinfra/heap.h>
38 #include <vppinfra/pool.h>
39 #include <vppinfra/format.h>
40 #include <vlibapi/api.h>
41 #include <vlibmemory/api.h>
43 #include <vlib/vlib.h>
44 #include <vlib/unix/unix.h>
45 #include <vnet/api_errno.h>
47 #include <svm/svmdb.h>
50 volatile int signal_received;
53 unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
65 setup_signal_handlers (void)
70 for (i = 1; i < 32; i++)
72 clib_memset (&sa, 0, sizeof (sa));
73 sa.sa_sigaction = (void *) unix_signal_handler;
74 sa.sa_flags = SA_SIGINFO;
78 /* these signals take the default action */
87 /* ignore SIGPIPE, SIGCHLD */
90 sa.sa_sigaction = (void *) SIG_IGN;
93 /* catch and handle all other signals */
98 if (sigaction (i, &sa, 0) < 0)
99 return clib_unix_warning (0, "sigaction %U", format_signal, i);
104 main (int argc, char **argv)
106 unformat_input_t input;
107 char *chroot_path = 0;
110 f64 *vector_ratep, *rx_ratep, *sig_error_ratep;
112 svmdb_map_args_t _ma, *ma = &_ma;
114 struct passwd _pw, *pw;
115 struct group _grp, *grp;
118 unformat_init_command_line (&input, argv);
123 while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
125 if (unformat (&input, "chroot %s", &chroot_path_u8))
127 chroot_path = (char *) chroot_path_u8;
129 else if (unformat (&input, "interval %d", &interval))
131 else if (unformat (&input, "uid %d", &uid))
133 else if (unformat (&input, "gid %d", &gid))
135 else if (unformat (&input, "uid %s", &s))
137 /* lookup the username */
139 rv = getpwnam_r (s, &_pw, buf, sizeof (buf), &pw);
142 fformat (stderr, "cannot fetch username %s", s);
147 fformat (stderr, "username %s does not exist", s);
153 else if (unformat (&input, "gid %s", &s))
155 /* lookup the group name */
157 rv = getgrnam_r (s, &_grp, buf, sizeof (buf), &grp);
160 fformat (stderr, "cannot fetch group %s", s);
165 fformat (stderr, "group %s does not exist", s);
174 "usage: vpp_get_metrics [chroot <path>] [interval <nn>]\n");
179 setup_signal_handlers ();
181 clib_memset (ma, 0, sizeof (*ma));
182 ma->root_path = chroot_path;
189 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC, "vpp_pid");
191 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
194 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
197 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
198 "vpp_sig_error_rate");
201 * Make sure vpp is actually running. Otherwise, there's every
202 * chance that the database region will be wiped out by the
203 * process monitor script
206 if (vpp_pidp == 0 || vector_ratep == 0 || rx_ratep == 0
207 || sig_error_ratep == 0)
209 fformat (stdout, "vpp not running\n");
216 * Once vpp exits, the svm db region will be recreated...
217 * Can't use kill (*vpp_pidp, 0) if running as non-root /
218 * accessing the shared-VM database via group perms.
222 fformat (stdout, "vpp not running\n");
226 "%d: vpp_vector_rate=%.2f, vpp_input_rate=%f, vpp_sig_error_rate=%f\n",
227 *vpp_pidp, *vector_ratep, *rx_ratep, *sig_error_ratep);
241 * fd.io coding-style-patch-verification: ON
244 * eval: (c-set-style "gnu")
249 * fd.io coding-style-patch-verification: ON
252 * eval: (c-set-style "gnu")