1 /**
2 * collectd - src/swap.c
3 * Copyright (C) 2005-2010 Florian octo Forster
4 * Copyright (C) 2009 Stefan Völkel
5 * Copyright (C) 2009 Manuel Sanmartin
6 * Copyright (C) 2010 Aurélien Reynaud
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; only version 2 of the License is applicable.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * Authors:
22 * Florian octo Forster <octo at collectd.org>
23 * Manuel Sanmartin
24 * Aurélien Reynaud <collectd at wattapower.net>
25 **/
27 #if HAVE_CONFIG_H
28 # include "config.h"
29 # undef HAVE_CONFIG_H
30 #endif
31 /* avoid swap.h error "Cannot use swapctl in the large files compilation environment" */
32 #if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64
33 # undef _FILE_OFFSET_BITS
34 # undef _LARGEFILE64_SOURCE
35 #endif
37 #include "collectd.h"
38 #include "common.h"
39 #include "plugin.h"
41 #if HAVE_SYS_SWAP_H
42 # include <sys/swap.h>
43 #endif
44 #if HAVE_VM_ANON_H
45 # include <vm/anon.h>
46 #endif
47 #if HAVE_SYS_PARAM_H
48 # include <sys/param.h>
49 #endif
50 #if HAVE_SYS_SYSCTL_H
51 # include <sys/sysctl.h>
52 #endif
53 #if HAVE_SYS_DKSTAT_H
54 # include <sys/dkstat.h>
55 #endif
56 #if HAVE_KVM_H
57 # include <kvm.h>
58 #endif
60 #if HAVE_STATGRAB_H
61 # include <statgrab.h>
62 #endif
64 #if HAVE_PERFSTAT
65 # include <sys/protosw.h>
66 # include <libperfstat.h>
67 #endif
69 #undef MAX
70 #define MAX(x,y) ((x) > (y) ? (x) : (y))
72 #if KERNEL_LINUX
73 # define SWAP_HAVE_CONFIG 1
74 /* No global variables */
75 /* #endif KERNEL_LINUX */
77 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
78 # define SWAP_HAVE_CONFIG 1
79 static derive_t pagesize;
80 /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
82 #elif defined(VM_SWAPUSAGE)
83 /* No global variables */
84 /* #endif defined(VM_SWAPUSAGE) */
86 #elif HAVE_LIBKVM_GETSWAPINFO
87 static kvm_t *kvm_obj = NULL;
88 int kvm_pagesize;
89 /* #endif HAVE_LIBKVM_GETSWAPINFO */
91 #elif HAVE_LIBSTATGRAB
92 /* No global variables */
93 /* #endif HAVE_LIBSTATGRAB */
95 #elif HAVE_PERFSTAT
96 static int pagesize;
97 static perfstat_memory_total_t pmemory;
98 /*# endif HAVE_PERFSTAT */
100 #else
101 # error "No applicable input method."
102 #endif /* HAVE_LIBSTATGRAB */
104 #if SWAP_HAVE_CONFIG
105 static const char *config_keys[] =
106 {
107 "ReportByDevice"
108 };
109 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
111 static _Bool report_by_device = 0;
113 static int swap_config (const char *key, const char *value) /* {{{ */
114 {
115 if (strcasecmp ("ReportByDevice", key) == 0)
116 {
117 if (IS_TRUE (value))
118 report_by_device = 1;
119 else
120 report_by_device = 0;
121 }
122 else
123 {
124 return (-1);
125 }
127 return (0);
128 } /* }}} int swap_config */
129 #endif /* SWAP_HAVE_CONFIG */
131 static int swap_init (void) /* {{{ */
132 {
133 #if KERNEL_LINUX
134 /* No init stuff */
135 /* #endif KERNEL_LINUX */
137 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
138 /* getpagesize(3C) tells me this does not fail.. */
139 pagesize = (derive_t) getpagesize ();
140 /* #endif HAVE_SWAPCTL */
142 #elif defined(VM_SWAPUSAGE)
143 /* No init stuff */
144 /* #endif defined(VM_SWAPUSAGE) */
146 #elif HAVE_LIBKVM_GETSWAPINFO
147 if (kvm_obj != NULL)
148 {
149 kvm_close (kvm_obj);
150 kvm_obj = NULL;
151 }
153 kvm_pagesize = getpagesize ();
155 if ((kvm_obj = kvm_open (NULL, /* execfile */
156 NULL, /* corefile */
157 NULL, /* swapfile */
158 O_RDONLY, /* flags */
159 NULL)) /* errstr */
160 == NULL)
161 {
162 ERROR ("swap plugin: kvm_open failed.");
163 return (-1);
164 }
165 /* #endif HAVE_LIBKVM_GETSWAPINFO */
167 #elif HAVE_LIBSTATGRAB
168 /* No init stuff */
169 /* #endif HAVE_LIBSTATGRAB */
171 #elif HAVE_PERFSTAT
172 pagesize = getpagesize();
173 #endif /* HAVE_PERFSTAT */
175 return (0);
176 } /* }}} int swap_init */
178 static void swap_submit (const char *plugin_instance, /* {{{ */
179 const char *type, const char *type_instance,
180 value_t value)
181 {
182 value_list_t vl = VALUE_LIST_INIT;
184 assert (type != NULL);
186 vl.values = &value;
187 vl.values_len = 1;
188 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
189 sstrncpy (vl.plugin, "swap", sizeof (vl.plugin));
190 if (plugin_instance != NULL)
191 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
192 sstrncpy (vl.type, type, sizeof (vl.type));
193 if (type_instance != NULL)
194 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
196 plugin_dispatch_values (&vl);
197 } /* }}} void swap_submit_inst */
199 static void swap_submit_gauge (const char *plugin_instance, /* {{{ */
200 const char *type_instance, gauge_t value)
201 {
202 value_t v;
204 v.gauge = value;
205 swap_submit (plugin_instance, "swap", type_instance, v);
206 } /* }}} void swap_submit_gauge */
208 static void swap_submit_derive (const char *plugin_instance, /* {{{ */
209 const char *type_instance, derive_t value)
210 {
211 value_t v;
213 v.derive = value;
214 swap_submit (plugin_instance, "swap_io", type_instance, v);
215 } /* }}} void swap_submit_derive */
218 #if KERNEL_LINUX
219 static int swap_read_separate (void) /* {{{ */
220 {
221 FILE *fh;
222 char buffer[1024];
224 fh = fopen ("/proc/swaps", "r");
225 if (fh == NULL)
226 {
227 char errbuf[1024];
228 WARNING ("swap plugin: fopen (/proc/swaps) failed: %s",
229 sstrerror (errno, errbuf, sizeof (errbuf)));
230 return (-1);
231 }
233 while (fgets (buffer, sizeof (buffer), fh) != NULL)
234 {
235 char *fields[8];
236 int numfields;
237 char *endptr;
239 char path[PATH_MAX];
240 gauge_t size;
241 gauge_t used;
242 gauge_t free;
244 numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
245 if (numfields != 5)
246 continue;
248 sstrncpy (path, fields[0], sizeof (path));
249 escape_slashes (path, sizeof (path));
251 errno = 0;
252 endptr = NULL;
253 size = strtod (fields[2], &endptr);
254 if ((endptr == fields[2]) || (errno != 0))
255 continue;
257 errno = 0;
258 endptr = NULL;
259 used = strtod (fields[3], &endptr);
260 if ((endptr == fields[3]) || (errno != 0))
261 continue;
263 if (size < used)
264 continue;
266 free = size - used;
268 swap_submit_gauge (path, "used", used);
269 swap_submit_gauge (path, "free", free);
270 }
272 fclose (fh);
274 return (0);
275 } /* }}} int swap_read_separate */
277 static int swap_read_combined (void) /* {{{ */
278 {
279 FILE *fh;
280 char buffer[1024];
282 uint8_t have_data = 0;
283 gauge_t swap_used = 0.0;
284 gauge_t swap_cached = 0.0;
285 gauge_t swap_free = 0.0;
286 gauge_t swap_total = 0.0;
288 fh = fopen ("/proc/meminfo", "r");
289 if (fh == NULL)
290 {
291 char errbuf[1024];
292 WARNING ("swap plugin: fopen (/proc/meminfo) failed: %s",
293 sstrerror (errno, errbuf, sizeof (errbuf)));
294 return (-1);
295 }
297 while (fgets (buffer, sizeof (buffer), fh) != NULL)
298 {
299 char *fields[8];
300 int numfields;
302 numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
303 if (numfields < 2)
304 continue;
306 if (strcasecmp (fields[0], "SwapTotal:") == 0)
307 {
308 swap_total = strtod (fields[1], /* endptr = */ NULL);
309 have_data |= 0x01;
310 }
311 else if (strcasecmp (fields[0], "SwapFree:") == 0)
312 {
313 swap_free = strtod (fields[1], /* endptr = */ NULL);
314 have_data |= 0x02;
315 }
316 else if (strcasecmp (fields[0], "SwapCached:") == 0)
317 {
318 swap_cached = strtod (fields[1], /* endptr = */ NULL);
319 have_data |= 0x04;
320 }
321 }
323 fclose (fh);
325 if (have_data != 0x07)
326 return (ENOENT);
328 if (isnan (swap_total)
329 || (swap_total <= 0.0)
330 || ((swap_free + swap_cached) > swap_total))
331 return (EINVAL);
333 swap_used = swap_total - (swap_free + swap_cached);
335 swap_submit_gauge (NULL, "used", 1024.0 * swap_used);
336 swap_submit_gauge (NULL, "free", 1024.0 * swap_free);
337 swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
339 return (0);
340 } /* }}} int swap_read_combined */
342 static int swap_read_io (void) /* {{{ */
343 {
344 FILE *fh;
345 char buffer[1024];
347 _Bool old_kernel = 0;
349 uint8_t have_data = 0;
350 derive_t swap_in = 0;
351 derive_t swap_out = 0;
353 fh = fopen ("/proc/vmstat", "r");
354 if (fh == NULL)
355 {
356 /* /proc/vmstat does not exist in kernels <2.6 */
357 fh = fopen ("/proc/stat", "r");
358 if (fh == NULL)
359 {
360 char errbuf[1024];
361 WARNING ("swap: fopen: %s",
362 sstrerror (errno, errbuf, sizeof (errbuf)));
363 return (-1);
364 }
365 else
366 old_kernel = 1;
367 }
369 while (fgets (buffer, sizeof (buffer), fh) != NULL)
370 {
371 char *fields[8];
372 int numfields;
374 numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
376 if (!old_kernel)
377 {
378 if (numfields != 2)
379 continue;
381 if (strcasecmp ("pswpin", fields[0]) == 0)
382 {
383 strtoderive (fields[1], &swap_in);
384 have_data |= 0x01;
385 }
386 else if (strcasecmp ("pswpout", fields[0]) == 0)
387 {
388 strtoderive (fields[1], &swap_out);
389 have_data |= 0x02;
390 }
391 }
392 else /* if (old_kernel) */
393 {
394 if (numfields != 3)
395 continue;
397 if (strcasecmp ("page", fields[0]) == 0)
398 {
399 strtoderive (fields[1], &swap_in);
400 strtoderive (fields[2], &swap_out);
401 }
402 }
403 } /* while (fgets) */
405 fclose (fh);
407 if (have_data != 0x03)
408 return (ENOENT);
410 swap_submit_derive (NULL, "in", swap_in);
411 swap_submit_derive (NULL, "out", swap_out);
413 return (0);
414 } /* }}} int swap_read_io */
416 static int swap_read (void) /* {{{ */
417 {
418 if (report_by_device)
419 swap_read_separate ();
420 else
421 swap_read_combined ();
423 swap_read_io ();
425 return (0);
426 } /* }}} int swap_read */
427 /* #endif KERNEL_LINUX */
429 /*
430 * Under Solaris, two mechanisms can be used to read swap statistics, swapctl
431 * and kstat. The former reads physical space used on a device, the latter
432 * reports the view from the virtual memory system. It was decided that the
433 * kstat-based information should be moved to the "vmem" plugin, but nobody
434 * with enough Solaris experience was available at that time to do this. The
435 * code below is still there for your reference but it won't be activated in
436 * *this* plugin again. --octo
437 */
438 #elif 0 && HAVE_LIBKSTAT
439 /* kstat-based read function */
440 static int swap_read_kstat (void) /* {{{ */
441 {
442 derive_t swap_alloc;
443 derive_t swap_resv;
444 derive_t swap_avail;
446 struct anoninfo ai;
448 if (swapctl (SC_AINFO, &ai) == -1)
449 {
450 char errbuf[1024];
451 ERROR ("swap plugin: swapctl failed: %s",
452 sstrerror (errno, errbuf, sizeof (errbuf)));
453 return (-1);
454 }
456 /*
457 * Calculations from:
458 * http://cvs.opensolaris.org/source/xref/on/usr/src/cmd/swap/swap.c
459 * Also see:
460 * http://www.itworld.com/Comp/2377/UIR980701perf/ (outdated?)
461 * /usr/include/vm/anon.h
462 *
463 * In short, swap -s shows: allocated + reserved = used, available
464 *
465 * However, Solaris does not allow to allocated/reserved more than the
466 * available swap (physical memory + disk swap), so the pedant may
467 * prefer: allocated + unallocated = reserved, available
468 *
469 * We map the above to: used + resv = n/a, free
470 *
471 * Does your brain hurt yet? - Christophe Kalt
472 *
473 * Oh, and in case you wonder,
474 * swap_alloc = pagesize * ( ai.ani_max - ai.ani_free );
475 * can suffer from a 32bit overflow.
476 */
477 swap_alloc = (derive_t) ((ai.ani_max - ai.ani_free) * pagesize);
478 swap_resv = (derive_t) ((ai.ani_resv + ai.ani_free - ai.ani_max)
479 * pagesize);
480 swap_avail = (derive_t) ((ai.ani_max - ai.ani_resv) * pagesize);
482 swap_submit_gauge (NULL, "used", swap_alloc);
483 swap_submit_gauge (NULL, "free", swap_avail);
484 swap_submit_gauge (NULL, "reserved", swap_resv);
486 return (0);
487 } /* }}} int swap_read_kstat */
488 /* #endif 0 && HAVE_LIBKSTAT */
490 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
491 /* swapctl-based read function */
492 static int swap_read (void) /* {{{ */
493 {
494 swaptbl_t *s;
495 char *s_paths;
496 int swap_num;
497 int status;
498 int i;
500 derive_t avail = 0;
501 derive_t total = 0;
503 swap_num = swapctl (SC_GETNSWP, NULL);
504 if (swap_num < 0)
505 {
506 ERROR ("swap plugin: swapctl (SC_GETNSWP) failed with status %i.",
507 swap_num);
508 return (-1);
509 }
510 else if (swap_num == 0)
511 return (0);
513 /* Allocate and initialize the swaptbl_t structure */
514 s = (swaptbl_t *) smalloc (swap_num * sizeof (swapent_t) + sizeof (struct swaptable));
515 if (s == NULL)
516 {
517 ERROR ("swap plugin: smalloc failed.");
518 return (-1);
519 }
521 /* Memory to store the path names. We only use these paths when the
522 * separate option has been configured, but it's easier to just
523 * allocate enough memory in any case. */
524 s_paths = calloc (swap_num, PATH_MAX);
525 if (s_paths == NULL)
526 {
527 ERROR ("swap plugin: malloc failed.");
528 sfree (s);
529 return (-1);
530 }
531 for (i = 0; i < swap_num; i++)
532 s->swt_ent[i].ste_path = s_paths + (i * PATH_MAX);
533 s->swt_n = swap_num;
535 status = swapctl (SC_LIST, s);
536 if (status < 0)
537 {
538 char errbuf[1024];
539 ERROR ("swap plugin: swapctl (SC_LIST) failed: %s",
540 sstrerror (errno, errbuf, sizeof (errbuf)));
541 sfree (s_paths);
542 sfree (s);
543 return (-1);
544 }
545 else if (swap_num < status)
546 {
547 /* more elements returned than requested */
548 ERROR ("swap plugin: I allocated memory for %i structure%s, "
549 "but swapctl(2) claims to have returned %i. "
550 "I'm confused and will give up.",
551 swap_num, (swap_num == 1) ? "" : "s",
552 status);
553 sfree (s_paths);
554 sfree (s);
555 return (-1);
556 }
557 else if (swap_num > status)
558 /* less elements returned than requested */
559 swap_num = status;
561 for (i = 0; i < swap_num; i++)
562 {
563 char path[PATH_MAX];
564 derive_t this_total;
565 derive_t this_avail;
567 if ((s->swt_ent[i].ste_flags & ST_INDEL) != 0)
568 continue;
570 this_total = ((derive_t) s->swt_ent[i].ste_pages) * pagesize;
571 this_avail = ((derive_t) s->swt_ent[i].ste_free) * pagesize;
573 /* Shortcut for the "combined" setting (default) */
574 if (!report_by_device)
575 {
576 avail += this_avail;
577 total += this_total;
578 continue;
579 }
581 sstrncpy (path, s->swt_ent[i].ste_path, sizeof (path));
582 escape_slashes (path, sizeof (path));
584 swap_submit_gauge (path, "used", (gauge_t) (this_total - this_avail));
585 swap_submit_gauge (path, "free", (gauge_t) this_avail);
586 } /* for (swap_num) */
588 if (total < avail)
589 {
590 ERROR ("swap plugin: Total swap space (%"PRIi64") "
591 "is less than free swap space (%"PRIi64").",
592 total, avail);
593 sfree (s_paths);
594 sfree (s);
595 return (-1);
596 }
598 /* If the "separate" option was specified (report_by_device == 2), all
599 * values have already been dispatched from within the loop. */
600 if (!report_by_device)
601 {
602 swap_submit_gauge (NULL, "used", (gauge_t) (total - avail));
603 swap_submit_gauge (NULL, "free", (gauge_t) avail);
604 }
606 sfree (s_paths);
607 sfree (s);
608 return (0);
609 } /* }}} int swap_read */
610 /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
612 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS
613 static int swap_read (void) /* {{{ */
614 {
615 struct swapent *swap_entries;
616 int swap_num;
617 int status;
618 int i;
620 derive_t used = 0;
621 derive_t total = 0;
623 swap_num = swapctl (SWAP_NSWAP, NULL, 0);
624 if (swap_num < 0)
625 {
626 ERROR ("swap plugin: swapctl (SWAP_NSWAP) failed with status %i.",
627 swap_num);
628 return (-1);
629 }
630 else if (swap_num == 0)
631 return (0);
633 swap_entries = calloc (swap_num, sizeof (*swap_entries));
634 if (swap_entries == NULL)
635 {
636 ERROR ("swap plugin: calloc failed.");
637 return (-1);
638 }
640 status = swapctl (SWAP_STATS, swap_entries, swap_num);
641 if (status != swap_num)
642 {
643 ERROR ("swap plugin: swapctl (SWAP_STATS) failed with status %i.",
644 status);
645 sfree (swap_entries);
646 return (-1);
647 }
649 #if defined(DEV_BSIZE) && (DEV_BSIZE > 0)
650 # define C_SWAP_BLOCK_SIZE ((derive_t) DEV_BSIZE)
651 #else
652 # define C_SWAP_BLOCK_SIZE ((derive_t) 512)
653 #endif
655 for (i = 0; i < swap_num; i++)
656 {
657 if ((swap_entries[i].se_flags & SWF_ENABLE) == 0)
658 continue;
660 used += ((derive_t) swap_entries[i].se_inuse)
661 * C_SWAP_BLOCK_SIZE;
662 total += ((derive_t) swap_entries[i].se_nblks)
663 * C_SWAP_BLOCK_SIZE;
664 }
666 if (total < used)
667 {
668 ERROR ("swap plugin: Total swap space (%"PRIu64") "
669 "is less than used swap space (%"PRIu64").",
670 total, used);
671 return (-1);
672 }
674 swap_submit_gauge (NULL, "used", (gauge_t) used);
675 swap_submit_gauge (NULL, "free", (gauge_t) (total - used));
677 sfree (swap_entries);
679 return (0);
680 } /* }}} int swap_read */
681 /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS */
683 #elif defined(VM_SWAPUSAGE)
684 static int swap_read (void) /* {{{ */
685 {
686 int mib[3];
687 size_t mib_len;
688 struct xsw_usage sw_usage;
689 size_t sw_usage_len;
691 mib_len = 2;
692 mib[0] = CTL_VM;
693 mib[1] = VM_SWAPUSAGE;
695 sw_usage_len = sizeof (struct xsw_usage);
697 if (sysctl (mib, mib_len, &sw_usage, &sw_usage_len, NULL, 0) != 0)
698 return (-1);
700 /* The returned values are bytes. */
701 swap_submit_gauge (NULL, "used", (gauge_t) sw_usage.xsu_used);
702 swap_submit_gauge (NULL, "free", (gauge_t) sw_usage.xsu_avail);
704 return (0);
705 } /* }}} int swap_read */
706 /* #endif VM_SWAPUSAGE */
708 #elif HAVE_LIBKVM_GETSWAPINFO
709 static int swap_read (void) /* {{{ */
710 {
711 struct kvm_swap data_s;
712 int status;
714 derive_t used;
715 derive_t free;
716 derive_t total;
718 if (kvm_obj == NULL)
719 return (-1);
721 /* only one structure => only get the grand total, no details */
722 status = kvm_getswapinfo (kvm_obj, &data_s, 1, 0);
723 if (status == -1)
724 return (-1);
726 total = (derive_t) data_s.ksw_total;
727 used = (derive_t) data_s.ksw_used;
729 total *= (derive_t) kvm_pagesize;
730 used *= (derive_t) kvm_pagesize;
732 free = total - used;
734 swap_submit_gauge (NULL, "used", (gauge_t) used);
735 swap_submit_gauge (NULL, "free", (gauge_t) free);
737 return (0);
738 } /* }}} int swap_read */
739 /* #endif HAVE_LIBKVM_GETSWAPINFO */
741 #elif HAVE_LIBSTATGRAB
742 static int swap_read (void) /* {{{ */
743 {
744 sg_swap_stats *swap;
746 swap = sg_get_swap_stats ();
748 if (swap == NULL)
749 return (-1);
751 swap_submit_gauge (NULL, "used", (gauge_t) swap->used);
752 swap_submit_gauge (NULL, "free", (gauge_t) swap->free);
754 return (0);
755 } /* }}} int swap_read */
756 /* #endif HAVE_LIBSTATGRAB */
758 #elif HAVE_PERFSTAT
759 static int swap_read (void) /* {{{ */
760 {
761 if(perfstat_memory_total(NULL, &pmemory, sizeof(perfstat_memory_total_t), 1) < 0)
762 {
763 char errbuf[1024];
764 WARNING ("memory plugin: perfstat_memory_total failed: %s",
765 sstrerror (errno, errbuf, sizeof (errbuf)));
766 return (-1);
767 }
768 swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
769 swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
771 return (0);
772 } /* }}} int swap_read */
773 #endif /* HAVE_PERFSTAT */
775 void module_register (void)
776 {
777 #if SWAP_HAVE_CONFIG
778 plugin_register_config ("swap", swap_config, config_keys, config_keys_num);
779 #endif
780 plugin_register_init ("swap", swap_init);
781 plugin_register_read ("swap", swap_read);
782 } /* void module_register */
784 /* vim: set fdm=marker : */