Code

Merge branch 'xl/zfs'
authorFlorian Forster <octo@collectd.org>
Tue, 4 Jun 2013 06:42:25 +0000 (08:42 +0200)
committerFlorian Forster <octo@collectd.org>
Tue, 4 Jun 2013 06:42:25 +0000 (08:42 +0200)
src/collectd.conf.pod
src/curl.c
src/df.c
src/write_riemann.c

index 432efb830fe98683b9b618e4f9b9d9bb231d2941..541af4ce9340b66450a06a21a5d582e3c9331c63 100644 (file)
@@ -1511,6 +1511,15 @@ Enable this option if inodes are a scarce resource for you, usually because
 many small files are stored on the disk. This is a usual scenario for mail
 transfer agents and web caches.
 
+=item B<ReportPercentage> B<false>|B<true>
+
+Enables or disables reporting of disk space and inodes as a percentage.
+Defaults to B<false>.
+
+This is useful for deploying I<collectd> on the cloud, where machines with
+different disk size may exist. Then it is more practical to configure
+thresholds based on relative disk size.
+
 =back
 
 =head2 Plugin C<disk>
@@ -6025,7 +6034,7 @@ Synopsis:
      Protocol UDP
      StoreRates true
      AlwaysAppendDS false
-     Delay 10
+     TTLFactor 2.0
    </Node>
    Tag "foobar"
  </Plugin>
@@ -6072,6 +6081,15 @@ If set the B<true>, append the name of the I<Data Source> (DS) to the
 identifies a metric in I<Riemann>. If set to B<false> (the default), this is
 only done when there is more than one DS.
 
+=item B<TTLFactor> I<Factor>
+
+I<Riemann> events have a I<Time to Live> (TTL) which specifies how long each
+event is considered active. I<collectd> populates this field based on the
+metrics interval setting. This setting controls the factor with which the
+interval is multiplied to set the TTL. The default value is B<2.0>. Unless you
+know exactly what you're doing, you should only increase this setting from its
+default value.
+
 =back
 
 =item B<Tag> I<String>
index 7d3130773944f79ccee35c3fb6074c1cdbe3fe52..280e61c8649ae70a0f2bc99658aeed5659e71e5a 100644 (file)
@@ -630,7 +630,7 @@ static int cc_read_page (web_page_t *wp) /* {{{ */
 {
   web_match_t *wm;
   int status;
-  cdtime_t start;
+  cdtime_t start = 0;
 
   if (wp->response_time)
     start = cdtime ();
index ded374b942e5d08d804dd027292eef2ef9f50fcb..5ff3f59be8cbcb401dd288c17ec4b89777251b43 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -54,7 +54,8 @@ static const char *config_keys[] =
        "IgnoreSelected",
        "ReportByDevice",
        "ReportReserved",
-       "ReportInodes"
+       "ReportInodes",
+       "ReportPercentage"
 };
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
@@ -64,6 +65,7 @@ static ignorelist_t *il_fstype = NULL;
 
 static _Bool by_device = 0;
 static _Bool report_inodes = 0;
+static _Bool report_percentage = 0;
 
 static int df_init (void)
 {
@@ -132,6 +134,15 @@ static int df_config (const char *key, const char *value)
                return (0);
        }
 
+       else if (strcasecmp (key, "ReportPercentage") == 0)
+       {
+               if (IS_TRUE (value))
+                       report_percentage = 1;
+               else
+                       report_percentage = 0;
+
+               return (0);
+       }
 
        return (-1);
 }
@@ -210,7 +221,7 @@ static int df_read (void)
                if (!statbuf.f_blocks)
                        continue;
 
