107 lines
3.1 KiB
C
107 lines
3.1 KiB
C
/***************************************************************************
|
|
* Copyright (C) 06/2006 by Olaf Rempel *
|
|
* razzor@kopf-tisch.de *
|
|
* *
|
|
* 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 Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <mntent.h>
|
|
#include <sys/vfs.h>
|
|
#include <string.h>
|
|
|
|
#include "plugins.h"
|
|
|
|
struct sammler_plugin plugin;
|
|
|
|
static char *ds_def[] = {
|
|
"DS:block_total:GAUGE:%d:0:U",
|
|
"DS:block_free:GAUGE:%d:0:U",
|
|
NULL
|
|
};
|
|
|
|
static char ** get_ds(int ds_id)
|
|
{
|
|
return ds_def;
|
|
}
|
|
|
|
static void probe(void)
|
|
{
|
|
FILE *fp;
|
|
struct mntent *mnt;
|
|
struct statfs fs;
|
|
char *slash, filename[64];
|
|
int len;
|
|
|
|
fp = setmntent("/etc/mtab", "r");
|
|
if (fp == NULL) {
|
|
log_print(LOG_WARN, "plugin mount");
|
|
return;
|
|
}
|
|
|
|
while ((mnt = getmntent(fp)) != NULL) {
|
|
if (!strcmp(mnt->mnt_fsname, "none"))
|
|
continue;
|
|
|
|
if (!strcmp(mnt->mnt_fsname, "proc"))
|
|
continue;
|
|
|
|
if (!strcmp(mnt->mnt_fsname, "sysfs"))
|
|
continue;
|
|
|
|
if (!strcmp(mnt->mnt_fsname, "udev"))
|
|
continue;
|
|
|
|
if (!strcmp(mnt->mnt_fsname, "devpts"))
|
|
continue;
|
|
|
|
if (!strcmp(mnt->mnt_type, "nfs"))
|
|
continue;
|
|
|
|
if (statfs(mnt->mnt_dir, &fs) == -1) {
|
|
log_print(LOG_WARN, "plugin mount: statfs(%s)", mnt->mnt_dir);
|
|
continue;
|
|
}
|
|
|
|
if (fs.f_blocks == 0)
|
|
continue;
|
|
|
|
slash = mnt->mnt_fsname;
|
|
while (slash && (slash = strchr(slash, '/'))) {
|
|
slash = strchr(slash, '/');
|
|
*slash++ = '_';
|
|
}
|
|
|
|
len = snprintf(filename, sizeof(filename), "mount%s.rrd", mnt->mnt_fsname);
|
|
if (len < 0 || len >= sizeof(filename)) {
|
|
log_print(LOG_WARN, "plugin mount: file name too long", mnt->mnt_fsname);
|
|
continue;
|
|
}
|
|
|
|
probe_submit(&plugin, filename, 0, "%lu:%lu",
|
|
fs.f_blocks * (fs.f_bsize /1024),
|
|
fs.f_bfree * (fs.f_bsize /1024));
|
|
}
|
|
endmntent(fp);
|
|
}
|
|
|
|
struct sammler_plugin plugin = {
|
|
.name = "mount",
|
|
.version = 1,
|
|
.probe = &probe,
|
|
.get_ds = &get_ds,
|
|
};
|