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>
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;
39 debug_msg("[mod_vpp]Received string params: %s", str_params);
41 /* Multiple name/value pair parameters. */
43 debug_msg("[mod_vpp]Received following params list: ");
44 params = (mmparam*) list_params->elts;
45 for(i=0; i< list_params->nelts; i++) {
46 debug_msg("\tParam: %s = %s", params[i].name, params[i].value);
50 svmdb_client = svmdb_map_chroot (chroot_path);
53 /* Initialize the metadata storage for each of the metrics and then
54 * store one or more key/value pairs. The define MGROUPS defines
55 * the key for the grouping attribute. */
56 for (i = 0; vpp_module.metrics_info[i].name != NULL; i++) {
57 MMETRIC_INIT_METADATA(&(vpp_module.metrics_info[i]),p);
58 MMETRIC_ADD_METADATA(&(vpp_module.metrics_info[i]),MGROUP,"VPP");
64 static void vpp_metric_cleanup (void)
66 svmdb_unmap (svmdb_client);
69 static g_val_t vpp_metric_handler (int metric_index)
73 f64 *vector_ratep, *vpp_rx_ratep, *sig_error_ratep;
75 switch (metric_index) {
77 vector_ratep = svmdb_local_get_vec_variable
78 (svmdb_client, "vpp_vector_rate", sizeof (*vector_ratep));
80 val.d = *vector_ratep;
81 vec_free (vector_ratep);
87 vpp_pidp = svmdb_local_get_vec_variable
89 "vpp_pid", sizeof (*vpp_pidp));
90 if (vpp_pidp && *vpp_pidp) {
91 if (kill(*vpp_pidp, 0) == 0 || errno != ESRCH) {
102 vpp_rx_ratep = svmdb_local_get_vec_variable
103 (svmdb_client, "vpp_input_rate", sizeof (*vector_ratep));
105 val.d = *vpp_rx_ratep;
106 vec_free (vpp_rx_ratep);
112 sig_error_ratep = svmdb_local_get_vec_variable
113 (svmdb_client, "vpp_sig_error_rate", sizeof (*vector_ratep));
114 if (sig_error_ratep) {
115 val.d = *sig_error_ratep;
116 vec_free (sig_error_ratep);
128 static Ganglia_25metric vpp_metric_info[] =
130 {0, "Vector_Rate", 100, GANGLIA_VALUE_DOUBLE, "Packets/Frame",
132 UDP_HEADER_SIZE+8, "VPP Vector Rate"},
133 {0, "VPP_State", 100, GANGLIA_VALUE_DOUBLE, "Run=1", "both", "%.0f",
134 UDP_HEADER_SIZE+8, "VPP State"},
135 {0, "Input_Rate", 100, GANGLIA_VALUE_DOUBLE, "5 sec RX rate",
137 UDP_HEADER_SIZE+8, "VPP Aggregate RX Rate"},
138 {0, "Sig_Error_Rate", 100, GANGLIA_VALUE_DOUBLE,
139 "5 sec significant error rate",
141 UDP_HEADER_SIZE+8, "VPP Significant Error Rate"},