-               if (by_device) 
+               if (by_device)
                {
                        /* eg, /dev/hda1  -- strip off the "/dev/" */
                        if (strncmp (mnt_ptr->spec_device, "/dev/", strlen ("/dev/")) == 0)
@@ -218,13 +229,13 @@ static int df_read (void)
                        else
                                sstrncpy (disk_name, mnt_ptr->spec_device, sizeof (disk_name));
 
-                       if (strlen(disk_name) < 1) 
+                       if (strlen(disk_name) < 1)
                        {
                                DEBUG("df: no device name name for mountpoint %s, skipping", mnt_ptr->dir);
                                continue;
                        }
-               } 
-               else 
+               }
+               else
                {
                        if (strcmp (mnt_ptr->dir, "/") == 0)
                        {
@@ -274,12 +285,30 @@ static int df_read (void)
                blk_reserved = (uint64_t) (statbuf.f_bfree - statbuf.f_bavail);
                blk_used     = (uint64_t) (statbuf.f_blocks - statbuf.f_bfree);
 
-               df_submit_one (disk_name, "df_complex", "free",
+               if (report_percentage && (statbuf.f_blocks > 0))
+               {
+                       uint64_t blk_total = (uint64_t) statbuf.f_blocks;
+                       char plugin_instance[DATA_MAX_NAME_LEN];
+
+                       ssnprintf (plugin_instance, sizeof (plugin_instance),
+                                       "%s-bytes", disk_name);
+
+                       df_submit_one (plugin_instance, "percent", "free",
+                                       100.0 * ((gauge_t) blk_free) / ((gauge_t) blk_total));
+                       df_submit_one (plugin_instance, "percent", "reserved",
+                                       100.0 * ((gauge_t) blk_reserved) / ((gauge_t) blk_total));
+                       df_submit_one (plugin_instance, "percent", "used",
+                                       100.0 * ((gauge_t) blk_used) / ((gauge_t) blk_total));
+               }
+               else if (!report_percentage)
+               {
+                       df_submit_one (disk_name, "df_complex", "free",
                                (gauge_t) (blk_free * blocksize));
-               df_submit_one (disk_name, "df_complex", "reserved",
+                       df_submit_one (disk_name, "df_complex", "reserved",
                                (gauge_t) (blk_reserved * blocksize));
-               df_submit_one (disk_name, "df_complex", "used",
+                       df_submit_one (disk_name, "df_complex", "used",
                                (gauge_t) (blk_used * blocksize));
+               }
 
                /* inode handling */
                if (report_inodes)
@@ -297,13 +326,31 @@ static int df_read (void)
                        inode_free = (uint64_t) statbuf.f_favail;
                        inode_reserved = (uint64_t) (statbuf.f_ffree - statbuf.f_favail);
                        inode_used = (uint64_t) (statbuf.f_files - statbuf.f_ffree);
-                       
-                       df_submit_one (disk_name, "df_inodes", "free",
-                                       (gauge_t) inode_free);
-                       df_submit_one (disk_name, "df_inodes", "reserved",
-                                       (gauge_t) inode_reserved);
-                       df_submit_one (disk_name, "df_inodes", "used",
-                                       (gauge_t) inode_used);
+
+                       if (report_percentage && (statbuf.f_files > 0))
+                       {
+                               uint64_t inode_total = (uint64_t) statbuf.f_files;
+                               char plugin_instance[DATA_MAX_NAME_LEN];
+
+                               ssnprintf (plugin_instance, sizeof (plugin_instance),
+                                               "%s-inodes", disk_name);
+
+                               df_submit_one (plugin_instance, "percent", "free",
+                                               100.0 * ((gauge_t) inode_free) / ((gauge_t) inode_total));
+                               df_submit_one (plugin_instance, "percent", "reserved",
+                                               100.0 * ((gauge_t) inode_reserved) / ((gauge_t) inode_total));
+                               df_submit_one (plugin_instance, "percent", "used",
+                                               100.0 * ((gauge_t) inode_used) / ((gauge_t) inode_total));
+                       }
+                       else if (!report_percentage)
+                       {
+                               df_submit_one (disk_name, "df_inodes", "free",
+                                               (gauge_t) inode_free);
+                               df_submit_one (disk_name, "df_inodes", "reserved",
+                                               (gauge_t) inode_reserved);
+                               df_submit_one (disk_name, "df_inodes", "used",
+                                               (gauge_t) inode_used);
+                       }
                }
        }
 
index d31a988e76de275fe52adb50d3d23557095e4de9..3e2ddd75b0d5caec3bbc40b5121b1de20ab819b4 100644 (file)
@@ -37,6 +37,7 @@
 
 #define RIEMANN_HOST           "localhost"
 #define RIEMANN_PORT           "5555"
+#define RIEMANN_TTL_FACTOR      2.0
 
 struct riemann_host {
        char                    *name;
@@ -49,6 +50,7 @@ struct riemann_host {
        char                    *service;
        _Bool                    use_tcp;
        int                      s;
+       double                   ttl_factor;
 
        int                      reference_count;
 };
@@ -365,6 +367,7 @@ static Event *riemann_value_to_protobuf (struct riemann_host const *host, /* {{{
        Event *event;
        char name_buffer[5 * DATA_MAX_NAME_LEN];
        char service_buffer[6 * DATA_MAX_NAME_LEN];
+       double ttl;
        int i;
 
        event = malloc (sizeof (*event));
@@ -379,7 +382,9 @@ static Event *riemann_value_to_protobuf (struct riemann_host const *host, /* {{{
        event->host = strdup (vl->host);
        event->time = CDTIME_T_TO_TIME_T (vl->time);
        event->has_time = 1;
-       event->ttl = CDTIME_T_TO_TIME_T (2 * vl->interval);
+
+       ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
+       event->ttl = (float) ttl;
        event->has_ttl = 1;
 
        riemann_event_add_attribute (event, "plugin", vl->plugin);
@@ -597,6 +602,7 @@ riemann_config_node(oconfig_item_t *ci)
        host->store_rates = 1;
        host->always_append_ds = 0;
        host->use_tcp = 0;
+       host->ttl_factor = RIEMANN_TTL_FACTOR;
 
        status = cf_util_get_string (ci, &host->name);
        if (status != 0) {
@@ -656,6 +662,33 @@ riemann_config_node(oconfig_item_t *ci)
                                        &host->always_append_ds);
                        if (status != 0)
                                break;
+               } else if (strcasecmp ("TTLFactor", child->key) == 0) {
+                       double tmp = NAN;
+                       status = cf_util_get_double (child, &tmp);
+                       if (status != 0)
+                               break;
+                       if (tmp >= 2.0) {
+                               host->ttl_factor = tmp;
+                       } else if (tmp >= 1.0) {
+                               NOTICE ("write_riemann plugin: The configured "
+                                               "TTLFactor is very small "
+                                               "(%.1f). A value of 2.0 or "
+                                               "greater is recommended.",
+                                               tmp);
+                               host->ttl_factor = tmp;
+                       } else if (tmp > 0.0) {
+                               WARNING ("write_riemann plugin: The configured "
+                                               "TTLFactor is too small to be "
+                                               "useful (%.1f). I'll use it "
+                                               "since the user knows best, "
+                                               "but under protest.",
+                                               tmp);
+                               host->ttl_factor = tmp;
+                       } else { /* zero, negative and NAN */
+                               ERROR ("write_riemann plugin: The configured "
+                                               "TTLFactor is invalid (%.1f).",
+                                               tmp);
+                       }
                } else {
                        WARNING("write_riemann plugin: ignoring unknown config "
                                "option: \"%s\"", child->key);