aboutsummaryrefslogtreecommitdiff
path: root/src/sysmon
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-11-26 10:26:54 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-11-26 10:26:54 +0000
commit8185d4b875012cfa58d71f326da37e047ba52dd9 (patch)
tree2c92dd04ab58c95d810aa6cbca9b54737af4c27b /src/sysmon
parent1a52014b3b0da4f4330ee00aef0f92400e917558 (diff)
downloadgnunet-8185d4b875012cfa58d71f326da37e047ba52dd9.tar.gz
gnunet-8185d4b875012cfa58d71f326da37e047ba52dd9.zip
changes
Diffstat (limited to 'src/sysmon')
-rw-r--r--src/sysmon/gnunet-daemon-sysmon.c183
1 files changed, 173 insertions, 10 deletions
diff --git a/src/sysmon/gnunet-daemon-sysmon.c b/src/sysmon/gnunet-daemon-sysmon.c
index 93ce107d7..cfd075deb 100644
--- a/src/sysmon/gnunet-daemon-sysmon.c
+++ b/src/sysmon/gnunet-daemon-sysmon.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file sysmon/gnunet-daemon-sysmon.c 22 * @file sysmon/gnunet-daemon-sysmon.c
23 * @brief system monitoring aemon 23 * @brief system monitoring daemon
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
@@ -46,8 +46,15 @@ struct SysmonProperty
46 46
47 char * desc; 47 char * desc;
48 int type; 48 int type;
49 int value; 49 int value_type;
50 struct GNUNET_TIME_Relative interval; 50 struct GNUNET_TIME_Relative interval;
51
52 uint64_t num_val;
53 char * str_val;
54
55 GNUNET_SCHEDULER_TaskIdentifier task_id;
56 GNUNET_SCHEDULER_Task task;
57
51}; 58};
52 59
53/** 60/**
@@ -96,6 +103,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 { 103 {
97 GNUNET_CONTAINER_DLL_remove (sp_head, sp_tail, sp); 104 GNUNET_CONTAINER_DLL_remove (sp_head, sp_tail, sp);
98 next = sp->next; 105 next = sp->next;
106 if (GNUNET_SCHEDULER_NO_TASK != sp->task_id)
107 {
108 GNUNET_SCHEDULER_cancel (sp->task_id);
109 sp->task_id = GNUNET_SCHEDULER_NO_TASK;
110 }
99 GNUNET_free_non_null (sp->desc); 111 GNUNET_free_non_null (sp->desc);
100 GNUNET_free (sp); 112 GNUNET_free (sp);
101 } 113 }
@@ -103,7 +115,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
103} 115}
104 116
105static void 117static void
106shutdown_now () 118shutdown_now (void)
107{ 119{
108 if (GNUNET_SCHEDULER_NO_TASK != end_task) 120 if (GNUNET_SCHEDULER_NO_TASK != end_task)
109 GNUNET_SCHEDULER_cancel (end_task); 121 GNUNET_SCHEDULER_cancel (end_task);
@@ -118,8 +130,28 @@ to_lower_str (char * str)
118 str[c] = tolower(str[c]); 130 str[c] = tolower(str[c]);
119} 131}
120 132
121void load_property (void *cls, 133static int
122 const char *section) 134put_property (struct SysmonProperty *sp)
135{
136 if (v_numeric ==sp->value_type)
137 {
138 GNUNET_STATISTICS_set (stats, sp->desc, sp->num_val, GNUNET_NO);
139 }
140 else if (v_string ==sp->value_type)
141 {
142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "NOT IMPLEMENTED\n");
143 }
144 else
145 {
146 GNUNET_break (0);
147 return GNUNET_SYSERR;
148 }
149 return GNUNET_OK;
150}
151
152static void
153load_property (void *cls,
154 const char *section)
123{ 155{
124 struct GNUNET_CONFIGURATION_Handle *properties = cls; 156 struct GNUNET_CONFIGURATION_Handle *properties = cls;
125 struct SysmonProperty *sp; 157 struct SysmonProperty *sp;
@@ -142,8 +174,6 @@ void load_property (void *cls,
142 "VALUE", section); 174 "VALUE", section);
143 return; 175 return;
144 } 176 }
145
146
147 sp = GNUNET_malloc (sizeof (struct SysmonProperty)); 177 sp = GNUNET_malloc (sizeof (struct SysmonProperty));
148 178
149 /* description */ 179 /* description */
@@ -170,9 +200,9 @@ void load_property (void *cls,
170 GNUNET_CONFIGURATION_get_value_string(properties, section, "VALUE", &tmp); 200 GNUNET_CONFIGURATION_get_value_string(properties, section, "VALUE", &tmp);
171 to_lower_str (tmp); 201 to_lower_str (tmp);
172 if (0 == strcasecmp(tmp, "numeric")) 202 if (0 == strcasecmp(tmp, "numeric"))
173 sp->value = v_numeric; 203 sp->value_type = v_numeric;
174 else if (0 == strcasecmp(tmp, "string")) 204 else if (0 == strcasecmp(tmp, "string"))
175 sp->value = v_string; 205 sp->value_type = v_string;
176 else 206 else
177 { 207 {
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid value %s for %s in section `%s'\n", 208 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid value %s for %s in section `%s'\n",
@@ -182,16 +212,131 @@ void load_property (void *cls,
182 return; 212 return;
183 } 213 }
184 GNUNET_free (tmp); 214 GNUNET_free (tmp);
215
185 /* interval */ 216 /* interval */
186 217
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded property `%s': type %u, value %u,\n", 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded property `%s': type %u, value %u,\n",
188 (NULL != sp->desc) ? sp->desc: "<undefined>", 219 (NULL != sp->desc) ? sp->desc: "<undefined>",
189 sp->type, sp->value); 220 sp->type, sp->value_type);
190 221
191 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp); 222 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp);
192 223
193} 224}
194 225
226static void
227update_uptime (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
228{
229 struct SysmonProperty *sp = cls;
230 sp->task_id = GNUNET_SCHEDULER_NO_TASK;
231 sp->num_val ++;
232 put_property (sp);
233 sp->task_id = GNUNET_SCHEDULER_add_delayed (sp->interval, sp->task, sp);
234}
235
236static int
237load_default_properties (void)
238{
239 struct SysmonProperty *sp;
240 /* GNUnet version array */
241 unsigned int ver[3];
242
243 /* GNUnet vcs revision */
244 unsigned int revision;
245
246 /* version */
247#ifdef VERSION
248 if (3 != sscanf (VERSION, "%u.%u.%u", &ver[0], &ver[1], &ver[2]))
249 {
250 ver[0] = 0;
251 ver[1] = 0;
252 ver[2] = 0;
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not parse version string `%s'\n", VERSION);
254 }
255#else
256 ver[0] = 0;
257 ver[1] = 0;
258 ver[2] = 0;
259 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Version string is undefined \n");
260#endif
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Version: %u.%u.%u\n", ver[0], ver[1], ver[2]);
262
263 sp = GNUNET_malloc (sizeof (struct SysmonProperty));
264 sp->desc = GNUNET_strdup ("GNUnet version");
265 sp->type = t_static;
266 sp->value_type = v_numeric;
267 sp->num_val = 100 * ver[0] + 10 * ver[1] + ver[2];
268 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp);
269
270 /* revision */
271#ifdef VCS_VERSION
272 if (1 != sscanf (VCS_VERSION, "svn-%uM", &revision))
273 {
274 revision = 0;
275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not parse revision string `%s'\n", VCS_VERSION);
276 }
277#else
278 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "VCS revision string is undefined \n");
279 revision = 0;
280#endif
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Revision: %u\n", revision);
282
283 sp = GNUNET_malloc (sizeof (struct SysmonProperty));
284 sp->desc = GNUNET_strdup ("GNUnet vcs revision");
285 sp->type = t_static;
286 sp->value_type = v_numeric;
287 sp->num_val = (uint64_t) revision;
288 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp);
289
290
291 /* GNUnet startup time */
292 sp = GNUNET_malloc (sizeof (struct SysmonProperty));
293 sp->desc = GNUNET_strdup ("GNUnet startup time");
294 sp->type = t_static;
295 sp->value_type = v_numeric;
296 sp->num_val = (uint64_t) GNUNET_TIME_absolute_get().abs_value;
297 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp);
298
299
300 /* GNUnet sysmon daemon uptime */
301 sp = GNUNET_malloc (sizeof (struct SysmonProperty));
302 sp->desc = GNUNET_strdup ("GNUnet uptime");
303 sp->type = t_continous;
304 sp->value_type = v_numeric;
305 sp->num_val = (uint64_t) 0;
306 sp->interval = GNUNET_TIME_UNIT_SECONDS;
307 sp->task_id = GNUNET_SCHEDULER_NO_TASK;
308 sp->task = update_uptime;
309 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp);
310
311 return GNUNET_OK;
312}
313
314static int
315run_properties (void)
316{
317 struct SysmonProperty *sp;
318
319 for (sp = sp_head; NULL != sp; sp = sp->next)
320 {
321 if (t_static == sp->type)
322 {
323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running static property `%s' \n", sp->desc);
324 put_property (sp);
325 }
326 else
327 {
328 if (NULL == sp->task)
329 {
330 continue;
331 GNUNET_break (0);
332 }
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running continous property `%s' \n", sp->desc);
334 sp->task_id = GNUNET_SCHEDULER_add_now (&update_uptime, sp);
335 }
336 }
337 return GNUNET_OK;
338}
339
195/** 340/**
196 * Main function that will be run by the scheduler. 341 * Main function that will be run by the scheduler.
197 * 342 *
@@ -252,6 +397,24 @@ run (void *cls, char *const *args, const char *cfgfile,
252 return; 397 return;
253 } 398 }
254 399
400 /* load properties */
401 if (GNUNET_SYSERR == load_default_properties ())
402 {
403 GNUNET_break (0);
404 shutdown_now();
405 ret = 1;
406 return;
407 }
408
409 /* run properties */
410 if (GNUNET_SYSERR == run_properties ())
411 {
412 GNUNET_break (0);
413 shutdown_now();
414 ret = 1;
415 return;
416 }
417
255} 418}
256 419
257 420