2 * Copyright (c) 2010 Pierre-Yves Ritschard <pyr@openbsd.org>
3 * Copyright (c) 2011 Stefan Rinkes <stefan.rinkes@gmail.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include <sys/socket.h>
23 #include <net/pfvar.h>
38 #include "configfile.h"
41 typedef u_int64_t counter_t;
44 #define PF_SOCKET "/dev/pf"
50 static struct pfdata pd;
52 static int pf_init(void);
53 static int pf_read(void);
54 static void submit_counter(const char *, const char *, counter_t);
57 submit_counter(const char *type, const char *inst, counter_t val)
61 value_list_t vl = VALUE_LIST_INIT;
63 values[0].gauge = val;
67 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
68 sstrncpy (vl.plugin, "pf", sizeof (vl.plugin));
69 sstrncpy (vl.type, type, sizeof(vl.type));
70 sstrncpy (vl.type_instance, inst, sizeof(vl.type_instance));
71 plugin_dispatch_values(&vl);
73 printf("%s.%s: %lld\n", type, inst, val);
81 struct pf_status status;
83 memset(&pd, '\0', sizeof(pd));
85 if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) {
88 if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) {
103 struct pf_status status;
105 char *cnames[] = PFRES_NAMES;
106 char *lnames[] = LCNT_NAMES;
107 char *names[] = { "searches", "inserts", "removals" };
109 if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) {
112 if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) {
117 for (i = 0; i < PFRES_MAX; i++)
118 submit_counter("pf_counters", cnames[i], status.counters[i]);
119 for (i = 0; i < LCNT_MAX; i++)
120 submit_counter("pf_limits", lnames[i], status.lcounters[i]);
121 for (i = 0; i < FCNT_MAX; i++)
122 submit_counter("pf_state", names[i], status.fcounters[i]);
123 for (i = 0; i < SCNT_MAX; i++)
124 submit_counter("pf_source", names[i], status.scounters[i]);
130 main(int argc, char *argv[])
139 void module_register(void) {
140 plugin_register_init("pf", pf_init);
141 plugin_register_read("pf", pf_read);