aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-10-26 15:10:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-10-26 15:10:32 +0000
commitda1d0733027d98db9cf9e12af9af82f049f163bc (patch)
treef7d8842059774df88e9127bb71665083490caaec
parent3022e99b38cec783bb84299d4f9707dc131f9531 (diff)
downloadgnunet-da1d0733027d98db9cf9e12af9af82f049f163bc.tar.gz
gnunet-da1d0733027d98db9cf9e12af9af82f049f163bc.zip
gnunet-statistics can retrieve stats from remote hosts without config
-rw-r--r--src/statistics/gnunet-statistics.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 15dedaec1..13468592a 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -63,6 +63,15 @@ static int watch;
63 */ 63 */
64static int quiet; 64static int quiet;
65 65
66/**
67 * Remote host
68 */
69static char *remote_host;
70
71/**
72 * Remote host's port
73 */
74static unsigned long long remote_port;
66 75
67/** 76/**
68 * Callback function to process statistic values. 77 * Callback function to process statistic values.
@@ -115,9 +124,14 @@ printer (void *cls, const char *subsystem, const char *name, uint64_t value,
115static void 124static void
116cleanup (void *cls, int success) 125cleanup (void *cls, int success)
117{ 126{
127
118 if (success != GNUNET_OK) 128 if (success != GNUNET_OK)
119 { 129 {
120 FPRINTF (stderr, "%s", _("Failed to obtain statistics.\n")); 130 if (NULL == remote_host)
131 FPRINTF (stderr, "%s", _("Failed to obtain statistics.\n"));
132 else
133 FPRINTF (stderr, _("Failed to obtain statistics from host `%s:%llu'\n"),
134 remote_host, remote_port);
121 ret = 1; 135 ret = 1;
122 } 136 }
123 GNUNET_SCHEDULER_shutdown (); 137 GNUNET_SCHEDULER_shutdown ();
@@ -129,9 +143,9 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
129{ 143{
130 struct GNUNET_STATISTICS_Handle *h = cls; 144 struct GNUNET_STATISTICS_Handle *h = cls;
131 145
132 GNUNET_STATISTICS_watch_cancel (h, subsystem, name, &printer, h);
133 if (NULL != h) 146 if (NULL != h)
134 { 147 {
148 GNUNET_STATISTICS_watch_cancel (h, subsystem, name, &printer, h);
135 GNUNET_STATISTICS_destroy (h, GNUNET_NO); 149 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
136 h = NULL; 150 h = NULL;
137 } 151 }
@@ -153,6 +167,29 @@ run (void *cls, char *const *args, const char *cfgfile,
153 struct GNUNET_STATISTICS_Handle *h; 167 struct GNUNET_STATISTICS_Handle *h;
154 unsigned long long val; 168 unsigned long long val;
155 169
170 if (NULL != remote_host)
171 {
172 /* connect to a remote host */
173 if (0 == remote_port)
174 {
175 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "statistics", "PORT", &remote_port))
176 {
177 FPRINTF (stderr, _("A port is required to connect to host `%s'\n"), remote_host);
178 return;
179 }
180 }
181 else if (65535 <= remote_port)
182 {
183 FPRINTF (stderr, _("A port has to be between 1 and 65535 to connect to host `%s'\n"), remote_host);
184 return;
185 }
186
187 /* Manipulate configuration */
188 GNUNET_CONFIGURATION_set_value_string ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "UNIXPATH", "");
189 GNUNET_CONFIGURATION_set_value_string ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "HOSTNAME", remote_host);
190 GNUNET_CONFIGURATION_set_value_number ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "PORT", remote_port);
191 }
192
156 if (args[0] != NULL) 193 if (args[0] != NULL)
157 { 194 {
158 if ((1 != SSCANF (args[0], "%llu", &val)) || (subsystem == NULL) || 195 if ((1 != SSCANF (args[0], "%llu", &val)) || (subsystem == NULL) ||
@@ -174,6 +211,7 @@ run (void *cls, char *const *args, const char *cfgfile,
174 return; 211 return;
175 } 212 }
176 h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg); 213 h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg);
214 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, h);
177 if (NULL == h) 215 if (NULL == h)
178 { 216 {
179 ret = 1; 217 ret = 1;
@@ -202,7 +240,6 @@ run (void *cls, char *const *args, const char *cfgfile,
202 GNUNET_SCHEDULER_add_now (&shutdown_task, h); 240 GNUNET_SCHEDULER_add_now (&shutdown_task, h);
203 return; 241 return;
204 } 242 }
205 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, h);
206 } 243 }
207} 244}
208 245
@@ -232,9 +269,17 @@ main (int argc, char *const *argv)
232 {'w', "watch", NULL, 269 {'w', "watch", NULL,
233 gettext_noop ("watch value continuously"), 0, 270 gettext_noop ("watch value continuously"), 0,
234 &GNUNET_GETOPT_set_one, &watch}, 271 &GNUNET_GETOPT_set_one, &watch},
272 {'r', "remote", NULL,
273 gettext_noop ("connect to remote host"), 1,
274 &GNUNET_GETOPT_set_string, &remote_host},
275 {'o', "port", NULL,
276 gettext_noop ("port for remote host"), 1,
277 &GNUNET_GETOPT_set_uint, &remote_port},
235 GNUNET_GETOPT_OPTION_END 278 GNUNET_GETOPT_OPTION_END
236 }; 279 };
237 280
281 remote_port = 0;
282 remote_host = NULL;
238 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 283 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
239 return 2; 284 return 2;
240 285
@@ -243,6 +288,8 @@ main (int argc, char *const *argv)
243 gettext_noop 288 gettext_noop
244 ("Print statistics about GNUnet operations."), 289 ("Print statistics about GNUnet operations."),
245 options, &run, NULL)) ? ret : 1; 290 options, &run, NULL)) ? ret : 1;
291
292 GNUNET_free_non_null(remote_host);
246} 293}
247 294
248/* end of gnunet-statistics.c */ 295/* end of gnunet-statistics.c */