error handling
[oweals/gnunet.git] / src / statistics / gnunet-statistics.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2004-2007, 2009, 2016 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
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      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @file statistics/gnunet-statistics.c
23  * @brief tool to obtain statistics
24  * @author Christian Grothoff
25  * @author Igor Wronsky
26  */
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_statistics_service.h"
30 #include "statistics.h"
31
32
33 /**
34  * Final status code.
35  */
36 static int ret;
37
38 /**
39  * Set to subsystem that we're going to get stats for (or NULL for all).
40  */
41 static char *subsystem;
42
43 /**
44  * The path of the testbed data.
45  */
46 static char *path_testbed;
47
48 /**
49  * Set to the specific stat value that we are after (or NULL for all).
50  */
51 static char *name;
52
53 /**
54  * Make the value that is being set persistent.
55  */
56 static int persistent;
57
58 /**
59  * Watch value continuously
60  */
61 static int watch;
62
63 /**
64  * Quiet mode
65  */
66 static int quiet;
67
68 /**
69  * @brief Separator string for csv.
70  */
71 static char *csv_separator;
72
73 /**
74  * Remote host
75  */
76 static char *remote_host;
77
78 /**
79  * Remote host's port
80  */
81 static unsigned long long remote_port;
82
83 /**
84  * Value to set
85  */
86 static unsigned long long set_val;
87
88 /**
89  * Set operation
90  */
91 static int set_value;
92
93 /**
94  * @brief Representation of all (testbed) nodes.
95  */
96 static struct Node
97 {
98   /**
99    * @brief Index of the node in this array.
100    */
101   unsigned index_node;
102
103   /**
104    * @brief Configuration handle for this node
105    */
106   struct GNUNET_CONFIGURATION_Handle *conf;
107
108   /**
109    * Handle for pending GET operation.
110    */
111   struct GNUNET_STATISTICS_GetHandle *gh;
112
113   /**
114    * @brief Statistics handle nodes.
115    */
116   struct GNUNET_STATISTICS_Handle *handle;
117   /**
118    * @brief Identifier for shutdown task for this node.
119    */
120   struct GNUNET_SCHEDULER_Task *shutdown_task;
121 } *nodes;
122
123 /**
124  * @brief Number of configurations of all (testbed) nodes.
125  */
126 static unsigned num_nodes;
127
128 /**
129  * @brief Set of values for a combination of subsystem and name.
130  */
131 struct ValueSet
132 {
133   /**
134    * @brief Subsystem of the valueset.
135    */
136   char *subsystem;
137
138   /**
139    * @brief Name of the valueset.
140    */
141   char *name;
142
143   /**
144    * @brief The values.
145    */
146   uint64_t *values;
147
148   /**
149    * @brief Persistence of the values.
150    */
151   int is_persistent;
152 };
153
154 /**
155  * @brief Collection of all values (represented with #ValueSet).
156  */
157 static struct GNUNET_CONTAINER_MultiHashMap *values;
158
159 /**
160  * @brief Number of nodes that have their values ready.
161  */
162 static int num_nodes_ready;
163
164 /**
165  * @brief Number of nodes that have their values ready.
166  */
167 static int num_nodes_ready_shutdown;
168
169 /**
170  * @brief Create a new #ValueSet
171  *
172  * @param subsystem Subsystem of the valueset.
173  * @param name Name of the valueset.
174  * @param num_values Number of values in valueset - number of peers.
175  * @param is_persistent Persistence status of values.
176  *
177  * @return Newly allocated #ValueSet.
178  */
179 static struct ValueSet *
180 new_value_set (const char *subsystem,
181                const char *name,
182                unsigned num_values,
183                int is_persistent)
184 {
185   struct ValueSet *value_set;
186
187   value_set = GNUNET_new (struct ValueSet);
188   value_set->subsystem = GNUNET_strdup (subsystem);
189   value_set->name = GNUNET_strdup (name);
190   value_set->values = GNUNET_new_array (num_values, uint64_t);
191   value_set->is_persistent = persistent;
192   return value_set;
193 }
194
195
196 /**
197  * @brief Print the (collected) values.
198  *
199  * Implements #GNUNET_CONTAINER_HashMapIterator.
200  *
201  * @param cls Closure - unused
202  * @param key #GNUNET_HashCode key of #GNUNET_CONTAINER_MultiHashMap iterator -
203  *        unused
204  * @param value Values represented as #ValueSet.
205  *
206  * @return GNUNET_YES - continue iteration.
207  */
208 static int
209 printer (void *cls, const struct GNUNET_HashCode *key, void *value)
210 {
211   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
212   const char *now_str;
213   struct ValueSet *value_set = value;
214
215   if (quiet == GNUNET_NO)
216   {
217     if (GNUNET_YES == watch)
218     {
219       now_str = GNUNET_STRINGS_absolute_time_to_string (now);
220       fprintf (stdout,
221                "%24s%s %s%s%12s%s %s%50s%s%s ",
222                now_str,
223                csv_separator,
224                value_set->is_persistent ? "!" : " ",
225                csv_separator,
226                value_set->subsystem,
227                csv_separator,
228                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
229                _ (value_set->name),
230                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
231                (0 == strlen (csv_separator) ? ":" : csv_separator));
232     }
233     else
234     {
235       fprintf (stdout,
236                "%s%s%12s%s %s%50s%s%s ",
237                value_set->is_persistent ? "!" : " ",
238                csv_separator,
239                value_set->subsystem,
240                csv_separator,
241                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
242                _ (value_set->name),
243                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
244                (0 == strlen (csv_separator) ? ":" : csv_separator));
245     }
246   }
247   for (unsigned i = 0; i < num_nodes; i++)
248   {
249     fprintf (stdout,
250              "%16llu%s",
251              (unsigned long long) value_set->values[i],
252              csv_separator);
253   }
254   fprintf (stdout, "\n");
255   GNUNET_free (value_set->subsystem);
256   GNUNET_free (value_set->name);
257   GNUNET_free (value_set->values);
258   GNUNET_free (value_set);
259   return GNUNET_YES;
260 }
261
262
263 /**
264  * Callback function to process statistic values.
265  *
266  * @param cls closure
267  * @param subsystem name of subsystem that created the statistic
268  * @param name the name of the datum
269  * @param value the current value
270  * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
271  * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
272  */
273 static int
274 printer_watch (void *cls,
275                const char *subsystem,
276                const char *name,
277                uint64_t value,
278                int is_persistent)
279 {
280   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
281   const char *now_str;
282
283   if (quiet == GNUNET_NO)
284   {
285     if (GNUNET_YES == watch)
286     {
287       now_str = GNUNET_STRINGS_absolute_time_to_string (now);
288       fprintf (stdout,
289                "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n",
290                now_str,
291                csv_separator,
292                is_persistent ? "!" : " ",
293                csv_separator,
294                subsystem,
295                csv_separator,
296                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
297                _ (name),
298                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
299                (0 == strlen (csv_separator) ? ":" : csv_separator),
300                (unsigned long long) value);
301     }
302     else
303     {
304       fprintf (stdout,
305                "%s%s%12s%s %s%50s%s%s %16llu\n",
306                is_persistent ? "!" : " ",
307                csv_separator,
308                subsystem,
309                csv_separator,
310                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
311                _ (name),
312                (0 == strlen (csv_separator) ? "" : "\""),   /* quotes if csv */
313                (0 == strlen (csv_separator) ? ":" : csv_separator),
314                (unsigned long long) value);
315     }
316   }
317   else
318     fprintf (stdout, "%llu\n", (unsigned long long) value);
319
320   return GNUNET_OK;
321 }
322
323
324 /**
325  * @brief Clean all data structures related to given node.
326  *
327  * Also clears global structures if we are the last node to clean.
328  *
329  * @param cls the index of the node
330  */
331 static void
332 clean_node (void *cls)
333 {
334   const unsigned index_node = *(unsigned *) cls;
335   struct GNUNET_STATISTICS_Handle *h;
336   struct GNUNET_STATISTICS_GetHandle *gh;
337
338   if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */
339       (NULL != nodes[index_node].conf))
340   {
341     GNUNET_CONFIGURATION_destroy (nodes[index_node].conf);
342     nodes[index_node].conf = NULL;
343   }
344
345   h = nodes[index_node].handle;
346   gh = nodes[index_node].gh;
347
348   if (NULL != gh)
349   {
350     GNUNET_STATISTICS_get_cancel (gh);
351     gh = NULL;
352   }
353   if (GNUNET_YES == watch)
354   {
355     GNUNET_assert (
356       GNUNET_OK ==
357       GNUNET_STATISTICS_watch_cancel (h,
358                                       subsystem,
359                                       name,
360                                       &printer_watch,
361                                       &nodes[index_node].index_node));
362   }
363
364   if (NULL != h)
365   {
366     GNUNET_STATISTICS_destroy (h, GNUNET_NO);
367     h = NULL;
368   }
369
370   num_nodes_ready_shutdown++;
371   if (num_nodes == num_nodes_ready_shutdown)
372   {
373     GNUNET_array_grow (nodes, num_nodes, 0);
374     GNUNET_CONTAINER_multihashmap_destroy (values);
375   }
376 }
377
378
379 /**
380  * @brief Print and shutdown
381  *
382  * @param cls unused
383  */
384 static void
385 print_finish (void *cls)
386 {
387   GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL);
388   GNUNET_SCHEDULER_shutdown ();
389 }
390
391
392 /**
393  * @brief Called once all statistic values are available.
394  *
395  * Implements #GNUNET_STATISTICS_Callback
396  *
397  * @param cls Closure - The index of the node.
398  * @param succes Whether statistics were obtained successfully.
399  */
400 static void
401 continuation_print (void *cls, int success)
402 {
403   const unsigned index_node = *(unsigned *) cls;
404
405   nodes[index_node].gh = NULL;
406   if (GNUNET_OK != success)
407   {
408     if (NULL == remote_host)
409       fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
410     else
411       fprintf (stderr,
412                _ ("Failed to obtain statistics from host `%s:%llu'\n"),
413                remote_host,
414                remote_port);
415     ret = 1;
416   }
417   if (NULL != nodes[index_node].shutdown_task)
418   {
419     GNUNET_SCHEDULER_cancel (nodes[index_node].shutdown_task);
420     nodes[index_node].shutdown_task = NULL;
421   }
422   GNUNET_SCHEDULER_add_now (clean_node, &nodes[index_node].index_node);
423   num_nodes_ready++;
424   if (num_nodes_ready == num_nodes)
425   {
426     GNUNET_SCHEDULER_add_now (print_finish, NULL);
427   }
428 }
429
430
431 /**
432  * Function called last by the statistics code.
433  *
434  * @param cls closure
435  * @param success #GNUNET_OK if statistics were
436  *        successfully obtained, #GNUNET_SYSERR if not.
437  */
438 static void
439 cleanup (void *cls, int success)
440 {
441   for (unsigned i = 0; i < num_nodes; i++)
442   {
443     nodes[i].gh = NULL;
444   }
445   if (GNUNET_OK != success)
446   {
447     if (NULL == remote_host)
448       fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
449     else
450       fprintf (stderr,
451                _ ("Failed to obtain statistics from host `%s:%llu'\n"),
452                remote_host,
453                remote_port);
454     ret = 1;
455   }
456   GNUNET_SCHEDULER_shutdown ();
457 }
458
459
460 /**
461  * @brief Iterate over statistics values and store them in #values.
462  * They will be printed once all are available.
463  *
464  * @param cls Cosure - Node index.
465  * @param subsystem Subsystem of the value.
466  * @param name Name of the value.
467  * @param value Value itself.
468  * @param is_persistent Persistence.
469  *
470  * @return GNUNET_OK - continue.
471  */
472 static int
473 collector (void *cls,
474            const char *subsystem,
475            const char *name,
476            uint64_t value,
477            int is_persistent)
478 {
479   const unsigned index_node = *(unsigned *) cls;
480   struct GNUNET_HashCode *key;
481   struct GNUNET_HashCode hc;
482   char *subsys_name;
483   unsigned len_subsys_name;
484   struct ValueSet *value_set;
485
486   len_subsys_name = strlen (subsystem) + 3 + strlen (name) + 1;
487   subsys_name = GNUNET_malloc (len_subsys_name);
488   sprintf (subsys_name, "%s---%s", subsystem, name);
489   key = &hc;
490   GNUNET_CRYPTO_hash (subsys_name, len_subsys_name, key);
491   GNUNET_free (subsys_name);
492   if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key))
493   {
494     value_set = GNUNET_CONTAINER_multihashmap_get (values, key);
495   }
496   else
497   {
498     value_set = new_value_set (subsystem, name, num_nodes, is_persistent);
499   }
500   value_set->values[index_node] = value;
501   GNUNET_assert (GNUNET_YES ==
502                  GNUNET_CONTAINER_multihashmap_put (
503                    values,
504                    key,
505                    value_set,
506                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
507   return GNUNET_OK;
508 }
509
510
511 /**
512  * Main task that does the actual work.
513  *
514  * @param cls closure with our configuration
515  */
516 static void
517 main_task (void *cls)
518 {
519   unsigned index_node = *(unsigned *) cls;
520   const struct GNUNET_CONFIGURATION_Handle *cfg = nodes[index_node].conf;
521
522   if (set_value)
523   {
524     if (NULL == subsystem)
525     {
526       fprintf (stderr, "%s", _ ("Missing argument: subsystem \n"));
527       ret = 1;
528       return;
529     }
530     if (NULL == name)
531     {
532       fprintf (stderr, "%s", _ ("Missing argument: name\n"));
533       ret = 1;
534       return;
535     }
536     nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, cfg);
537     if (NULL == nodes[index_node].handle)
538     {
539       ret = 1;
540       return;
541     }
542     GNUNET_STATISTICS_set (nodes[index_node].handle,
543                            name,
544                            (uint64_t) set_val,
545                            persistent);
546     GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_YES);
547     nodes[index_node].handle = NULL;
548     return;
549   }
550   if (NULL == (nodes[index_node].handle =
551                  GNUNET_STATISTICS_create ("gnunet-statistics", cfg)))
552   {
553     ret = 1;
554     return;
555   }
556   if (GNUNET_NO == watch)
557   {
558     if (NULL == (nodes[index_node].gh =
559                    GNUNET_STATISTICS_get (nodes[index_node].handle,
560                                           subsystem,
561                                           name,
562                                           &continuation_print,
563                                           &collector,
564                                           &nodes[index_node].index_node)))
565       cleanup (nodes[index_node].handle, GNUNET_SYSERR);
566   }
567   else
568   {
569     if ((NULL == subsystem) || (NULL == name))
570     {
571       printf (_ ("No subsystem or name given\n"));
572       GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_NO);
573       nodes[index_node].handle = NULL;
574       ret = 1;
575       return;
576     }
577     if (GNUNET_OK != GNUNET_STATISTICS_watch (nodes[index_node].handle,
578                                               subsystem,
579                                               name,
580                                               &printer_watch,
581                                               &nodes[index_node].index_node))
582     {
583       fprintf (stderr, _ ("Failed to initialize watch routine\n"));
584       nodes[index_node].shutdown_task =
585         GNUNET_SCHEDULER_add_now (&clean_node, &nodes[index_node].index_node);
586       return;
587     }
588   }
589   nodes[index_node].shutdown_task =
590     GNUNET_SCHEDULER_add_shutdown (&clean_node, &nodes[index_node].index_node);
591 }
592
593
594 /**
595  * @brief Iter over content of a node's directory to check for existence of a
596  * config file.
597  *
598  * Implements #GNUNET_FileNameCallback
599  *
600  * @param cls pointer to indicate success
601  * @param filename filename inside the directory of the potential node
602  *
603  * @return to continue iteration or not to
604  */
605 static int
606 iter_check_config (void *cls, const char *filename)
607 {
608   if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6))
609   {
610     /* Found the config - stop iteration successfully */
611     GNUNET_array_grow (nodes, num_nodes, num_nodes + 1);
612     nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create ();
613     nodes[num_nodes - 1].index_node = num_nodes - 1;
614     if (GNUNET_OK !=
615         GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename))
616     {
617       fprintf (stderr, "Failed loading config `%s'\n", filename);
618       return GNUNET_SYSERR;
619     }
620     return GNUNET_NO;
621   }
622   else
623   {
624     /* Continue iteration */
625     return GNUNET_OK;
626   }
627 }
628
629
630 /**
631  * @brief Iterates over filenames in testbed directory.
632  *
633  * Implements #GNUNET_FileNameCallback
634  *
635  * Checks if the file is a directory for a testbed node
636  * and counts the nodes.
637  *
638  * @param cls counter of nodes
639  * @param filename full path of the file in testbed
640  *
641  * @return status whether to continue iteration
642  */
643 static int
644 iter_testbed_path (void *cls, const char *filename)
645 {
646   unsigned index_node;
647
648   GNUNET_assert (NULL != filename);
649   if (1 == sscanf (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node))
650   {
651     if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL))
652     {
653       /* This is probably no directory for a testbed node
654        * Go on with iteration */
655       return GNUNET_OK;
656     }
657     return GNUNET_OK;
658   }
659   return GNUNET_OK;
660 }
661
662
663 /**
664  * @brief Count the number of nodes running in the testbed
665  *
666  * @param path_testbed path to the testbed data
667  *
668  * @return number of running nodes
669  */
670 static int
671 discover_testbed_nodes (const char *path_testbed)
672 {
673   int num_dir_entries;
674
675   num_dir_entries =
676     GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL);
677   if (-1 == num_dir_entries)
678   {
679     fprintf (stderr, "Failure during scanning directory `%s'\n", path_testbed);
680     return -1;
681   }
682   return 0;
683 }
684
685
686 /**
687  * Main function that will be run by the scheduler.
688  *
689  * @param cls closure
690  * @param args remaining command-line arguments
691  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
692  * @param cfg configuration
693  */
694 static void
695 run (void *cls,
696      char *const *args,
697      const char *cfgfile,
698      const struct GNUNET_CONFIGURATION_Handle *cfg)
699 {
700   struct GNUNET_CONFIGURATION_Handle *c;
701
702   c = (struct GNUNET_CONFIGURATION_Handle *) cfg;
703   set_value = GNUNET_NO;
704   if (NULL == csv_separator)
705     csv_separator = "";
706   if (NULL != args[0])
707   {
708     if (1 != sscanf (args[0], "%llu", &set_val))
709     {
710       fprintf (stderr, _ ("Invalid argument `%s'\n"), args[0]);
711       ret = 1;
712       return;
713     }
714     set_value = GNUNET_YES;
715   }
716   if (NULL != remote_host)
717   {
718     if (0 == remote_port)
719     {
720       if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
721                                                                   "statistics",
722                                                                   "PORT",
723                                                                   &remote_port))
724       {
725         fprintf (stderr,
726                  _ ("A port is required to connect to host `%s'\n"),
727                  remote_host);
728         return;
729       }
730     }
731     else if (65535 <= remote_port)
732     {
733       fprintf (stderr,
734                _ (
735                  "A port has to be between 1 and 65535 to connect to host `%s'\n"),
736                remote_host);
737       return;
738     }
739
740     /* Manipulate configuration */
741     GNUNET_CONFIGURATION_set_value_string (c, "statistics", "UNIXPATH", "");
742     GNUNET_CONFIGURATION_set_value_string (c,
743                                            "statistics",
744                                            "HOSTNAME",
745                                            remote_host);
746     GNUNET_CONFIGURATION_set_value_number (c,
747                                            "statistics",
748                                            "PORT",
749                                            remote_port);
750   }
751   if (NULL == path_testbed)
752   {
753     values = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
754     GNUNET_array_grow (nodes, num_nodes, 1);
755     nodes[0].index_node = 0;
756     nodes[0].conf = c;
757     GNUNET_SCHEDULER_add_now (&main_task, &nodes[0].index_node);
758   }
759   else
760   {
761     if (GNUNET_YES == watch)
762     {
763       printf (
764         _ ("Not able to watch testbed nodes (yet - feel free to implement)\n"));
765       ret = 1;
766       return;
767     }
768     values = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
769     if (-1 == discover_testbed_nodes (path_testbed))
770     {
771       return;
772     }
773     /* For each config/node collect statistics */
774     for (unsigned i = 0; i < num_nodes; i++)
775     {
776       GNUNET_SCHEDULER_add_now (&main_task, &nodes[i].index_node);
777     }
778   }
779 }
780
781
782 /**
783  * The main function to obtain statistics in GNUnet.
784  *
785  * @param argc number of arguments from the command line
786  * @param argv command line arguments
787  * @return 0 ok, 1 on error
788  */
789 int
790 main (int argc, char *const *argv)
791 {
792   struct GNUNET_GETOPT_CommandLineOption options[] =
793   { GNUNET_GETOPT_option_string (
794       'n',
795       "name",
796       "NAME",
797       gettext_noop ("limit output to statistics for the given NAME"),
798       &name),
799
800     GNUNET_GETOPT_option_flag ('p',
801                                "persistent",
802                                gettext_noop (
803                                  "make the value being set persistent"),
804                                &persistent),
805
806     GNUNET_GETOPT_option_string ('s',
807                                  "subsystem",
808                                  "SUBSYSTEM",
809                                  gettext_noop (
810                                    "limit output to the given SUBSYSTEM"),
811                                  &subsystem),
812
813     GNUNET_GETOPT_option_string ('S',
814                                  "csv-separator",
815                                  "CSV_SEPARATOR",
816                                  gettext_noop ("use as csv separator"),
817                                  &csv_separator),
818
819     GNUNET_GETOPT_option_filename (
820       't',
821       "testbed",
822       "TESTBED",
823       gettext_noop ("path to the folder containing the testbed data"),
824       &path_testbed),
825
826     GNUNET_GETOPT_option_flag ('q',
827                                "quiet",
828                                gettext_noop (
829                                  "just print the statistics value"),
830                                &quiet),
831
832     GNUNET_GETOPT_option_flag ('w',
833                                "watch",
834                                gettext_noop ("watch value continuously"),
835                                &watch),
836
837     GNUNET_GETOPT_option_string ('r',
838                                  "remote",
839                                  "REMOTE",
840                                  gettext_noop ("connect to remote host"),
841                                  &remote_host),
842
843     GNUNET_GETOPT_option_ulong ('o',
844                                 "port",
845                                 "PORT",
846                                 gettext_noop ("port for remote host"),
847                                 &remote_port),
848
849     GNUNET_GETOPT_OPTION_END };
850
851   remote_port = 0;
852   remote_host = NULL;
853   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
854     return 2;
855
856   ret = (GNUNET_OK ==
857          GNUNET_PROGRAM_run (argc,
858                              argv,
859                              "gnunet-statistics [options [value]]",
860                              gettext_noop (
861                                "Print statistics about GNUnet operations."),
862                              options,
863                              &run,
864                              NULL))
865         ? ret
866         : 1;
867   GNUNET_free_non_null (remote_host);
868   GNUNET_free ((void *) argv);
869   return ret;
870 }
871
872
873 /* end of gnunet-statistics.c */