Debian Codegraph @

src/network/juniper/trapeze/snmp/mode/memory.pm

raw
1 #
2 # Copyright 2015 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package network::juniper::trapeze::snmp::mode::memory;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_output {
29 my ($self, %options) = @_;
30
31 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
32 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
33 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
34
35 my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
36 $total_size_value . " " . $total_size_unit,
37 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
38 $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used});
39 return $msg;
40 }
41
42 sub set_counters {
43 my ($self, %options) = @_;
44
45 $self->{maps_counters_type} = [
46 { name => 'memory', type => 0, cb_prefix_output => 'prefix_memory_output' },
47 { name => 'flash', type => 0, cb_prefix_output => 'prefix_flash_output' }
48 ];
49
50 $self->{maps_counters}->{memory} = [
51 { label => 'memory', set => {
52 key_values => [ { name => 'prct_used'}, { name => 'used' }, { name => 'free' }, { name => 'total' } ],
53 closure_custom_output => $self->can('custom_usage_output'),
54 threshold_use => 'prct_used',
55 perfdatas => [
56 { label => 'memory', value => 'used', template => '%.2f', threshold_total => 'total', cast_int => 1,
57 min => 0, max => 'total', unit => 'B' },
58 ],
59 }
60 },
61 ];
62 $self->{maps_counters}->{flash} = [
63 { label => 'flash', set => {
64 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'total' } ],
65 closure_custom_output => $self->can('custom_usage_output'),
66 threshold_use => 'prct_used',
67 perfdatas => [
68 { label => 'flash', value => 'used', template => '%.2f', threshold_total => 'total', cast_int => 1,
69 min => 0, max => 'total', unit => 'B' },
70 ],
71 }
72 },
73 ];
74 }
75
76 sub prefix_memory_output {
77 my ($self, %options) = @_;
78
79 return "Memory ";
80 }
81
82 sub prefix_flash_output {
83 my ($self, %options) = @_;
84
85 return "Flash ";
86 }
87
88 sub new {
89 my ($class, %options) = @_;
90 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
91 bless $self, $class;
92
93 $options{options}->add_options(arguments =>
94 {
95 });
96
97 return $self;
98 }
99
100 sub manage_selection {
101 my ($self, %options) = @_;
102
103 my ($total_bytes, $used_bytes, $free_bytes);
104
105 # TRAPEZE-NETWORKS-SYSTEM-MIB
106 my $oid_trpzSysFlashMemoryUsedBytes = '.1.3.6.1.4.1.14525.4.8.1.1.3.0';
107 my $oid_trpzSysFlashMemoryTotalBytes = '.1.3.6.1.4.1.14525.4.8.1.1.4.0';
108 my $oid_trpzSysCpuMemoryInstantUsage = '.1.3.6.1.4.1.14525.4.8.1.1.12.1.0';
109 my $oid_trpzSysCpuMemoryUsedBytes = '.1.3.6.1.4.1.14525.4.8.1.1.1.0';
110 my $oid_trpzSysCpuMemoryTotalBytes = '.1.3.6.1.4.1.14525.4.8.1.1.2.0';
111 my $oid_trpzSysCpuMemorySize = '.1.3.6.1.4.1.14525.4.8.1.1.6.0';
112
113 my $results = $options{snmp}->get_leef(oids => [$oid_trpzSysFlashMemoryUsedBytes, $oid_trpzSysFlashMemoryTotalBytes, $oid_trpzSysCpuMemoryUsedBytes,
114 $oid_trpzSysCpuMemoryInstantUsage, $oid_trpzSysCpuMemorySize, $oid_trpzSysCpuMemoryTotalBytes ],
115 nothing_quit => 1);
116
117 if (defined($results->{$oid_trpzSysCpuMemorySize}) || $results->{$oid_trpzSysCpuMemorySize} != 0) {
118 $total_bytes = $results->{$oid_trpzSysCpuMemorySize} * 1024;
119 $used_bytes = $results->{$oid_trpzSysCpuMemoryInstantUsage} * 1024;
120 $free_bytes = $total_bytes - $used_bytes;
121 } else {
122 $total_bytes = $results->{$oid_trpzSysCpuMemoryTotalBytes};
123 $used_bytes = $results->{$oid_trpzSysCpuMemoryUsedBytes};
124 $free_bytes = $total_bytes - $used_bytes;
125 }
126
127 my $free_bytes_flash = $results->{$oid_trpzSysFlashMemoryTotalBytes} - $results->{$oid_trpzSysFlashMemoryUsedBytes};
128
129 $self->{memory} = {display => 'memory',
130 prct_used => $used_bytes * 100 / $total_bytes,
131 used => $used_bytes,
132 free => $free_bytes,
133 total => $total_bytes,
134 };
135
136 $self->{flash} = {display => 'flash',
137 prct_used => $results->{$oid_trpzSysFlashMemoryUsedBytes} * 100 / $results->{$oid_trpzSysFlashMemoryTotalBytes},
138 used => $results->{$oid_trpzSysFlashMemoryUsedBytes},
139 free => $free_bytes_flash,
140 total => $results->{$oid_trpzSysFlashMemoryTotalBytes},
141 };
142 }
143
144 1;
145
146 __END__
147
148 =head1 MODE
149
150 Check memory usage
151
152 =over 8
153
154 =item B<--filter-counters>
155
156 Only display some counters (regexp can be used).
157 Example: --filter-counters='^(memory)$'
158
159 =item B<--warning-*>
160
161 Warning threshold.
162 Can be: 'memory', 'flash'
163
164 =item B<--critical-*>
165
166 Critical threshold.
167 Can be: 'memory', 'flash'
168
169 =back
170
171 =cut