Skip to content

Commit

Permalink
torben can now monitor cpu and mem
Browse files Browse the repository at this point in the history
  • Loading branch information
lausser committed Nov 22, 2015
1 parent c0b7c87 commit f549f8c
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/Monitoring/GLPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use File::Basename;
use Digest::MD5 qw(md5_hex);
use Errno;
our $AUTOLOAD;
*VERSION = \'1.2';
*VERSION = \'1.2.1';

use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };

Expand Down
44 changes: 42 additions & 2 deletions lib/Monitoring/GLPlugin/SNMP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1274,10 +1274,11 @@ sub get_snmp_tables {
my $table = $info->[1];
my $class = $info->[2];
my $filter = $info->[3];
my $rows = $info->[4];
$self->{$arrayname} = [] if ! exists $self->{$arrayname};
if (! exists $Monitoring::GLPlugin::SNMP::tablecache->{$mib} || ! exists $Monitoring::GLPlugin::SNMP::tablecache->{$mib}->{$table}) {
$Monitoring::GLPlugin::SNMP::tablecache->{$mib}->{$table} = [];
foreach ($self->get_snmp_table_objects($mib, $table)) {
foreach ($self->get_snmp_table_objects($mib, $table, undef, $rows)) {
my $new_object = $class->new(%{$_});
next if (defined $filter && ! &$filter($new_object));
push(@{$self->{$arrayname}}, $new_object);
Expand Down Expand Up @@ -1306,8 +1307,8 @@ sub merge_tables {
}
}
}
delete $self->{$_};
}

}

sub mibs_and_oids_definition {
Expand Down Expand Up @@ -1368,13 +1369,37 @@ sub get_snmp_table_objects_with_cache {
return @entries;
}

sub get_table_row_oids {
my $self = shift;
my $mib = shift;
my $table = shift;
my $rows = shift;
my $entry = $table;
$entry =~ s/Table/Entry/g;
my $eoid = $Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.';
my $eoidlen = length($eoid);
my @columns = scalar(@{$rows}) ?
map {
$Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}
} @{$rows}
:
map {
$Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}
} grep {
substr($Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}, 0, $eoidlen) eq
$Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.'
} keys %{$Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}};
return @columns;
}

# get_snmp_table_objects('MIB-Name', 'Table-Name', 'Table-Entry', [indices])
# returns array of hashrefs
sub get_snmp_table_objects {
my $self = shift;
my $mib = shift;
my $table = shift;
my $indices = shift || [];
my $rows = shift || [];
my @entries = ();
my $augmenting_table;
$self->debug(sprintf "get_snmp_table_objects %s %s", $mib, $table);
Expand Down Expand Up @@ -1531,6 +1556,21 @@ sub get_snmp_table_objects {
# $self->get_indices($Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry});
@entries = $self->make_symbolic($mib, $result, $indices);
@entries = map { $_->{indices} = shift @{$indices}; $_ } @entries;
} elsif (scalar(@{$rows})) {
my @columns = $self->get_table_row_oids($mib, $table, $rows);
my $result = $self->get_entries(
-columns => \@columns,
);
$self->debug(sprintf "get_snmp_table_objects get_table_r returns %d oids",
scalar(keys %{$result}));
my @indices =
$self->get_indices(
-baseoid => $Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry},
-oids => [keys %{$result}]);
$self->debug(sprintf "get_snmp_table_objects get_table_r returns %d indices",
scalar(@indices));
@entries = $self->make_symbolic($mib, $result, \@indices);
@entries = map { $_->{indices} = shift @indices; $_ } @entries;
} else {
$self->debug(sprintf "get_snmp_table_objects calls get_table %s",
$Monitoring::GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table});
Expand Down
31 changes: 12 additions & 19 deletions plugins-scripts/Classes/Huawei/CloudEngine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,18 @@ $Monitoring::GLPlugin::SNMP::definitions->{'HUAWEI-ENTITY-EXTENT-MIB'} = {
'4' => 'supportTunableType',
},
};
$self->get_snmp_tables('ENTITY-MIB', [
['entities', 'entPhysicalTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
]);
if ($self->mode =~ /device::hardware::health/) {
$self->analyze_and_check_environmental_subsystem("Classes::Huawei::Component::EnvironmentalSubsystem");
} elsif ($self->mode =~ /device::hardware::load/) {
$self->analyze_and_check_cpu_subsystem("Classes::Huawei::Component::CpuSubsystem");
} elsif ($self->mode =~ /device::hardware::memory/) {
$self->analyze_and_check_mem_subsystem("Classes::Huawei::Component::MemSubsystem");
} else {
$self->no_such_mode();
}
}

