2006-06-13 21:34:36 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* 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>
|
2007-04-01 15:45:31 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2006-06-13 21:34:36 +02:00
|
|
|
#include <mntent.h>
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
|
2007-04-01 15:45:31 +02:00
|
|
|
#include "logging.h"
|
2006-06-13 21:34:36 +02:00
|
|
|
#include "plugins.h"
|
2007-04-01 14:30:05 +02:00
|
|
|
#include "probe.h"
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
#define MAXFSNAME 16
|
|
|
|
|
2006-06-13 21:34:36 +02:00
|
|
|
struct sammler_plugin plugin;
|
|
|
|
|
2007-03-31 22:31:07 +02:00
|
|
|
static const char *ds_def = {
|
2006-09-30 17:10:32 +02:00
|
|
|
"DS:block_total:GAUGE:15:0:U "
|
|
|
|
"DS:block_free:GAUGE:15:0:U "
|
2006-06-13 21:34:36 +02:00
|
|
|
};
|
|
|
|
|
2007-03-31 22:31:07 +02:00
|
|
|
static const char * get_ds(int ds_id)
|
2006-06-13 21:34:36 +02:00
|
|
|
{
|
|
|
|
return ds_def;
|
|
|
|
}
|
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
static char * get_valid_fs(int *xcnt)
|
2006-06-13 21:34:36 +02:00
|
|
|
{
|
2007-04-01 16:51:39 +02:00
|
|
|
FILE *fp = fopen("/proc/filesystems", "r");
|
|
|
|
if (fp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
char buffer[64];
|
|
|
|
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
|
|
|
|
if (!strncmp(buffer, "nodev", 5))
|
|
|
|
continue;
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
cnt++;
|
2006-06-13 21:34:36 +02:00
|
|
|
}
|
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
char *valid_arr = malloc(cnt * MAXFSNAME);
|
|
|
|
if (valid_arr == NULL)
|
|
|
|
return NULL;
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
rewind(fp);
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
int i = 0;
|
|
|
|
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
|
|
|
|
if (!strncmp(buffer, "nodev", 5))
|
2006-06-13 21:34:36 +02:00
|
|
|
continue;
|
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
char *end = memccpy(valid_arr + (i++ * MAXFSNAME), buffer +1, '\n', MAXFSNAME);
|
|
|
|
*(end -1) = '\0';
|
|
|
|
}
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
fclose(fp);
|
|
|
|
*xcnt = cnt;
|
|
|
|
return valid_arr;
|
|
|
|
}
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
static int probe(void)
|
|
|
|
{
|
|
|
|
FILE *fp = setmntent("/etc/mtab", "r");
|
|
|
|
if (fp == NULL) {
|
|
|
|
log_print(LOG_WARN, "plugin mount");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
int cnt;
|
|
|
|
char *valid_arr = get_valid_fs(&cnt);
|
|
|
|
if (valid_arr == NULL) {
|
|
|
|
log_print(LOG_WARN, "plugin mount");
|
|
|
|
endmntent(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mntent *mnt;
|
|
|
|
while ((mnt = getmntent(fp)) != NULL) {
|
|
|
|
|
|
|
|
int i, valid = 0;
|
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
if (strncmp(mnt->mnt_type, valid_arr + (i * MAXFSNAME), MAXFSNAME) == 0)
|
|
|
|
valid = 1;
|
|
|
|
|
|
|
|
if (valid == 0)
|
2006-07-27 16:12:34 +02:00
|
|
|
continue;
|
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
struct statfs fs;
|
2006-06-13 21:34:36 +02:00
|
|
|
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;
|
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
char *slash = mnt->mnt_fsname;
|
2006-06-13 21:34:36 +02:00
|
|
|
while (slash && (slash = strchr(slash, '/'))) {
|
|
|
|
slash = strchr(slash, '/');
|
|
|
|
*slash++ = '_';
|
|
|
|
}
|
|
|
|
|
2007-04-01 16:51:39 +02:00
|
|
|
char filename[64];
|
|
|
|
int len = snprintf(filename, sizeof(filename), "mount%s.rrd", mnt->mnt_fsname);
|
2006-06-22 20:33:30 +02:00
|
|
|
if (len < 0 || len >= sizeof(filename)) {
|
2006-06-13 21:34:36 +02:00
|
|
|
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));
|
|
|
|
}
|
2007-04-01 16:51:39 +02:00
|
|
|
|
|
|
|
free(valid_arr);
|
2006-06-13 21:34:36 +02:00
|
|
|
endmntent(fp);
|
2006-10-07 20:37:30 +02:00
|
|
|
return 0;
|
2006-06-13 21:34:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sammler_plugin plugin = {
|
|
|
|
.name = "mount",
|
2006-09-30 17:10:32 +02:00
|
|
|
.interval = 10,
|
2006-06-13 21:34:36 +02:00
|
|
|
.probe = &probe,
|
|
|
|
.get_ds = &get_ds,
|
|
|
|
};
|