root/lib/Core/Iostat.pm

Revision 7c54048ca9a58d0809af322fa48bf5755ae76888, 4.6 kB (checked in by Jason Dixon <jdixon@omniti.com>, 4 years ago)

no-config support for Solaris, return metrics for all known disks

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@383 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
1 package Core::Iostat;
2
3 use strict;
4 use warnings;
5
6 use base 'Resmon::Module';
7
8 use Resmon::ExtComm qw(run_command cache_command);
9
10 =pod
11
12 =head1 NAME
13
14 Core::Iostat - Monitor disk I/O statistics using iostat
15
16 =head1 SYNOPSIS
17
18  Core::Iostat {
19      local : noop
20  }
21
22  Core::Iostat {
23      local : iostat_path => /usr/sbin/iostat
24  }
25
26 =head1 DESCRIPTION
27
28 This module monitors I/O statistics for a given disk.  It uses the running
29 total values reported by iostat.  The type and number of metrics returned
30 depend on the type returned by each platform's respective iostat command.
31 Each metric returned is prefixed with the name of the associated disk.
32
33 =head1 CONFIGURATION
34
35 =over
36
37 =item check_name
38
39 The check name is used for descriptive purposes only.
40 It is not used for anything functional.
41
42 =item iostat_path
43
44 Provide an alternate path to the iostat command (optional).
45
46 =back
47
48 =head1 METRICS
49
50 =over
51
52 =item reads_sec
53
54 Reads per second.
55
56 =item writes_sec
57
58 Writes per second.
59
60 =item kb_read_sec
61
62 Kilobytes read per second.
63
64 =item kb_write_sec
65
66 Kilobytes written per second.
67
68 =item lqueue_txn
69
70 Transaction queue length.
71
72 =item wait_txn
73
74 Average number of transactions waiting for service.
75
76 =item actv_txn
77
78 Average number of transactions actively being serviced.
79
80 =item rspt_txn
81
82 Average response time of transactions, in milliseconds.
83
84 =item wait_pct
85
86 Percent of time there are transactions waiting for service.
87
88 =item busy_pct
89
90 Percent of time the disk is busy.
91
92 =item soft_errors
93
94 Number of soft errors.
95
96 =item hard_errors
97
98 Number of hard errors.
99
100 =item txport_errors
101
102 Number of transport errors.
103
104 =item kb_xfrd
105
106 Kilobytes transferred (counter).
107
108 =item disk_xfrs
109
110 Disk transfers (counter).
111
112 =item busy_sec
113
114 Seconds spent in disk activity (counter).
115
116 =item xfrs_sec
117
118 Disk transfers per second.
119
120 =back
121
122 =cut
123
124 sub handler {
125     my $self = shift;
126     my $disk = $self->{'check_name'};
127     my $config = $self->{'config'};
128     my $iostat_path = $config->{'iostat_path'} || 'iostat';
129     my $osname = $^O;
130     my %metrics;
131
132     if ($osname eq 'solaris') {
133         my $output = run_command("$iostat_path -xe");
134         foreach (split(/\n/, $output)) {
135             next unless (/(\w+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*/);
136             $metrics{"${1}_reads_sec"} = [$2, 'n'];
137             $metrics{"${1}_writes_sec"} = [$3, 'n'];
138             $metrics{"${1}_kb_read_sec"} = [$4, 'n'];
139             $metrics{"${1}_kb_write_sec"} = [$5, 'n'];
140             $metrics{"${1}_wait_txn"} = [$6, 'n'];
141             $metrics{"${1}_actv_txn"} = [$7, 'n'];
142             $metrics{"${1}_rspt_txn"} = [$8, 'n'];
143             $metrics{"${1}_wait_pct"} = [$9, 'I'];
144             $metrics{"${1}_busy_pct"} = [$10, 'I'];
145             $metrics{"${1}_soft_errors"} = [$11, 'I'];
146             $metrics{"${1}_hard_errors"} = [$12, 'I'];
147             $metrics{"${1}_txport_errors"} = [$13, 'I'];
148             $metrics{"${1}_total_errors"} = [$14, 'I'];
149         }
150         if (keys %metrics) {
151             return \%metrics;
152         } else {
153             die "No disks found\n";
154         }
155     } elsif ($osname eq 'linux') {
156         my $output = run_command("$iostat_path $disk");
157         my ($line) = grep(/$disk\s*/, split(/\n/, $output));
158         if ($line =~ /^$disk\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+).*/) {
159             return {
160                 'xfrs_sec' => [$1, 'i'],
161                 'reads_sec' => [$2, 'i'],
162                 'writes_sec' => [$3, 'i']
163             };
164         } else {
165             die "Unable to find disk: $disk\n";
166         }
167     } elsif ($osname eq 'freebsd') {
168         my $output = run_command("$iostat_path -x $disk");
169         my ($line) = grep(/$disk\s*/, split(/\n/, $output));
170         if ($line =~ /^$disk\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\S+).*/) {
171             return {
172                 'reads_sec' => [$1, 'i'],
173                 'writes_sec' => [$2, 'i'],
174                 'kb_read_sec' => [$3, 'i'],
175                 'kb_write_sec' => [$4, 'i'],
176                 'lqueue_txn' => [$5, 'i'],
177                 'rspt_txn' => [$6, 'i']
178             };
179         } else {
180             die "Unable to find disk: $disk\n";
181         }
182     } elsif ($osname eq 'openbsd') {
183         my $output = run_command("$iostat_path -D -I $disk");
184         if ($output =~ /\s+$disk\s+\n\s+KB xfr time\s+\n\s+(\d+)\s+(\d+)\s+(\S+).*/) {
185             return {
186                 'kb_xfrd' => [$1, 'i'],
187                 'disk_xfrs' => [$2, 'i'],
188                 'busy_sec' => [$3, 'i']
189             };
190         } else {
191             die "Unable to find disk: $disk\n";
192         }
193     } else {
194         die "Unsupported platform: $osname\n";
195     }
196 };
197
198 1;
Note: See TracBrowser for help on using the browser.