__END__
foreach my $ding (qw(
hwEntityStateTable
hwRUModuleInfoTable
Expand All @@ -678,20 +687,4 @@ hwPreDisposeEntInfoTable)) {
# [$ding, $ding, 'Monitoring::GLPlugin::SNMP::TableItem'],
]);
}
foreach my $ding (qw(
hwEntityStateTable)) {
$self->get_snmp_tables('HUAWEI-ENTITY-EXTENT-MIB', [
[$ding, $ding, 'Monitoring::GLPlugin::SNMP::TableItem'],
]);
}

#printf "entities %s\n", join(" ", map { $_->{flat_indices}} @{$self->{entities}});
#printf "entities %s\n", join(" ", map { $_->{flat_indices}} @{$self->{hwEntityStateTable}});

$self->merge_tables("entities", "hwEntityStateTable");
foreach (@{$self->{entities}}) {
$_->dump();
}

}
81 changes: 81 additions & 0 deletions plugins-scripts/Classes/Huawei/Component/CpuSubsystem.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package Classes::Huawei::Component::CpuSubsystem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::Item);
use strict;

sub init {
my $self = shift;
$self->get_snmp_tables('ENTITY-MIB', [
['entities', 'entPhysicalTable', 'Classes::Huawei::Component::CpuSubsystem::Cpu', sub { my $o = shift; $o->{entPhysicalClass} eq 'module' }, ['entPhysicalClass', 'entPhysicalDescr', 'entPhysicalName']],
]);
$self->get_snmp_tables('HUAWEI-ENTITY-EXTENT-MIB', [
['entitystates', 'hwEntityStateTable', 'Monitoring::GLPlugin::SNMP::TableItem', undef, ['hwEntityCpuUsage', 'hwEntityCpuUsageThreshold']],
]);
$self->merge_tables("entities", "entitystates");
}


package Classes::Huawei::Component::CpuSubsystem::Cpu;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub finish {
my $self = shift;
$self->{name} = $self->{entPhysicalName};
}

sub check {
my $self = shift;
my $id = shift;
$self->add_info(sprintf 'CPU %s usage is %s%%',
$self->{name}, $self->{hwEntityCpuUsage});
$self->set_thresholds(
metric => 'cpu_'.$self->{name},
warning => $self->{hwEntityCpuUsageThreshold},
critical => $self->{hwEntityCpuUsageThreshold},
);
$self->add_message(
$self->check_thresholds(
metric => 'cpu_'.$self->{name},
value => $self->{hwEntityCpuUsage}
));
$self->add_perfdata(
label => 'cpu_'.$self->{name},
value => $self->{hwEntityCpuUsage},
uom => '%',
);
}

__END__
entPhysicalAlias:
entPhysicalAssetID:
entPhysicalClass: module
entPhysicalContainedIn: 16842752
entPhysicalDescr: Assembling Components-CE5800-CE5850-48T4S2Q-EI-CE5850-48T4S2Q-
EI Switch(48-Port GE RJ45,4-Port 10GE SFP+,2-Port 40GE QSFP+,Without Fan and Pow
er Module)
entPhysicalFirmwareRev: 266
entPhysicalHardwareRev: DE51SRU1B VER D
entPhysicalIsFRU: 1
entPhysicalMfgName: Huawei
entPhysicalModelName:
entPhysicalName: CE5850-48T4S2Q-EI 1
entPhysicalParentRelPos: 1
entPhysicalSerialNum: 210235527210E2000218
entPhysicalSoftwareRev: Version 8.80 V100R003C00SPC600
entPhysicalVendorType: .1.3.6.1.4.1.2011.20021210.12.688138
hwEntityAdminStatus: unlocked
hwEntityCpuUsage: 14
hwEntityCpuUsageThreshold: 95
hwEntityFaultLight: normal
hwEntityMemSizeMega: 1837
hwEntityMemUsage: 43
hwEntityMemUsageThreshold: 95
hwEntityOperStatus: enabled
hwEntityPortType: notSupported
hwEntitySplitAttribute:
hwEntityStandbyStatus: providingService
hwEntityTemperature: 33
hwEntityTemperatureLowThreshold: 0
hwEntityTemperatureThreshold: 62
hwEntityUpTime: 34295804
81 changes: 81 additions & 0 deletions plugins-scripts/Classes/Huawei/Component/MemSubsystem.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package Classes::Huawei::Component::MemSubsystem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::Item);
use strict;

