Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Last active December 19, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiyoh/5989255 to your computer and use it in GitHub Desktop.
Save taiyoh/5989255 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Data::AnomalyDetect;
my $detect = Data::AnomalyDetect->new(
# fluent-plugin-anomalydetect の初期値と同じ値を指定
outlier_term => 28,
outlier_discount => 0.05,
smooth_term => 7,
score_term => 14,
score_discount => 0.1,
threshold => -1.0
);
while(1) {
my $res = `uptime`;
chomp $res;
my ($a) = ($res =~ /load averages: (.+)$/);
my ($a1, $a2, $a3) = split /\s/, $a;
if (my $ret = $detect->emit($a1)) {
print "target -> $ret->{target}, outlier -> $ret->{outlier}, score -> $ret->{score}\n";
}
sleep 3;
}
__DATA__
# output
target -> 1.12, outlier -> 9.48310778734713, score -> 6.91179755926319
target -> 1.11, outlier -> -0.541562650368135, score -> 3.40657864244154
target -> 1.11, outlier -> -0.567111530327911, score -> 3.95873333105756
target -> 1.19, outlier -> -0.540999905002498, score -> 3.99833427509008
target -> 1.17, outlier -> -0.588621159274131, score -> 3.94086063829979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment