X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpf.c;h=33e2d4b964c0ef8dc5d45058c383a5a7889dfd55;hb=22d0859f5c5c43adc8c58ff0dd40be79528681eb;hp=9b69fecfd88905d44467b4ae796f35731d17de1a;hpb=7a0995fb1e8355ef8e89f32d1d50f6382a6c66e8;p=collectd.git diff --git a/src/pf.c b/src/pf.c index 9b69fecf..33e2d4b9 100644 --- a/src/pf.c +++ b/src/pf.c @@ -21,41 +21,19 @@ static int pf_init(void); static int pf_read(void); static void submit_counter(const char *, const char *, counter_t); -void -submit_counter(const char *type, const char *inst, counter_t val) -{ -#ifndef TEST - value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; - - values[0].gauge = val; - - vl.values = values; - vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); - sstrncpy (vl.plugin, "pf", sizeof (vl.plugin)); - sstrncpy (vl.type, type, sizeof(vl.type)); - sstrncpy (vl.type_instance, inst, sizeof(vl.type_instance)); - plugin_dispatch_values(&vl); -#else - printf("%s.%s: %lld\n", type, inst, val); -#endif -} - - int pf_init(void) { struct pf_status status; - if ((pfdev = open(PF_SOCKET, O_RDWR)) == -1) { + if ((dev = open(PF_SOCKET, O_RDONLY)) == -1) { return (-1); } - if (ioctl(pfdev, DIOCGETSTATUS, &status) == -1) { + if (ioctl(dev, DIOCGETSTATUS, &status) == -1) { return (-1); } - close(pfdev); + close(dev); if (!status.running) return (-1); @@ -72,14 +50,14 @@ pf_read(void) char *lnames[] = LCNT_NAMES; char *names[] = { "searches", "inserts", "removals" }; - if ((pfdev = open(PF_SOCKET, O_RDWR)) == -1) { + if ((dev = open(PF_SOCKET, O_RDONLY)) == -1) { return (-1); } - if (ioctl(pfdev, DIOCGETSTATUS, &status) == -1) { + if (ioctl(dev, DIOCGETSTATUS, &status) == -1) { return (-1); } - close(pfdev); + close(dev); for (i = 0; i < PFRES_MAX; i++) submit_counter("pf_counters", cnames[i], status.counters[i]); for (i = 0; i < LCNT_MAX; i++) @@ -91,6 +69,27 @@ pf_read(void) return (0); } +void +submit_counter(const char *type, const char *inst, counter_t val) +{ +#ifndef TEST + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].counter = val; + + vl.values = values; + vl.values_len = 1; + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "pf", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof(vl.type)); + sstrncpy (vl.type_instance, inst, sizeof(vl.type_instance)); + plugin_dispatch_values(&vl); +#else + printf("%s.%s: %lld\n", type, inst, val); +#endif +} + #ifdef TEST int main(int argc, char *argv[])