AnyEvent-Graphite

 view release on metacpan or  search on metacpan

lib/AnyEvent/Graphite/SNMPAgent.pm  view on Meta::CPAN


    # need to know about $self before defining the callback just below this
    my $self = bless {
        graphite => $graphite,
        hosts => $hosts,
        snmp_version => $snmp_version,
        %args,
    }, $class;

       
    # start the timer running
    $self->{timer} = AE::timer 0, $interval, sub { $self->gather_metrics; }; 

    return $self;
}

sub add_snmp {
    my ($self, %arg) = @_;
    # toss the arguments into the (per-host) queue
    # look up the host with AnyEvent::DNS so we can be async even here
    AnyEvent::DNS::a $arg{'host'}, sub {
        my (@addrs) = @_;
        push(@{$self->{hosts}{$addrs[0]}}, \%arg); 
    };
}

# this is called by $self->{timer} every $interval seconds
sub gather_metrics {
    my ($self) = @_;
    for my $host (keys %{$self->{hosts}}) {

        # skip any hosts that did not resolve
        next unless $host;

        # steal a community string from the first item in the list. They should all be the same
        my $community = $self->{hosts}{$host}[0]{community} || "public";
        my $session = Net::SNMP->session(



( run in 1.831 second using v1.01-cache-2.11-cpan-49f99fa48dc )