Created
December 25, 2016 14:39
-
-
Save yn-misaki/31953e289447ea041af05143c2dc6956 to your computer and use it in GitHub Desktop.
MackerelでMac&Bluetooth接続された周辺機器を監視してみる ref: http://qiita.com/yn-misaki/items/322cad7b4861d810742d
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
$ istats cpu | |
========================= | |
CPU temp: 40.88°C ▁▂▃▅▆▇ ← この温度だけ使いたい! | |
========================= |
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
$ gem install iStats |
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
$ launchctl stop homebrew.mxcl.mackerel-agent | |
$ launchctl start homebrew.mxcl.mackerel-agent |
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
$ launchctl stop homebrew.mxcl.mackerel-agent | |
$ launchctl start homebrew.mxcl.mackerel-agent |
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
$ vim /usr/local/etc/mackerel-agent.conf | |
# ファイルの最下部に追加 | |
# command = "ruby <開発したプラグインのファイル場所>" | |
======================================== | |
[plugin.metrics.hogehoge] | |
command = "/Users/yn-misaki/.rbenv/shims/ruby /Users/yn-misaki/dev/mackerel_plugin/hogehoge.rb" | |
======================================== |
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
require 'iStats' | |
require 'json' | |
# iStatsのCPUに関する状態を取得するモジュールをinclude | |
include CPU_STATS | |
# Mackerelで表示するラベル、表の名前とかの設定 | |
if ENV["MACKEREL_AGENT_PLUGIN_META"] == '1' | |
meta = { | |
:graphs => { | |
'cpu' => { | |
:label => 'CPU Temp (℃)', | |
:unit => 'integer', | |
:metrics => [ | |
{ | |
:name => 'temp', | |
:label => 'cpu' | |
}, | |
] | |
} | |
} | |
} | |
puts '# mackerel-agent-plugin' | |
puts meta.to_json | |
exit 0 | |
end | |
# iStatsのメソッドget_cpu_tempでCPU温度を取得 | |
puts [ 'cpu.temp', get_cpu_temp.to_i, Time.now.to_i ].join("\t") |
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
$ ioreg -c AppleBluetoothHIDKeyboard | |
# トラックパットの場合 | |
# $ ioreg -c BNBTrackpadDevice |
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
require 'json' | |
# ioregでキーボードのバッテリー情報を取得し、整形するワンライナー・・・。 | |
battery = `ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | grep -v ExtendedFeatures`.gsub(/[[:blank:]]|\|/, '').match(/"BatteryPercent"=(\d+)/)[1] | |
if ENV["MACKEREL_AGENT_PLUGIN_META"] == '1' | |
meta = { | |
graphs: { | |
'keybord' => { | |
:label => 'Keyboard Battery Charge(%)', | |
:unit => 'percentage', | |
:metrics => [ | |
{ | |
name: 'charge', | |
label: 'Battery-0', | |
stacked: false # stackedをfalseに指定すると、積み上げグラフになります | |
}, | |
] | |
} | |
} | |
} | |
puts '# mackerel-agent-plugin' | |
puts meta.to_json | |
exit 0 | |
end | |
puts [ 'keybord.battery_charge', battery, Time.now.to_i ].join("\t") |
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
$ tail -f /usr/local/var/log/mackerel-agent.log |
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
$ vim /usr/local/etc/mackerel-agent.conf | |
# ファイルの最下部に追加 | |
======================================== | |
[plugin.metrics.cpu] | |
command = "/Users/yn-misaki/.rbenv/shims/ruby /Users/yn-misaki/dev/mackerel_plugin/cpu.rb" | |
======================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment