Upgrade to Pro — share decks privately, control downloads, hide ads and more …

自前運用の Zabbix から Mackerel へ - ソーシャルゲームタイトルのサーバ監視の移行事例

jetzou
January 26, 2019
1.5k

自前運用の Zabbix から Mackerel へ - ソーシャルゲームタイトルのサーバ監視の移行事例

jetzou

January 26, 2019
Tweet

Transcript

  1. 発表 • 監視・ 移植 • 通知 対処法 • ⾃作 ・

    利⽤ 監視 • mackerel 便利 機能 • / 付 合 ⼯夫 • ryotarai/waker 連携 • mackerel service discovery 利⽤ 緊急 ⽅法
  2. 甲⼦園! • 以下 • 4周年 迎 • Perl5 書 •

    AWS • Packer, Chef , 構成管理 • Consul, stretcher 仕組 • ⾃前運⽤ Zabbix 監視
  3. Zabbix • Zabbix 運⽤ 必要 • 追従 • 現⾏: 2.0.x

    • 最新 : 4.0 • 各 ⾜並 必要 難
  4. • 提供 SaaS型 監視 • mackerel-agent: 動作 監視 • AWS

    : 向 • zabbix-server 監視 運⽤ 不要 mackerel
  5. 監視移植 • Zabbix (監視項⽬) 列挙 • mackerel 監視 / 監視

    • mackerel-agent.conf 等 chef recipe 追加 • Zabbix mackerel 並⾏運⽤ • 同 ⾶ 確認 OK • Zabbix 監視 抜
  6. Zabbix ・ 列挙 • 各EC2 役割 (role) • web, batch,

    log-aggregator… • 50 ~ 80 • 各 ・ Template 組 合 • EC2 ⽤ 基本的 Template + 各role⽤ Template • 継承 Template 各 設定 値 違 • 各 role 適⽤ 洗 出
  7. Zabbix mackerel 監視 • 監視 監視 • 選定 • ⾜

    機能 PR 送 作 • 深刻度 対応付
  8. 監視 監視 • 監視 • agent mackerel 送 、 値

    設 • 監視設定 mackerel 上 定義 • 監視 • agent 実⾏ 結果 監視項⽬ • 監視設定 agent 設定 定義 • 何 異常 如何 、 値 形 • 監視 設定 起 • 移⾏中 設定 誤発⽕・不発 監視 多
  9. 監視 監視 • 監視 • agent mackerel 送 、 値

    設 • 監視設定 mackerel 上 定義 • 監視 • agent 実⾏ 結果 監視項⽬ • 監視設定 agent 設定 定義 • 何 異常 如何 、 値 形 • 監視 設定 起 • 移⾏中 設定 誤発⽕・不発 監視 多 監視 寄
  10. 監視例 # CRITICAL consulͷHTTPΤϯυϙΠϯτ؂ࢹ [plugin.checks.consul_http_listen] command = "check-tcp --port 8500”

    # CRITICAL consulͷDNS Interface؂ࢹ [plugin.checks.consul_dns_listen] command = "check-tcp --port 8600” mackerel-agent.conf
  11. 監視例 # CRITICAL consulͷHTTPΤϯυϙΠϯτ؂ࢹ [plugin.checks.consul_http_listen] command = "check-tcp --port 8500”

    # CRITICAL consulͷDNS Interface؂ࢹ [plugin.checks.consul_dns_listen] command = "check-tcp --port 8600” mackerel-agent.conf 深刻度 *1 *1現在 memo 要素 使 良
  12. 選定 • 公式 充実 、 探 • : mackerelio/mackerel-agent-plugins •

    監視 : mackerelio/go-check-plugins • 各 README • ⼿元 動 ・ 読 • README.md 有⽤
  13. 無 、機能 ⾜ • 公式 機能 ⾜ 場合 PR 出

    • • mysql: Aurora *1 • redis: CONFIG cmd 対応*2, Uptime 収集*3 • 監視 • check-tcp: 疎通失敗時 WARN 選 *4 *1 https://github.com/mackerelio/mackerel-agent-plugins/pull/462 *2 https://github.com/mackerelio/mackerel-agent-plugins/pull/463 *3 https://github.com/mackerelio/mackerel-agent-plugins/pull/502 *4 https://github.com/mackerelio/go-check-plugins/pull/212
  14. • 作 • • https://github.com/kayac/mackerel-plugin-katsubushi • https://github.com/kayac/mackerel-plugin-gunfish • https://github.com/kayac/mackerel-plugin-kuiperbelt •

    監視 • https://github.com/kayac/check-consul • https://github.com/kayac/check-crontab • https://github.com/kayac/check-reboot 無 、機能 ⾜
  15. 深刻度 対応付 • 使⽤ Zabbix 深刻度 4段階 • INFO(情報)/WARN(警告)/Average(軽度 障害)/High(重度

    障害) • mackerel 深刻度 2段階 • WARN/CRITICAL • 深刻度 通知先 変
  16. 深刻度 Zabbix mackerel 通知 情報 (INFO) slack 警告 (WARN) WARNING

    slack 軽度 障害 (AVG) CRITICAL slack @channel, waker, mail 重度 障害 (HIGH) CRITICAL slack @channel, waker, mail
  17. 深刻度 Zabbix mackerel 通知 情報 (INFO) slack 警告 (WARN) WARNING

    slack 軽度 障害 (AVG) CRITICAL slack @channel, waker, mail 重度 障害 (HIGH) CRITICAL slack @channel, waker, mail 同 通知先 CRITICAL
  18. 深刻度 Zabbix mackerel 通知 情報 (INFO) slack 警告 (WARN) WARNING

    slack 軽度 障害 (AVG) CRITICAL slack @channel, waker, mail 重度 障害 (HIGH) CRITICAL slack @channel, waker, mail INFO ?
  19. 通知 対処法 • INFO • 障害・ 通知 事項 • 具体例

    • norikra 変更検知 • consul 交代 • 低度 Load Average 増加
  20. Songmu/horenso • Usage: horenso ̶reporter /path/reporter.pl ̶ /path/job.sh • 実⾏結果

    slack 通知 • cron 実⾏結果 報告 使 • ref: 0 * * * * /path/job.sh >/dev/null 2>&1*1 • INFO 相当 ? *1 cron >/dev/null 椅⼦ 投 3 ⽅法 https://sfujiwara.hatenablog.com/entry/20120613/1339547638
  21. Songmu/horenso • reporter 受 取 JSON • exitCode ⾒ 平常時

    • perl+shell reporter *1 { "command": "perl -E 'say 1;warn \"$$\\n\";'", "commandArgs": [ "perl", "-E", "say 1;warn \"$$\\n\";" ], "output": "1\n95030\n", "stdout": "1\n", "stderr": "95030\n", "exitCode": 0, "result": "command exited with code: 0", "pid": 95030, "startAt": "2015-12-28T00:37:10.494282399+09:00", "endAt": "2015-12-28T00:37:10.546466379+09:00", "hostname": "webserver.example.com", "systemTime": 0.034632, "userTime": 0.026523 } *1 horenso slack reporter 書 https://beatsync.net/main/log20160330.html
  22. Songmu/horenso • horenso 終了 対象 終了 • agent 異常系 終了

    伝 ⾶ • horenso 常 終了 0 返 追加 • Author 意図 期待 挙動 相談 上 PR 送 *1 *1 add override command status option #16 https://github.com/Songmu/horenso/pull/16
  23. mackerel-info # INFO [plugin.checks.consul_leader_changed] command = "/usr/local/bin/mackerel-info check-consul leader-changed" #!/bin/bash

    export PATH="$PATH:/usr/local/bin" export SLACK_ENDPOINT="<%= @webhook_uri %>" export SLACK_USERNAME="Mackerel horenso" export SLACK_CHANNEL="<%= node[:horenso][:slack_channel] %>" export SLACK_ICON_EMOJI=":mackerel:" export SLACK_MUTE_ON_NORMAL=1 exec horenso -o -r slack_reporter.pl -- "$@" mackerel-agent.conf /usr/local/bin/mackerel-info
  24. 深刻度 Zabbix mackerel 通知 情報 (INFO) INFO (horenso) slack 警告

    (WARN) WARNING slack 軽度 障害 (AVG) CRITICAL slack @channel, waker, mail 重度 障害 (HIGH) CRITICAL slack @channel, waker, mail
  25. mackerel-agent 設定 追加 • 構成管理 Chef • recipe mackerel-agent, ,

    設定 管理 • /etc/mackerel-agent/mackerel-agent.conf • EC2 共通 、 記述 • /etc/mackerel-agent/conf.d/*.conf • role 分 、 記述 • Chef recipe 分
  26. mackerel-agent 設定 追加 • role 対応 roles/*.json 読 込 •

    run_list role 固有 監視設定 配置 recipe ⾜ • 例: • role 監視 ⼊ "run_list": [ "role[stretcher]", "recipe[gearmand]", + "recipe[mackerel-agent::gearmand]", "recipe[haproxy]", + "recipe[mackerel-agent::haproxy]", roles/batch.json
  27. Zabbix mackerel 並⾏利⽤ • mackerel 監視 導⼊後 Zabbix 継続 利⽤

    • 移⾏中 mackerel 監視設定 • 不発、 暴発 • 移⾏作業中 何度 • 実績 Zabbix 監視設定 信⽤ • 移⾏期間中 監視 質 下 • 監視項⽬ 発動 障害 気付 不安 無
  28. mackerel 便利機能: • Google 記録 残 • 通称: • mackerel

    上 情報 出 便利 • • 指定 時間帯 注釈
  29. • 投稿 • 1⾏追加 対応完了 # mackerel ʹάϥϑΞϊςʔγϣϯΛ௥Ճ͢Δ mkr annotations

    create —-service prod \ -—title "$event_name" \ --from $(date +%s --date "$start_time") \ --to $(date +%s --date "$end_time")
  30. • 捌 web • 起動時 AMI作成時 構成 最新 状態 ⾛

    • 、 Chef 実⾏ • agent ⾃動 ⽴ 上 中 監視 始 • InService 各役割 満 状態 • 監視対象 準備 済 ⾶
  31. • 退役時 各種 ・ 終了 • mackerel-agent 終了順序 遅 …

    • 監視対象 先 落 ⾶ • 各種 agent 起動・終了順序 考慮 動作
  32. 起動時 制御 • rc.local 実⾏ • Chef, , consul maint

    解除 • mackerel-agent ⾃動起動 無効 rc.local 最後 起動 • Chef mackerel-agent 起動
  33. 退役時 制御 • /etc/init.d/autoscale • 退役処理 init • fluentd ,

    consul /ELB leave … • mackerel-agent 終了順序 考慮 • mackerel-agent K05 、 autoscale 当初 K00 • autoscale 優先度 mackerel-agent 落 ( K00 -> K10 )
  34. Packer • 各 role Packer AMI 作成 • Chef 実⾏

    • mackerel-agent 起動 • AMI 作 mackerel 登録 • role ⾃動起動 無効
  35. service “mackerel-agent” resource supports = node[:roles].include?("packer") ? {:start => false,

    :reload => false} : {:reload => true} if node[:roles].include?("autoscale") && node[:roles].include?("packer") then actions = [:disable, :stop] elsif node[:roles].include?("autoscale") then actions = [:enable] elsif node[:roles].include?("packer") then actions = [:enable, :stop] else actions = [:enable, :start] end service "mackerel-agent" do action actions supports supports end
  36. service “mackerel-agent” resource supports = node[:roles].include?("packer") ? {:start => false,

    :reload => false} : {:reload => true} if node[:roles].include?("autoscale") && node[:roles].include?("packer") then actions = [:disable, :stop] elsif node[:roles].include?("autoscale") then actions = [:enable] elsif node[:roles].include?("packer") then actions = [:enable, :stop] else actions = [:enable, :start] end service "mackerel-agent" do action actions supports supports end
  37. service “mackerel-agent” resource supports = node[:roles].include?("packer") ? {:start => false,

    :reload => false} : {:reload => true} if node[:roles].include?("autoscale") && node[:roles].include?("packer") then actions = [:disable, :stop] elsif node[:roles].include?("autoscale") then actions = [:enable] elsif node[:roles].include?("packer") then actions = [:enable, :stop] else actions = [:enable, :start] end service "mackerel-agent" do action actions supports supports end
  38. service “mackerel-agent” resource supports = node[:roles].include?("packer") ? {:start => false,

    :reload => false} : {:reload => true} if node[:roles].include?("autoscale") && node[:roles].include?("packer") then actions = [:disable, :stop] elsif node[:roles].include?("autoscale") then actions = [:enable] elsif node[:roles].include?("packer") then actions = [:enable, :stop] else actions = [:enable, :start] end service "mackerel-agent" do action actions supports supports end
  39. service “mackerel-agent” resource supports = node[:roles].include?("packer") ? {:start => false,

    :reload => false} : {:reload => true} if node[:roles].include?("autoscale") && node[:roles].include?("packer") then actions = [:disable, :stop] elsif node[:roles].include?("autoscale") then actions = [:enable] elsif node[:roles].include?("packer") then actions = [:enable, :stop] else actions = [:enable, :start] end service "mackerel-agent" do action actions supports supports end
  40. service “mackerel-agent” resource supports = node[:roles].include?("packer") ? {:start => false,

    :reload => false} : {:reload => true} if node[:roles].include?("autoscale") && node[:roles].include?("packer") then actions = [:disable, :stop] elsif node[:roles].include?("autoscale") then actions = [:enable] elsif node[:roles].include?("packer") then actions = [:enable, :stop] else actions = [:enable, :start] end service "mackerel-agent" do action actions supports supports end
  41. waker • https://github.com/ryotarai/waker • • Zabbix mackerel 受 取 、担当者

    電話 • 担当者 応答 次 担当者 発呼 • Google ⼊ 替
  42. waker mackerel 連携 • Zabbix waker 送 • mackerel waker

    登録 • webhook 通知 使 • mackerel ⽤ 作成 PR 送 *1 *1 https://github.com/ryotarai/waker/pull/42
  43. mackerel 利⽤ 緊急 ⼊ ⽅ • 通常時 consul template nginx

    設定 書 換 ⼊ • consul 崩壊 • ⼊ 、 出来 • 各 ssh ⼊ nginx 設定 書 換 • 普段 memberlist 使 ssh 接続先 補完 、
 各 回 ⼀苦労
  44. • mkr hosts web IP 取得 • nssh /var/tmp/503 設置

    • nginx 503 返 • consul 復旧 mackerel 利⽤ 緊急 ⼊ ⽅ $ mkr hosts --service prod --role web | jq -r ".[].ipAddresses.eth0" >web-ip-list $ nssh -f web-ip-list "touch /var/tmp/503"
  45. • 監視 Zabbix mackerel 移⾏ • ⾜ 機能 ⾃分 作

    PR 送 : 育 監視 • Zabbix 並⾏ 運⽤ 、監視設定 確認 • 付 合 • agent 起動・終了順序 地味 丁寧 • mackerel 情報 使 緊急 ⼊ 仕組 ⼊