Projet

Général

Profil

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

root / plugins / drbd / drbd-stat @ e5ce7492

Historique | Voir | Annoter | Télécharger (3,51 ko)

1 5b477ce9 Brent Clark
#!/usr/bin/perl
2
3
# http://www.drbd.org/users-guide/ch-admin.html#s-proc-drbd
4
5
use strict;
6
#use Data::Dumper;
7
8
my $file="/proc/drbd";
9
my $store = {};
10
my $temp;
11
12
&crunch;
13
&display;
14
15
sub display{
16
	if ($ARGV[0] and $ARGV[0] eq "config"){
17
		print "graph_title DRBD\n";
18
		print "graph_category DRBD\n";
19
		print "graph_info Graph DRBD\n";
20
		print "graph_vlabel Graph DRBD\n";
21
		#print "graph_scale no\n";
22
		print "graph_args --base 1024 --lower-limit 0\n";
23
		#print "graph_args --base 1000\n";
24
25
		foreach my $key ( keys %$store ){
26
			my $drbdname = 'drbd'.$key;
27
			print $drbdname."dr.label $drbdname Disk Read\n";
28
			print $drbdname."dw.label $drbdname Disk Write\n";
29
			print $drbdname."ns.label $drbdname Network Send\n";
30
			print $drbdname."nr.label $drbdname Network Receive\n";
31
		}
32
	}
33
34
35
#print Dumper \$store;
36
37
	foreach my $key ( keys %$store ){
38
		my $drbdname = 'drbd'.$key;
39
		print $drbdname."dw.value ".$store->{$key}->{'dw'}."\n";
40
		print $drbdname."dr.value ".$store->{$key}->{'dr'}."\n";
41
		print $drbdname."ns.value ".$store->{$key}->{'ns'}."\n";
42
		print $drbdname."nr.value ".$store->{$key}->{'nr'}."\n";
43
	}
44
}
45
46
sub crunch{
47
open (IN, $file ) || die "Could not open $file for reading: $!";
48
	while (<IN>){
49
		next if /version:|GIT-hash:/;
50
		chomp;
51
52
		my ($drbd) = $_ =~ /^\s+(\d):/;
53
		$temp = $drbd if $drbd =~ /\d/;
54
55
		if (/resync/){
56
			my ($hits) = $_ =~ /hits:(\d*)/;
57
			$store->{ $temp }->{'resync'}->{hits} = $hits if $hits ne undef;
58
59
			my ($misses) = $_ =~ /misses:(\d*)/;
60
			$store->{ $temp }->{'resync'}->{misses} = $misses if $misses ne undef;
61
62
			my ($starving) = $_ =~ /starving:(\d*)/;
63
			$store->{ $temp }->{'resync'}->{starving} = $starving if $starving ne undef;
64
65
			my ($dirty) = $_ =~ /dirty:(\d*)/;
66
			$store->{ $temp }->{'resync'}->{dirty} = $dirty if $dirty ne undef;
67
68
			my ($changed) = $_ =~ /changed:(\d*)/;
69
			$store->{ $temp }->{'resync'}->{changed} = $changed if $changed ne undef;
70
		}
71
72
		if (/act_log/){
73
			my ($hits) = $_ =~ /hits:(\d*)/;
74
			$store->{ $temp }->{'act_log'}->{hits} = $hits if $hits ne undef;
75
76
			my ($misses) = $_ =~ /misses:(\d*)/;
77
			$store->{ $temp }->{'act_log'}->{misses} = $misses if $misses ne undef;
78
79
			my ($starving) = $_ =~ /starving:(\d*)/;
80
			$store->{ $temp }->{'act_log'}->{starving} = $starving if $starving ne undef;
81
82
			my ($dirty) = $_ =~ /dirty:(\d*)/;
83
			$store->{ $temp }->{'act_log'}->{dirty} = $dirty if $dirty ne undef;
84
85
			my ($changed) = $_ =~ /changed:(\d*)/;
86
			$store->{ $temp }->{'act_log'}->{changed} = $changed if $changed ne undef;
87
		}
88
		
89
		my ($ns) = $_ =~ /ns:(\d*)/;
90
		$store->{ $temp }->{'ns'} = $ns if $ns ne undef;
91
92
		my ($nr) = $_ =~ /nr:(\d*)/;
93
		$store->{ $temp }->{'nr'} = $nr if $ns ne undef;
94
95
		my ($dw) = $_ =~ /dw:(\d*)/;
96
		$store->{ $temp }->{'dw'} = $dw if $dw ne undef;
97
98
		my ($dr) = $_ =~ /dr:(\d*)/;
99
		$store->{ $temp }->{'dr'} = $dr if $dr ne undef;
100
101
		my ($al) = $_ =~ /al:(\d*)/;
102
		$store->{ $temp }->{'al'} = $al if $dr ne undef;
103
104
		my ($bm) = $_ =~ /bm:(\d*)/;
105
		$store->{ $temp }->{'bm'} = $bm if $dr ne undef;
106
107
		my ($lo) = $_ =~ /lo:(\d*)/;
108
		$store->{ $temp }->{'lo'} = $lo if $dr ne undef;
109
110
		my ($pe) = $_ =~ /pe:(\d*)/;
111
		$store->{ $temp }->{'pe'} = $pe if $dr ne undef;
112
113
		my ($ua) = $_ =~ /ua:(\d*)/;
114
		$store->{ $temp }->{'ua'} = $ua if $dr ne undef;
115
116
		my ($ap) = $_ =~ /ap:(\d*)/;
117
		$store->{ $temp }->{'ap'} = $ap if $ap ne undef;
118
119
		my ($hits) = $_ =~ /hits:(\d*)/;
120
		$store->{ $temp }->{'hits'} = $hits if $hits ne undef;
121
122
		my ($used) = $_ =~ /used:(\d*\\\d*)\s/;
123
		$store->{ $temp }->{'used'} = $used if $used ne undef;
124
}
125
126
close (IN);
127
128
#print Dumper \$store;
129
130
}
131
132
exit 0;