Plugin Hackathon オリエンテーション
TIME rest time current/total
TopicsPlaceHolder

Plugin Hackathon オリエンテーション

Mackerel Plugin Hackathon #1

Aug 19th, 2017

Profile

songmu

【宣伝】本が出ます

会場について

会場について

本日

本日のTA

アイデアがあれば何でもご相談ください。

Pluginの作り方

その前に

Macにmackerel-agentを導入しよう

あまりうまく行かなさそうなので、今日余力あれば整備します…

% brew install mackerelio/mackerel-agent/mackerel-agent
% mackerel-agent init -apikey={{APIKEY}} -conf=/usr/local/etc/mackerel-agent.conf
% brew services start mackerel-agent

このやり方であればいけます → http://blog.a-know.me/entry/2015/05/12/215236

ドキュメント

Pluginは3種類

どんな言語でも作れます。公式プラグイン集はGo。

メトリックプラグイン

メトリックプラグイン

メトリックプラグインのフォーマット

標準出力の各行に次のフォーマットが期待されます。(Sensu互換)

{metric name}\t{metric value}\t{epoch seconds}

例: ランダムダイスプラグイン

#!/bin/sh
echo "random.dice\t$((($RANDOM%6) + 1))\t$(date +%s)"

実行例

% mackerel-plugin-dice.sh
random.dice     3       1503107984

設定

[plugin.metrics.dice]
command = "/path/to/mackerel-agent-dice.sh"

動作

グラフ定義(任意)

Mackerel独自の追加仕様。グラフ定義。

# mackerel-agent-plugin
{
  "graphs": {
    {graph}: {
      "label": GRAPH_LABEL,
      "unit": UNIT_TYPE
      "metrics": [
        {
          "name": METRIC_NAME,
          "label": METRIC_LABEL
        },
        ...
      ]
    },
    GRAPH_NAME: ...
  }
}

グラフ定義の出力例

% MACKEREL_AGENT_PLUGIN_META=1 mackerel-plugin-uptime
# mackerel-agent-plugin
{
  "graphs": {
    "uptime": {
      "label": "Uptime",
      "unit": "float",
      "metrics": [
        {
          "name": "seconds",
          "label": "Seconds",
          "type": "",
          "stacked": false,
          "scale": 0
        }
      ]
    }
  }
}

公式ヘルパーを利用したプラグインの作り方

チェックプラグイン

チェックプラグイン

チェックプラグインの仕様

例: ダイスプラグイン

#!/bin/sh
dice=$((($RANDOM%6) + 1))
echo "Roll a dice and get a $dice!"
case "$dice" in
  [1-3]) exit 0;;
  [45])  exit 1;;
  "6")   exit 2;;
esac

実行例:

% check-dice.sh
Roll a dice and get a 6!
% echo $?
2

設定

[plugin.checks.dice]
command = "/path/to/check-dice.sh"

実例

https://mackerel.io/orgs/songmu/alerts/35ZYxnBJ73m

公式ヘルパーを用いた実装

メタデータプラグイン

メタデータプラグイン

メタデータプラグインの仕様

設定例

[plugin.meta.packages]
command = "/path/to/packages.pl"

データ参照の方法

以上

enjoy!