Skip to content

Instantly share code, notes, and snippets.

@yalla
Created August 11, 2011 12:00
Show Gist options
  • Save yalla/1139477 to your computer and use it in GitHub Desktop.
Save yalla/1139477 to your computer and use it in GitHub Desktop.
Generic HOST-RESOURCES-MIB::hrProcessorLoad Cacti script - gives all CPU-load in a single call. Needs data-, data-input-methode- and graph-tepmplates.
#!/usr/bin/perl
use Net::SNMP;
# base_oid ist HOST-RESOURCES-MIB::hrProcessorLoad
my $base_oid = ".1.3.6.1.2.1.25.3.3.1.2";
($session, $error) = Net::SNMP->session(
-hostname => "$ARGV[0]",
-version => "2",
-community => "public",
);
if ($error != 0) {
print("Net::SNMP::session() - Could not connect to ARGV[0].\n");
die;
}
my $result = $session->get_table(
-baseoid => $base_oid,
-maxrepetitions => 3,
);
if ($result == undef) {
printf("get_table() returned no result.\n");
die;
}
$numcpus = scalar(keys(%$result));
my $i=1;
foreach $key (sort keys %$result) {
printf("cpu%i:%i", $i, $result->{$key});
if ($i != $numcpus) { printf(" "); }
$i++;
}
$session->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment