/*************************************************************************** * 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 #include #include #include "plugins.h" #define BUFSIZE 1024 struct sammler_plugin plugin; static char *ds_def[] = { "DS:entries:GAUGE:%d:0:U", "DS:searched:DERIVE:%d:0:U", "DS:found:DERIVE:%d:0:U", "DS:new:DERIVE:%d:0:U", "DS:invalid:DERIVE:%d:0:U", "DS:ignore:DERIVE:%d:0:U", "DS:delete:DERIVE:%d:0:U", "DS:delete_list:DERIVE:%d:0:U", "DS:insert:DERIVE:%d:0:U", "DS:insert_failed:DERIVE:%d:0:U", "DS:drop:DERIVE:%d:0:U", "DS:early_drop:DERIVE:%d:0:U", "DS:icmp_error:DERIVE:%d:0:U", "DS:expect_new:DERIVE:%d:0:U", "DS:expect_create:DERIVE:%d:0:U", "DS:expect_delete:DERIVE:%d:0:U", NULL }; static char ** get_ds(int ds_id) { return ds_def; } static void probe(void) { FILE *fp; char *buffer, *val[16], filename[16]; unsigned long long arr[16]; int i, cpu = 0; buffer = malloc(BUFSIZE); if (buffer == NULL) { log_print(LOG_WARN, "plugin ctstat: out of memory"); return; } fp = fopen("/proc/net/stat/ip_conntrack", "r"); if (fp == NULL) { log_print(LOG_WARN, "plugin ctstat"); free(buffer); return; } while (fgets(buffer, BUFSIZE, fp) != NULL) { if (!strncmp(buffer, "entries", 7)) continue; if (strsplit(buffer, val, 16) != 16) continue; for (i = 0; i < 16; i++) arr[i] = strtoll(val[i], NULL, 16); snprintf(filename, sizeof(filename), "ctstat-%d.rrd", cpu); 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); free(buffer); } struct sammler_plugin plugin = { .name = "ctstat", .version = 1, .probe = &probe, .get_ds = &get_ds, };