2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file sysmon/gnunet-daemon-sysmon.c
23 * @brief system monitoring aemon
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_statistics_service.h"
44 struct SysmonProperty *next;
45 struct SysmonProperty *prev;
50 struct GNUNET_TIME_Relative interval;
59 * Configuration handle
61 const struct GNUNET_CONFIGURATION_Handle *cfg;
67 struct GNUNET_STATISTICS_Handle *stats;
73 GNUNET_SCHEDULER_TaskIdentifier end_task;
75 struct SysmonProperty *sp_head;
76 struct SysmonProperty *sp_tail;
79 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81 struct SysmonProperty *sp;
82 struct SysmonProperty *next;
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sysdaemon stopping ... \n");
86 end_task = GNUNET_SCHEDULER_NO_TASK;
90 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
95 while (NULL != (sp = next))
97 GNUNET_CONTAINER_DLL_remove (sp_head, sp_tail, sp);
99 GNUNET_free_non_null (sp->desc);
108 if (GNUNET_SCHEDULER_NO_TASK != end_task)
109 GNUNET_SCHEDULER_cancel (end_task);
110 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
114 to_lower_str (char * str)
117 for (c = 0; c <= strlen (str); c++)
118 str[c] = tolower(str[c]);
121 void load_property (void *cls,
124 struct GNUNET_CONFIGURATION_Handle *properties = cls;
125 struct SysmonProperty *sp;
128 if (NULL == strstr (section, "sysmon-"))
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading section `%s'\n", section);
133 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(properties, section, "TYPE"))
135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n",
139 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(properties, section,"VALUE"))
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n",
147 sp = GNUNET_malloc (sizeof (struct SysmonProperty));
150 GNUNET_CONFIGURATION_get_value_string(properties, section, "DESCRIPTION", &sp->desc);
153 GNUNET_CONFIGURATION_get_value_string(properties, section, "TYPE", &tmp);
155 if (0 == strcasecmp(tmp, "static"))
157 else if (0 == strcasecmp(tmp, "continous"))
158 sp->type = t_continous;
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid value %s for %s in section `%s'\n",
162 tmp, "TYPE", section);
170 GNUNET_CONFIGURATION_get_value_string(properties, section, "VALUE", &tmp);
172 if (0 == strcasecmp(tmp, "numeric"))
173 sp->value = v_numeric;
174 else if (0 == strcasecmp(tmp, "string"))
175 sp->value = v_string;
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid value %s for %s in section `%s'\n",
179 tmp, "VALUE", section);
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded property `%s': type %u, value %u,\n",
188 (NULL != sp->desc) ? sp->desc: "<undefined>",
189 sp->type, sp->value);
191 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp);
196 * Main function that will be run by the scheduler.
199 * @param args remaining command-line arguments
200 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
201 * @param cfg configuration
204 run (void *cls, char *const *args, const char *cfgfile,
205 const struct GNUNET_CONFIGURATION_Handle *mycfg)
207 struct GNUNET_CONFIGURATION_Handle *properties;
210 end_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sysdaemon starting ... \n");
215 if (GNUNET_SYSERR ==GNUNET_CONFIGURATION_get_value_filename (mycfg, "sysmon", "CFGFILE", &file))
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sysmon configuration file not set, exit! \n");
223 properties = GNUNET_CONFIGURATION_create();
224 if (NULL == properties)
231 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (properties, file))
234 GNUNET_CONFIGURATION_destroy (properties);
241 GNUNET_CONFIGURATION_iterate_sections (properties, &load_property, properties);
243 GNUNET_CONFIGURATION_destroy (properties);
245 /* Creating statistics */
246 stats = GNUNET_STATISTICS_create ("sysmon", mycfg);
261 * @param argc number of arguments from the command line
262 * @param argv command line arguments
263 * @return 0 ok, 1 on error
266 main (int argc, char *const *argv)
268 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
269 GNUNET_GETOPT_OPTION_END
271 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
275 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-sysmon",
276 gettext_noop ("GNUnet system monitoring and information daemon"), options, &run,
278 GNUNET_free ((void*) argv);
282 /* end of gnunet-daemon-sysmon.c */