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.
20 static int pf_init(void);
21 static int pf_read(void);
22 static void submit_counter(const char *, const char *, counter_t, int);
24 char *pf_device = "/dev/pf";
29 struct pf_status status;
32 if ((pfdev = open(pf_device, O_RDONLY)) == -1) {
33 ERROR("unable to open %s", pf_device);
37 if (ioctl(pfdev, DIOCGETSTATUS, &status) == -1) {
38 ERROR("DIOCGETSTATUS: %i", pfdev);
53 struct pf_status status;
57 char *cnames[] = PFRES_NAMES;
58 char *lnames[] = LCNT_NAMES;
59 char *names[] = { "searches", "inserts", "removals" };
61 if ((pfdev = open(pf_device, O_RDONLY)) == -1) {
62 ERROR("unable to open %s", pf_device);
66 if (ioctl(pfdev, DIOCGETSTATUS, &status) == -1) {
67 ERROR("DIOCGETSTATUS: %i", pfdev);
74 for (i = 0; i < PFRES_MAX; i++)
75 submit_counter("pf_counters", cnames[i], status.counters[i], 0);
76 for (i = 0; i < LCNT_MAX; i++)
77 submit_counter("pf_limits", lnames[i], status.lcounters[i], 0);
78 for (i = 0; i < FCNT_MAX; i++)
79 submit_counter("pf_state", names[i], status.fcounters[i], 0);
80 for (i = 0; i < SCNT_MAX; i++)
81 submit_counter("pf_source", names[i], status.scounters[i], 0);
83 submit_counter("pf_states", "current", status.states, 1);
89 submit_counter(const char *type, const char *inst, counter_t val, int usegauge)
93 value_list_t vl = VALUE_LIST_INIT;
96 values[0].gauge = val;
98 values[0].counter = val;
102 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
103 sstrncpy (vl.plugin, "pf", sizeof (vl.plugin));
104 sstrncpy (vl.type, type, sizeof(vl.type));
105 sstrncpy (vl.type_instance, inst, sizeof(vl.type_instance));
106 plugin_dispatch_values(&vl);
108 printf("%s.%s: %lld\n", type, inst, val);
114 main(int argc, char *argv[])
123 void module_register(void) {
124 plugin_register_init("pf", pf_init);
125 plugin_register_read("pf", pf_read);