Skip to content

Instantly share code, notes, and snippets.

@Songmu
Created May 17, 2015 11:23
Show Gist options
  • Save Songmu/0d18627173b67075e046 to your computer and use it in GitHub Desktop.
Save Songmu/0d18627173b67075e046 to your computer and use it in GitHub Desktop.
mackerel plugins for mac
#!/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;
}
#!/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