Debian Codegraph @

gmond/modules/status/mod_gstatus.c

raw
1 /*******************************************************************************
2 * Copyright (C) 2007 Novell, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * - Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * - Neither the name of Novell, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Author: Brad Nicholes (bnicholes novell.com)
31 ******************************************************************************/
32
33 #include <gm_metric.h>
34 #include <ganglia_priv.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include "config.h"
39 #include "gm_scoreboard.h"
40
41 #include <apr_strings.h>
42
43 /*
44 * Declare ourselves so the configuration routines can find and know us.
45 * We'll fill it in at the end of the module.
46 */
47 mmodule gstatus_module;
48
49 static apr_array_header_t *metric_info = NULL;
50
51 static int gs_scorecard_offset = 0;
52
53 static Ganglia_25metric static_metric_info[] =
54 {
55 {0, "gmond_version", 1200, GANGLIA_VALUE_STRING, "", "zero", "%s", UDP_HEADER_SIZE+32, "gmond version"},
56 {0, "gmond_version_full", 1200, GANGLIA_VALUE_STRING, "", "zero", "%s", UDP_HEADER_SIZE+32, "gmond version and release"},
57 {0, NULL}
58 };
59
60
61 static int gs_metric_init (apr_pool_t *p)
62 {
63 void *sbi = ganglia_scoreboard_iterator();
64 Ganglia_25metric *gmi;
65 char *name;
66 int *i = &gs_scorecard_offset;
67
68 metric_info = apr_array_make(p, 2, sizeof(Ganglia_25metric));
69
70 for(; static_metric_info[*i].name != NULL; (*i)++)
71 {
72 gmi = apr_array_push(metric_info);
73 memcpy(gmi, &static_metric_info[*i], sizeof(Ganglia_25metric));
74 MMETRIC_INIT_METADATA(gmi,p);
75 MMETRIC_ADD_METADATA(gmi,MGROUP,"gstatus");
76 }
77
78 while (sbi) {
79 name = ganglia_scoreboard_next(&sbi);
80 gmi = apr_array_push(metric_info);
81
82 /* gmi->key will be automatically assigned by gmond */
83 gmi->name = apr_pstrdup (p, name);
84 gmi->tmax = 90;
85 gmi->type = GANGLIA_VALUE_UNSIGNED_INT;
86 gmi->units = apr_pstrdup(p, "count");
87 gmi->slope = apr_pstrdup(p, "both");
88 gmi->fmt = apr_pstrdup(p, "%u");
89 gmi->msg_size = UDP_HEADER_SIZE+8;
90 gmi->desc = apr_pstrdup(p, "Gmond status metric");
91
92 MMETRIC_INIT_METADATA(gmi,p);
93 MMETRIC_ADD_METADATA(gmi,MGROUP,"gstatus");
94 }
95
96 /* Add a terminator to the array and replace the empty static metric definition
97 array with the dynamic array that we just created
98 */
99 gmi = apr_array_push(metric_info);
100 memset (gmi, 0, sizeof(*gmi));
101
102 gstatus_module.metrics_info = (Ganglia_25metric *)metric_info->elts;
103 return 0;
104 }
105
106 static void gs_metric_cleanup ( void )
107 {
108 }
109
110 static g_val_t gs_metric_handler ( int metric_index )
111 {
112 g_val_t val;
113 Ganglia_25metric *gmi = &(gstatus_module.metrics_info[metric_index]);
114
115 if(metric_index >= gs_scorecard_offset)
116 val.uint32 = ganglia_scoreboard_get(gmi->name);
117 else
118 {
119 if(strcmp(gmi->name, "gmond_version") == 0)
120 {
121 snprintf(val.str, MAX_G_STRING_SIZE, VERSION);
122 }
123 else if(strcmp(gmi->name, "gmond_version_full") == 0)
124 {
125 snprintf(val.str, MAX_G_STRING_SIZE, GANGLIA_VERSION_FULL);
126 }
127 }
128
129 return val;
130 }
131
132 mmodule gstatus_module =
133 {
134 STD_MMODULE_STUFF,
135 gs_metric_init,
136 gs_metric_cleanup,
137 NULL, /* defined dynamically */
138 gs_metric_handler,
139 };