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.
16 #include <gm_metric.h>
21 #include <vppinfra/clib.h>
22 #include <vppinfra/vec.h>
23 #include <vppinfra/hash.h>
24 #include <svm/svmdb.h>
28 static svmdb_client_t *svmdb_client;
30 static int vpp_metric_init (apr_pool_t *p)
32 const char* str_params = vpp_module.module_params;
33 apr_array_header_t *list_params = vpp_module.module_params_list;
35 char *chroot_path = 0;
36 svmdb_map_args_t _ma, *ma= &_ma;
40 clib_warning("[mod_vpp]Received string params: %s", str_params);
42 /* Multiple name/value pair parameters. */
44 clib_warning("[mod_vpp]Received following params list: ");
45 params = (mmparam*) list_params->elts;
46 for(i=0; i< list_params->nelts; i++) {
47 clib_warning("\tParam: %s = %s", params[i].name, params[i].value);
51 memset (ma, 0, sizeof (*ma));
52 ma->root_path = (char *)chroot_path;
54 svmdb_client = svmdb_map (ma);
57 /* Initialize the metadata storage for each of the metrics and then
58 * store one or more key/value pairs. The define MGROUPS defines
59 * the key for the grouping attribute. */
60 for (i = 0; vpp_module.metrics_info[i].name != NULL; i++) {
61 MMETRIC_INIT_METADATA(&(vpp_module.metrics_info[i]),p);
62 MMETRIC_ADD_METADATA(&(vpp_module.metrics_info[i]),MGROUP,"VPP");
68 static void vpp_metric_cleanup (void)
70 svmdb_unmap (svmdb_client);
73 static g_val_t vpp_metric_handler (int metric_index)
77 f64 *vector_ratep, *vpp_rx_ratep, *sig_error_ratep;
79 switch (metric_index) {
81 vector_ratep = svmdb_local_get_vec_variable
82 (svmdb_client, "vpp_vector_rate", sizeof (*vector_ratep));
84 val.d = *vector_ratep;
85 vec_free (vector_ratep);
91 vpp_pidp = svmdb_local_get_vec_variable
93 "vpp_pid", sizeof (*vpp_pidp));
94 if (vpp_pidp && *vpp_pidp) {
95 if (kill(*vpp_pidp, 0) == 0 || errno != ESRCH) {
106 vpp_rx_ratep = svmdb_local_get_vec_variable
107 (svmdb_client, "vpp_input_rate", sizeof (*vector_ratep));
109 val.d = *vpp_rx_ratep;
110 vec_free (vpp_rx_ratep);
116 sig_error_ratep = svmdb_local_get_vec_variable
117 (svmdb_client, "vpp_sig_error_rate", sizeof (*vector_ratep));
118 if (sig_error_ratep) {
119 val.d = *sig_error_ratep;
120 vec_free (sig_error_ratep);
132 static Ganglia_25metric vpp_metric_info[] =
134 {0, "Vector_Rate", 100, GANGLIA_VALUE_DOUBLE, "Packets/Frame",
136 UDP_HEADER_SIZE+8, "VPP Vector Rate"},
137 {0, "VPP_State", 100, GANGLIA_VALUE_DOUBLE, "Run=1", "both", "%.0f",
138 UDP_HEADER_SIZE+8, "VPP State"},
139 {0, "Input_Rate", 100, GANGLIA_VALUE_DOUBLE, "5 sec RX rate",
141 UDP_HEADER_SIZE+8, "VPP Aggregate RX Rate"},
142 {0, "Sig_Error_Rate", 100, GANGLIA_VALUE_DOUBLE,
143 "5 sec significant error rate",
145 UDP_HEADER_SIZE+8, "VPP Significant Error Rate"},