sub init {
my $self = shift;
$self->get_snmp_tables('ENTITY-MIB', [
['entities', 'entPhysicalTable', 'Classes::Huawei::Component::MemSubsystem::Mem', sub { my $o = shift; $o->{entPhysicalClass} eq 'module' }, ['entPhysicalClass', 'entPhysicalDescr', 'entPhysicalName']],
]);
$self->get_snmp_tables('HUAWEI-ENTITY-EXTENT-MIB', [
['entitystates', 'hwEntityStateTable', 'Monitoring::GLPlugin::SNMP::TableItem', undef, ['hwEntityMemUsage', 'hwEntityMemUsageThreshold', 'hwEntityMemSizeMega']],
]);
$self->merge_tables("entities", "entitystates");
}


package Classes::Huawei::Component::MemSubsystem::Mem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub finish {
my $self = shift;
$self->{name} = $self->{entPhysicalName};
}

sub check {
my $self = shift;
my $id = shift;
$self->add_info(sprintf 'Memory %s usage is %s%% (of %dMB)',
$self->{name}, $self->{hwEntityMemUsage}, $self->{hwEntityMemSizeMega});
$self->set_thresholds(
metric => 'cpu_'.$self->{name},
warning => $self->{hwEntityMemUsageThreshold},
critical => $self->{hwEntityMemUsageThreshold},
);
$self->add_message(
$self->check_thresholds(
metric => 'cpu_'.$self->{name},
value => $self->{hwEntityMemUsage}
));
$self->add_perfdata(
label => 'cpu_'.$self->{name},
value => $self->{hwEntityMemUsage},
uom => '%',
);
}

__END__
entPhysicalAlias:
entPhysicalAssetID:
entPhysicalClass: module
entPhysicalContainedIn: 16842752
entPhysicalDescr: Assembling Components-CE5800-CE5850-48T4S2Q-EI-CE5850-48T4S2Q-
EI Switch(48-Port GE RJ45,4-Port 10GE SFP+,2-Port 40GE QSFP+,Without Fan and Pow
er Module)
entPhysicalFirmwareRev: 266
entPhysicalHardwareRev: DE51SRU1B VER D
entPhysicalIsFRU: 1
entPhysicalMfgName: Huawei
entPhysicalModelName:
entPhysicalName: CE5850-48T4S2Q-EI 1
entPhysicalParentRelPos: 1
entPhysicalSerialNum: 210235527210E2000218
entPhysicalSoftwareRev: Version 8.80 V100R003C00SPC600
entPhysicalVendorType: .1.3.6.1.4.1.2011.20021210.12.688138
hwEntityAdminStatus: unlocked
hwEntityCpuUsage: 14
hwEntityCpuUsageThreshold: 95
hwEntityFaultLight: normal
hwEntityMemSizeMega: 1837
hwEntityMemUsage: 43
hwEntityMemUsageThreshold: 95
hwEntityOperStatus: enabled
hwEntityPortType: notSupported
hwEntitySplitAttribute:
hwEntityStandbyStatus: providingService
hwEntityTemperature: 33
hwEntityTemperatureLowThreshold: 0
hwEntityTemperatureThreshold: 62
hwEntityUpTime: 34295804
2 changes: 2 additions & 0 deletions plugins-scripts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ EXTRA_MODULES=\
Classes/HH3C/Component/MemSubsystem.pm \
Classes/HH3C/Component/CpuSubsystem.pm \
Classes/HH3C.pm \
Classes/Huawei/Component/CpuSubsystem.pm \
Classes/Huawei/Component/MemSubsystem.pm \
Classes/Huawei/CloudEngine.pm \
Classes/Huawei.pm \
Classes/HP/Procurve/Component/MemSubsystem.pm \
Expand Down

0 comments on commit f549f8c

Please sign in to comment.