Skip to content

Instantly share code, notes, and snippets.

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 yn-misaki/31953e289447ea041af05143c2dc6956 to your computer and use it in GitHub Desktop.
Save yn-misaki/31953e289447ea041af05143c2dc6956 to your computer and use it in GitHub Desktop.
MackerelでMac&Bluetooth接続された周辺機器を監視してみる ref: http://qiita.com/yn-misaki/items/322cad7b4861d810742d
$ istats cpu
=========================
CPU temp: 40.88°C ▁▂▃▅▆▇ ← この温度だけ使いたい!
=========================
$ launchctl stop homebrew.mxcl.mackerel-agent
$ launchctl start homebrew.mxcl.mackerel-agent
$ launchctl stop homebrew.mxcl.mackerel-agent
$ launchctl start homebrew.mxcl.mackerel-agent
$ 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"
========================================
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")
$ ioreg -c AppleBluetoothHIDKeyboard
# トラックパットの場合
# $ ioreg -c BNBTrackpadDevice
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")
$ tail -f /usr/local/var/log/mackerel-agent.log
$ 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