X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdf.c;h=d327164ac601e3a98c59217122240b0e77b8ea4b;hb=c8e76316f549f75149d4787fd2e2390bbaee5531;hp=780197f66fa7a0ec5bfd199167273e44c373c02b;hpb=2d03e4e3df8383b6324845cb24bae021ce76115c;p=collectd.git diff --git a/src/df.c b/src/df.c index 780197f6..d327164a 100644 --- a/src/df.c +++ b/src/df.c @@ -1,6 +1,6 @@ /** * collectd - src/df.c - * Copyright (C) 2005 Florian octo Forster + * Copyright (C) 2005,2006 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -23,7 +23,9 @@ #include "collectd.h" #include "common.h" #include "plugin.h" +#include "configfile.h" #include "utils_mount.h" +#include "utils_ignorelist.h" #define MODULE_NAME "df" @@ -33,33 +35,102 @@ # define DF_HAVE_READ 0 #endif -#if HAVE_STATFS -#define STATANYFS statfs -#define BLOCKSIZE(s) (s).f_bsize - -#elif HAVE_STATVFS -#define STATANYFS statvfs -#define BLOCKSIZE(s) ((s).f_frsize ? (s).f_frsize : (s).f_bsize) +#if HAVE_STATVFS +# if HAVE_SYS_STATVFS_H +# include +# endif +# define STATANYFS statvfs +# define BLOCKSIZE(s) ((s).f_frsize ? (s).f_frsize : (s).f_bsize) +#elif HAVE_STATFS +# if HAVE_SYS_STATFS_H +# include +# endif +# define STATANYFS statfs +# define BLOCKSIZE(s) (s).f_bsize #endif static char *filename_template = "df-%s.rrd"; -/* 104857600 == 100 MB */ static char *ds_def[] = { - "DS:used:GAUGE:25:0:U", - "DS:free:GAUGE:25:0:U", + "DS:used:GAUGE:"COLLECTD_HEARTBEAT":0:U", + "DS:free:GAUGE:"COLLECTD_HEARTBEAT":0:U", NULL }; static int ds_num = 2; +static char *config_keys[] = +{ + "Device", + "MountPoint", + "FSType", + "IgnoreSelected", + NULL +}; +static int config_keys_num = 4; + +static ignorelist_t *il_device = NULL; +static ignorelist_t *il_mountpoint = NULL; +static ignorelist_t *il_fstype = NULL; + #define BUFSIZE 512 static void df_init (void) { + if (il_device == NULL) + il_device = ignorelist_create (1); + if (il_mountpoint == NULL) + il_mountpoint = ignorelist_create (1); + if (il_fstype == NULL) + il_fstype = ignorelist_create (1); + return; } +static int df_config (char *key, char *value) +{ + df_init (); + + if (strcasecmp (key, "Device") == 0) + { + if (ignorelist_add (il_device, value)) + return (1); + return (0); + } + else if (strcasecmp (key, "MountPoint") == 0) + { + if (ignorelist_add (il_mountpoint, value)) + return (1); + return (0); + } + else if (strcasecmp (key, "FSType") == 0) + { + if (ignorelist_add (il_fstype, value)) + return (1); + return (0); + } + else if (strcasecmp (key, "IgnoreSelected") == 0) + { + if ((strcasecmp (value, "True") == 0) + || (strcasecmp (value, "Yes") == 0) + || (strcasecmp (value, "On") == 0)) + { + ignorelist_set_invert (il_device, 0); + ignorelist_set_invert (il_mountpoint, 0); + ignorelist_set_invert (il_fstype, 0); + } + else + { + ignorelist_set_invert (il_device, 1); + ignorelist_set_invert (il_mountpoint, 1); + ignorelist_set_invert (il_fstype, 1); + } + return (0); + } + + return (-1); +} + static void df_write (char *host, char *inst, char *val) { char file[BUFSIZE]; @@ -90,24 +161,26 @@ static void df_submit (char *df_name, static void df_read (void) { - struct STATANYFS statbuf; +#if HAVE_STATVFS + struct statvfs statbuf; +#elif HAVE_STATFS + struct statfs statbuf; +#endif + /* struct STATANYFS statbuf; */ cu_mount_t *mnt_list; cu_mount_t *mnt_ptr; unsigned long long blocksize; unsigned long long df_free; unsigned long long df_used; + char mnt_name[BUFSIZE]; mnt_list = NULL; if (cu_mount_getlist (&mnt_list) == NULL) - { - syslog (LOG_WARNING, "cu_mount_getlist returned `NULL'"); return; - } for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) { - if (STATANYFS (mnt_ptr->dir, &statbuf) < 0) { syslog (LOG_ERR, "statv?fs failed: %s", strerror (errno)); @@ -121,8 +194,33 @@ static void df_read (void) df_free = statbuf.f_bfree * blocksize; df_used = (statbuf.f_blocks - statbuf.f_bfree) * blocksize; - syslog (LOG_INFO, "blocksize = %llu, free = %llu, used = %llu, dir = %s", blocksize, df_free, df_used, mnt_ptr->dir); - df_submit ("blahfoo", df_used, df_free); + if (strcmp (mnt_ptr->dir, "/") == 0) + { + strncpy (mnt_name, "root", BUFSIZE); + } + else + { + int i, len; + + strncpy (mnt_name, mnt_ptr->dir + 1, BUFSIZE); + len = strlen (mnt_name); + + for (i = 0; i < len; i++) + if (mnt_name[i] == '/') + mnt_name[i] = '-'; + } + + if (ignorelist_match (il_device, + (mnt_ptr->spec_device != NULL) + ? mnt_ptr->spec_device + : mnt_ptr->device)) + continue; + if (ignorelist_match (il_mountpoint, mnt_ptr->dir)) + continue; + if (ignorelist_match (il_fstype, mnt_ptr->type)) + continue; + + df_submit (mnt_name, df_used, df_free); } cu_mount_freelist (mnt_list); @@ -134,6 +232,7 @@ static void df_read (void) void module_register (void) { plugin_register (MODULE_NAME, df_init, df_read, df_write); + cf_register (MODULE_NAME, df_config, config_keys, config_keys_num); } #undef BUFSIZE