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 */
86 /* ignore SIGPIPE, SIGCHLD */
89 sa.sa_sigaction = (void *) SIG_IGN;
92 /* catch and handle all other signals */
97 if (sigaction (i, &sa, 0) < 0)
98 return clib_unix_warning (0, "sigaction %U", format_signal, i);
103 main (int argc, char **argv)
105 unformat_input_t input;
106 char *chroot_path = 0;
109 f64 *vector_ratep, *rx_ratep, *sig_error_ratep;
111 svmdb_map_args_t _ma, *ma = &_ma;
113 struct passwd _pw, *pw;
114 struct group _grp, *grp;
117 unformat_init_command_line (&input, argv);
122 while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
124 if (unformat (&input, "chroot %s", &chroot_path_u8))
126 chroot_path = (char *) chroot_path_u8;
128 else if (unformat (&input, "interval %d", &interval))
130 else if (unformat (&input, "uid %d", &uid))
132 else if (unformat (&input, "gid %d", &gid))
134 else if (unformat (&input, "uid %s", &s))
136 /* lookup the username */
138 rv = getpwnam_r (s, &_pw, buf, sizeof (buf), &pw);
141 fformat (stderr, "cannot fetch username %s", s);
146 fformat (stderr, "username %s does not exist", s);
152 else if (unformat (&input, "gid %s", &s))
154 /* lookup the group name */
156 rv = getgrnam_r (s, &_grp, buf, sizeof (buf), &grp);
159 fformat (stderr, "cannot fetch group %s", s);
164 fformat (stderr, "group %s does not exist", s);
173 "usage: vpp_get_metrics [chroot <path>] [interval <nn>]\n");
178 setup_signal_handlers ();
180 clib_memset (ma, 0, sizeof (*ma));
181 ma->root_path = chroot_path;
188 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC, "vpp_pid");
190 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
193 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
196 svmdb_local_get_variable_reference (c, SVMDB_NAMESPACE_VEC,
197 "vpp_sig_error_rate");
200 * Make sure vpp is actually running. Otherwise, there's every
201 * chance that the database region will be wiped out by the
202 * process monitor script
205 if (vpp_pidp == 0 || vector_ratep == 0 || rx_ratep == 0
206 || sig_error_ratep == 0)
208 fformat (stdout, "vpp not running\n");
215 * Once vpp exits, the svm db region will be recreated...
216 * Can't use kill (*vpp_pidp, 0) if running as non-root /
217 * accessing the shared-VM database via group perms.
221 fformat (stdout, "vpp not running\n");
225 "%d: vpp_vector_rate=%.2f, vpp_input_rate=%f, vpp_sig_error_rate=%f\n",
226 *vpp_pidp, *vector_ratep, *rx_ratep, *sig_error_ratep);
240 * fd.io coding-style-patch-verification: ON
243 * eval: (c-set-style "gnu")
248 * fd.io coding-style-patch-verification: ON
251 * eval: (c-set-style "gnu")