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>
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-10-08 16:33:07 +02:00
|
|
|
#include "helper.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 15:23:09 +02:00
|
|
|
#define BUFSIZE 1024
|
|
|
|
|
2006-06-13 21:34:36 +02:00
|
|
|
struct sammler_plugin plugin;
|
2007-04-01 15:23:09 +02:00
|
|
|
static char *buffer;
|
2006-06-13 21:34:36 +02:00
|
|
|
|
2007-03-31 22:31:07 +02:00
|
|
|
static const char *ds_def = {
|
2006-09-30 17:10:32 +02:00
|
|
|
"DS:entries:GAUGE:15:0:U "
|
|
|
|
"DS:searched:DERIVE:15:0:U "
|
|
|
|
"DS:found:DERIVE:15:0:U "
|
|
|
|
"DS:new:DERIVE:15:0:U "
|
|
|
|
"DS:invalid:DERIVE:15:0:U "
|
|
|
|
"DS:ignore:DERIVE:15:0:U "
|
|
|
|
"DS:delete:DERIVE:15:0:U "
|
|
|
|
"DS:delete_list:DERIVE:15:0:U "
|
|
|
|
"DS:insert:DERIVE:15:0:U "
|
|
|
|
"DS:insert_failed:DERIVE:15:0:U "
|
|
|
|
"DS:drop:DERIVE:15:0:U "
|
|
|
|
"DS:early_drop:DERIVE:15:0:U "
|
|
|
|
"DS:icmp_error:DERIVE:15:0:U "
|
|
|
|
"DS:expect_new:DERIVE:15:0:U "
|
|
|
|
"DS:expect_create:DERIVE:15:0:U "
|
|
|
|
"DS:expect_delete:DERIVE: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;
|
|
|
|
}
|
|
|
|
|
2006-10-07 20:37:30 +02:00
|
|
|
static int probe(void)
|
2006-06-13 21:34:36 +02:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2006-10-07 20:37:30 +02:00
|
|
|
char *val[16], filename[16];
|
2006-06-13 21:34:36 +02:00
|
|
|
unsigned long long arr[16];
|
2006-06-22 20:33:30 +02:00
|
|
|
int i, len, cpu = 0;
|
2006-06-13 21:34:36 +02:00
|
|
|
|
|
|
|
fp = fopen("/proc/net/stat/ip_conntrack", "r");
|
|
|
|
if (fp == NULL) {
|
|
|
|
log_print(LOG_WARN, "plugin ctstat");
|
2006-10-07 20:37:30 +02:00
|
|
|
return -1;
|
2006-06-13 21:34:36 +02:00
|
|
|
}
|
|
|
|
|
2007-04-01 15:23:09 +02:00
|
|
|
while (fgets(buffer, BUFSIZE, fp) != NULL) {
|
|
|
|
if (!strncmp(buffer, "entries", 7))
|
2006-06-13 21:34:36 +02:00
|
|
|
continue;
|
|
|
|
|
2007-04-01 15:23:09 +02:00
|
|
|
if (strsplit(buffer, " \t\n", val, 16) != 16)
|
2006-06-13 21:34:36 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
arr[i] = strtoll(val[i], NULL, 16);
|
|
|
|
|
2006-06-22 20:33:30 +02:00
|
|
|
len = snprintf(filename, sizeof(filename), "ctstat-%d.rrd", cpu);
|
|
|
|
if (len < 0 || len >= sizeof(filename))
|
|
|
|
continue;
|
2006-06-13 21:34:36 +02:00
|
|
|
|
|
|
|
probe_submit(&plugin, filename, 0,
|
|
|
|
"%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
|
|
|
|
arr[0], arr[1], arr[2], arr[3],
|
|
|
|
arr[4], arr[5], arr[6], arr[7],
|
|
|
|
arr[8], arr[9], arr[10], arr[11],
|
|
|
|
arr[12], arr[13], arr[14], arr[15]);
|
|
|
|
|
|
|
|
cpu++;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
2006-10-07 20:37:30 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-01 15:23:09 +02:00
|
|
|
static int init(void)
|
|
|
|
{
|
|
|
|
buffer = malloc(BUFSIZE);
|
|
|
|
return (buffer == NULL) ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fini(void)
|
|
|
|
{
|
|
|
|
free(buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-13 21:34:36 +02:00
|
|
|
struct sammler_plugin plugin = {
|
|
|
|
.name = "ctstat",
|
2006-09-30 17:10:32 +02:00
|
|
|
.interval = 10,
|
2007-04-01 15:23:09 +02:00
|
|
|
.init = &init,
|
|
|
|
.fini = &fini,
|
2006-06-13 21:34:36 +02:00
|
|
|
.probe = &probe,
|
|
|
|
.get_ds = &get_ds,
|
|
|
|
};
|