Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / system / dar_vmstat @ e5ce7492

Historique | Voir | Annoter | Télécharger (2,23 ko)

1
#!/usr/bin/perl -w
2
# -*- perl -*-
3

    
4
=head1 NAME
5

    
6
dar_vmstat - Munin plugin to monitor darwin virtual memory usage.
7

    
8
=head1 APPLICABLE SYSTEMS
9

    
10
Should work on any darwin (Mac OS X) system with the 'vm_stat' command.
11

    
12
=head1 CONFIGURATION
13

    
14
None needed
15

    
16
=head1 INTERPRETATION
17

    
18
The plugin runs the vm_stat command a shows the results.  Consult the
19
vm_stat man page for more information on the output.
20

    
21
=head1 BUGS
22

    
23
None right now.
24

    
25
=head1 MAGIC MARKERS
26

    
27
  #%# family=auto
28
  #%# capabilities=autoconf
29

    
30
=head1 VERSION
31

    
32
  v.0.0.1
33

    
34
=head1 AUTHOR
35

    
36
Copyright (C) 2010.
37

    
38
Original version by J.T.Sage (at) gmail (dot) com.
39

    
40
=head1 LICENSE
41

    
42
GPLv2
43

    
44
=cut
45

    
46
use Munin::Plugin;
47

    
48
if ( defined($ARGV[0])) {
49
    if ($ARGV[0] eq 'autoconf') {
50
	$uname = `uname`;
51
	if ( not ( $uname =~ /Darwin/ ) ) { print "no (not a Darwin System)\n"; }
52
	else {
53
		if ( not -x "/usr/bin/vm_stat" ) { print "no (vm_stat not found)\n"; }
54
		else {
55
			print "yes\n";
56
		}
57
	}
58
	exit 0;
59
    }
60

    
61
    if ( $ARGV[0] eq "config" ) {
62
	print "graph_title Virtual Memory Statiscs\n";
63
	print "graph_args --base 1000 -l 0\n";
64
	print "graph_vlabel bytes\n";
65
	print "graph_scale yes\n";
66
	print "graph_category system\n";
67
	@vmstat = `vm_stat`;
68
	for ( $i = 1;  $i < $#vmstat; $i++ ) {
69
		$line = $vmstat[$i];
70
		$label = $line;
71
		$label =~ s/"//g;
72
		$label =~ s/(\w+)\:.+$/$1/;
73
		$label =~ s/\n//g;
74
		$name = $label;
75
		$name =~ tr/A-Z/a-z/;
76
		$name =~ s/[^A-Za-z0-9_]/_/g;
77
		if ( $name eq "pages_free" || $name eq "pages_active" || $name eq "pages_inactive" || $name eq "pages_speculative" || $name eq "pages_wired_down" ) {
78
			$label =~ s/Pages //;
79
			print $name, ".label ", $label, "\n";
80
			print $name, ".type GAUGE\n";
81
			print $name, ".cdef ", $name, ",4096,*\n";
82
		}
83
	}
84
	exit 0;
85
    }
86
}
87

    
88
@vmstat = `vm_stat`;
89
for ( $i = 1;  $i < $#vmstat; $i++ ) {
90
	$line = $vmstat[$i];
91
	$label = $line;
92
	$label =~ s/"//g;
93
	$label =~ s/(\w+)\:.+$/$1/;
94
	$label =~ s/\n//g;
95
	$name = $label;
96
	$name =~ tr/A-Z/a-z/;
97
	$name =~ s/[^A-Za-z0-9_]/_/g;
98
	$data = $line;
99
	$data =~ s/.+?(\d+)\./$1/;
100
	$data =~ s/\n//g;
101
	#$data = int(($data / 1000) + .5);
102
	if ( $name eq "pages_free" || $name eq "pages_active" || $name eq "pages_inactive" || $name eq "pages_speculative" || $name eq "pages_wired_down" ) {
103
		print $name, ".value ", $data, "\n";
104
	}
105

    
106
}
107

    
108

    
109

    
110
# vim:syntax=perl