summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 552e81e)
raw | patch | inline | side by side (parent: 552e81e)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 7 Aug 2010 07:43:33 +0000 (09:43 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 7 Aug 2010 07:43:33 +0000 (09:43 +0200) |
This is a GNU extension and, thus, not portable.
Also, pimped the usage output a bit.
Also, pimped the usage output a bit.
src/collectd-flush.c | patch | blob | history | |
src/collectd-flush.pod | patch | blob | history |
diff --git a/src/collectd-flush.c b/src/collectd-flush.c
index 165c073adc8714c5bd49121d4da5c33537d2c366..7b9326bfac83d0a2d745f1cdf05ffed9cd6c3983 100644 (file)
--- a/src/collectd-flush.c
+++ b/src/collectd-flush.c
}
static void exit_usage (const char *name, int status) {
- fprintf ((status == 0) ? stdout : stderr, "Usage: %s [options]\n"
- "\n"
- "Valid options are:\n"
- " -h, --help Display this help message.\n"
- " -s, --socket=<socket> Path to collectd's UNIX socket. Default: /var/run/collectd-unixsock\n"
- " -p, --plugin=<plugin> Plugin to flush _to_ (not from). Example: rrdtool\n"
- " -i, --identifier=<identifier>\n"
- " Only flush data specified by <identifier>, which has the format: \n"
- "\n"
- " [<hostname>/]<plugin>[-<plugin_instance>]/<type>[-<type_instance>]\n"
- "\n"
- " Hostname defaults to the local hostname if omitted.\n"
- " No error is returned if the specified identifier does not exist.\n"
- " Examples: uptime/uptime\n"
- " somehost/cpu-0/cpu-wait\n"
- " -t, --timeout=<timeout> Only flush values older than this timeout.\n", name);
+ fprintf ((status == 0) ? stdout : stderr,
+ "Usage: %s [options]\n\n"
+
+ "Available options:\n"
+ " -s Path to collectd's UNIX socket.\n"
+ " Default: /var/run/collectd-unixsock\n"
+ " -p <plugin> Plugin to be flushed.\n"
+ " -i <id> Flush data identified by <id> only (see below).\n"
+ " -t <seconds> Flush values older than this value only.\n"
+
+ "\n -h Display this help and exit.\n"
+
+ "\nIdentfiers:\n\n"
+
+ "An identifier (as accepted by the -i option) has the following\n"
+ "format:\n\n"
+
+ " [<hostname>/]<plugin>[-<plugin_instance>]/<type>[-<type_instance>]\n\n"
+
+ "Hostname defaults to the local hostname if omitted (e.g., uptime/uptime).\n"
+ "No error is returned if the specified identifier does not exist.\n"
+
+ "\nExample:\n\n"
+
+ " collectd-flush -p rrdtool -i somehost/cpu-0/cpu-wait\n\n"
+
+ "Flushes all CPU wait RRD values of the first CPU of the local host.\n"
+ "I.e., writes all pending RRD updates of that data-source to disk.\n"
+ , name);
exit (status);
}
char ident_str[1024] = "";
int timeout = -1;
char hostname[1024];
- char c;
- static struct option long_options[] =
- {
- {"help", no_argument, 0, 'h'},
- {"socket", required_argument, 0, 's'},
- {"plugin", required_argument, 0, 'p'},
- {"identifier", required_argument, 0, 'i'},
- {"timeout", required_argument, 0, 't'}
- };
- int option_index = 0;
+ while (42) {
+ int c;
+ c = getopt (argc, argv, "s:p:i:ht:");
+
+ if (c == -1)
+ break;
- while ((c = getopt_long (argc, argv, "s:p:i:ht:", long_options, &option_index)) != -1) {
switch (c) {
case 's':
snprintf (address, sizeof (address), "unix:%s", optarg);
+ address[sizeof (address) - 1] = '\0';
break;
case 'p':
plugin = optarg;
break;
case 'i':
- if(charoccurences(optarg, '/') == 1) {
+ if (charoccurences (optarg, '/') == 1) {
/* The user has omitted the hostname part of the identifier
* (there is only one '/' in the identifier)
* Let's add the local hostname */
- if(gethostname(hostname, sizeof(hostname)) != 0) {
- fprintf (stderr, "Could not get local hostname: %s", strerror(errno));
+ if (gethostname (hostname, sizeof (hostname)) != 0) {
+ fprintf (stderr, "Could not get local hostname: %s", strerror (errno));
return 1;
}
/* Make sure hostname is zero-terminated */
- hostname[sizeof(hostname)-1] = '\0';
+ hostname[sizeof (hostname) - 1] = '\0';
snprintf (ident_str, sizeof (ident_str), "%s/%s", hostname, optarg);
/* Make sure ident_str is zero terminated */
- ident_str[sizeof(ident_str)-1] = '\0';
+ ident_str[sizeof(ident_str) - 1] = '\0';
} else {
- strncpy(ident_str, optarg, sizeof (ident_str));
+ strncpy (ident_str, optarg, sizeof (ident_str));
/* Make sure identifier is zero terminated */
- ident_str[sizeof(ident_str)-1] = '\0';
+ ident_str[sizeof (ident_str) - 1] = '\0';
}
break;
case 't':
break;
case 'h':
exit_usage (argv[0], 0);
+ break;
default:
exit_usage (argv[0], 1);
}
diff --git a/src/collectd-flush.pod b/src/collectd-flush.pod
index cf7b178bc6f83567f33c7d35d007c78102b7aaf4..f3fb866a971e70ac580897ee3a74d97c1d5c1313 100644 (file)
--- a/src/collectd-flush.pod
+++ b/src/collectd-flush.pod
=head1 DESCRIPTION
-This small command line utitilty uses C<libcollectdclient> to flush collectd
-through a socket from the L<unixsock plugin>. Useful if you want to be sure
-you have the latest values in your RRD files before graphing them or copying
+This small command line utitilty uses C<libcollectdclient> to flush collectd
+through a socket from the L<unixsock plugin>. Useful if you want to be sure
+you have the latest values in your RRD files before graphing them or copying
them somewhere else.
=head1 ARGUMENTS AND OPTIONS
The following arguments and options are understood by collectd-flush. The order
-of the arguments generally doesn't matter, as long as no argument is passed
+of the arguments generally doesn't matter, as long as no argument is passed
more than once.
=over 4
-=item B<-h>, B<--help>
+=item B<-s> I<socket>
-Display information about the options.
-
-=item B<-s>, B<--socket=>I<socket>
-
-Path to the UNIX socket opened by collectd's C<unixsock plugin>.
+Path to the UNIX socket opened by collectd's C<unixsock plugin>.
Default: /var/run/collectd-unixsock
-=item B<-p>, B<--plugin=>I<plugin>
+=item B<-p> I<plugin>
Plugin to flush I<to>. Example: B<rrdtool>.
-=item B<-i>, B<--identifier=>I<identifier>
+=item B<-i> I<identifier>
If this option is present, only the data specified by I<identifier> will be flushed.
I<identifier> has the following format:
otherhost/memory/memory-used
Hostname defaults to the local hostname if omitted. No error is returned if the
-specified identifier does not exist (this is a limitation in the
-C<libcollectdclient> library).You can only specify one identifier each time you
+specified identifier does not exist (this is a limitation in the
+C<libcollectdclient> library). You can only specify one identifier each time you
run this program (even though L<collectd-unixsock(5)> supports multiple
identifiers).
-=item B<-t>, B<--timeout=>I<timeout>
+=item B<-t> I<timeout>
+
+Only flush values older than I<timeout> seconds.
+
+=item B<-h>
-Only flush values older than I<timeout>.
+Display usage information and exit.
=back