-
-
Save Songmu/0d18627173b67075e046 to your computer and use it in GitHub Desktop.
mackerel plugins for mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.014; | |
use warnings; | |
use utf8; | |
use JSON::PP; | |
if ($ENV{MACKEREL_AGENT_PLUGIN_META}) { | |
print_meta(); | |
} else { | |
main(); | |
} | |
sub print_meta { | |
say '# mackerel-agent-plugin'; | |
say encode_json({ | |
graphs => { | |
"macbook.pmset" => { | |
label => "Battery", | |
unit => "percentage", | |
metrics => [ | |
{ | |
name => "ib0", | |
label => "InternalBattery-0" | |
}, | |
] | |
} | |
} | |
}); | |
} | |
sub main { | |
my $binfo = `pmset -g ps`; | |
die "pmset failed: $!\n" if $!; | |
my ($battery) = $binfo =~ /\t([0-9.]+)%/ms; | |
die "failed retrieving current_battery: $binfo\n" unless defined $battery; | |
say join "\t", 'macbook.pmset.ib0', $battery, time; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.014; | |
use warnings; | |
use utf8; | |
use JSON::PP; | |
if ($ENV{MACKEREL_AGENT_PLUGIN_META}) { | |
print_meta(); | |
} else { | |
main(); | |
} | |
sub print_meta { | |
say '# mackerel-agent-plugin'; | |
say encode_json({ | |
graphs => { | |
"macbook.temperature" => { | |
label => "Macbook Temperature", | |
unit => "float", | |
metrics => [ | |
{ | |
name => "cpu", | |
label => "CPU temperature", | |
}, | |
], | |
}, | |
}, | |
}); | |
} | |
sub main { | |
my $cpu_temp = `/Users/Songmu/bin/osx-cpu-temp`; | |
die "osx-cpu-temp failed: $!\n" if $!; | |
my ($temperature) = $cpu_temp =~ /^([0-9.]+)/ms; | |
die "failed retrieving temperature: $temperature\n" unless defined $temperature; | |
say join "\t", 'macbook.temperature.cpu', $temperature, time; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment