å¢ç°ã§ããæ¤ åãæ°èª¿ãããè °çãå§ã¾ãã¾ãããã§ãå æ°ã§ãã
ãã¦ãå°ãåã« Go 㧠Mackerel ã® delayed_job plugin ãä½ãã¾ããã
masutaka/mackerel-plugin-delayed-job-count
ãªãä½ã£ããï¼
æè¿ãç§ãé¢ãã£ã¦ããã½ã¼ã·ã£ã«PLUSã§ãæ°ãããµã¼ãã¹ãä½ãå§ãã¾ãããä»ã¾ã§ã¯ Zabbix ã§ç£è¦ãã¦ããã®ã§ãããä»åãæ¡ç¨ãã㨠Zabbix ã稼åããããµã¼ããï¼Zabbix ã®ããã®ï¼ããæå³ç¹æ®ã¹ãã«ãå¿ è¦ã§ãå°å ¥ãã¹ããæ©ãã§ãã¾ããããããã£ãäºæ ãããä»å㯠Mackerel ãæ¡ç¨ããã®ãäºã®çºç«¯ã§ãã
ãã®ãµã¼ãã¹ã§ã¯ delayed_job ãåãã¦ãã¾ããdelayed_job ã®ç£è¦ã¯å¤§ãã 2 ã¤ãå¿ è¦ã§ãã
- ããã»ã¹æ°ã®ç£è¦
- Job Queue ã®ç£è¦
1 ã«ã¤ãã¦ã¯ Ruby ã§æ¸ãã Mackerel plugin ãä½ãã¾ãããpgrep ã使ã£ã¦ããã»ã¹æ°ãã«ã¦ã³ãããç´ æ´ãªã¹ã¯ãªããã§ãã
#!/usr/bin/env ruby
if ENV['MACKEREL_AGENT_PLUGIN_META'] == '1'
require 'json'
meta = {
graphs: {
'delayed_job' => {
label: 'delayed_job processes',
unit: 'integer',
metrics: [
{
name: 'processes',
label: 'processes'
}
]
}
}
}
puts '# mackerel-agent-plugin'
puts meta.to_json
exit 0
end
process_count = %x(pgrep -fc '^delayed_job').chomp
puts [ 'delayed_job.processes', process_count, Time.now.to_i ].join("\t")
2 ãå½å㯠Ruby ã§æ¸ãäºå®ã§ãããã以ä¸ã®çç±ã«ãã Go ã§æ¸ããã¨ã«ãã¾ããã
- ã·ã¹ãã ã« mysql2 ãªã©ã® Gem ãã¤ã³ã¹ãã¼ã«ããå¿
è¦ããããChef ã¬ã·ãã®ä¾åãå¢ãã¦ãã¾ã
- ããããæå³ã§ã¯ 1 ã Ruby ã¨ã®ä¾åãåºæ¥ã¦ãã
- æ¥å㧠Go ãæ¸ãã¦ã¿ãããããããæåãä½ããã
ã©ã®ããã«ä½ã£ããï¼
åã㯠monochromegane/mackerel-plugin-delayed-job-count ããã®ã¾ã¾ä½¿ãäºå®ã§ããã
ã§ããåãããã¡ããªã¯ã¹ããè¨å®ã®æ¸¡ãæ¹ããããªãã«éã£ããããããããããã£ã¦ãããå¥ç©ã«ãªã£ã¦ãã¾ãã¾ããã
ä½ãã§ãããï¼
ç¾å¨ã¯ MySQL ã®ã¿å¯¾å¿ãã¦ãã¾ããPostgreSQL çã¸ã®å¯¾å¿ãé£ãããªããããªã®ã§ãããã対å¿ããããã§ãã
ä»åã® masutaka/mackerel-plugin-delayed-job-count ã¯ä»¥ä¸ã®ã¡ããªã¯ã¹ã Mackerel ã«éä¿¡ãã¾ããå®éã® SQL ã¯çºè¡åæ°ãæ¸ãããããè¥å¹²éãã¾ãã
- Processed Job Count
- ç´è¿ 1 åã§å¦çããã¸ã§ãæ°
SHOW TABLE STATUS LIKE 'delayed_jobs'
ã§åå¾ããAuto_increment
ã -1 ãã¦ãå·®åã Mackerel ã«éä¿¡
- Queued Job Count
- ç¾å¨ãã¥ã¼ã«æºã¾ã£ã¦ããã¸ã§ãæ°
SELECT COUNT(*) FROM delayed_jobs WHERE failed_at IS NULL AND locked_by IS NULL
- Processing Job Count
- ç¾å¨å¦çä¸ã®ã¸ã§ãæ°
SELECT COUNT(*) FROM delayed_jobs WHERE failed_at IS NULL AND locked_by IS NOT NULL
- Failed Job Count
- 失æããã¸ã§ãæ°
SELECT COUNT(*) FROM delayed_jobs WHERE failed_at IS NOT NULL
åèã¾ã§ã« monochromegane/mackerel-plugin-delayed-job-count ã¯ä»¥ä¸ã®ã¡ããªã¯ã¹ã Mackerel ã«éä¿¡ãã¾ãã
- Job Count
- ç¾å¨ãã¥ã¼ã«æºã¾ã£ã¦ãããã¾ãã¯å¦çä¸ã®ã¸ã§ãæ°
SELECT COUNT(id) FROM delayed_jobs
- Error Job Count
- 失æããã¸ã§ãæ°
SELECT COUNT(id) FROM delayed_jobs WHERE failed_at IS NOT NULL
ã©ã®ããã«ä½¿ããï¼
macOS 㨠Linux ç¨ã®ãã¤ããªã GitHub ã«ãªãªã¼ã¹ãã¦ãã¾ãã
https://github.com/masutaka/mackerel-plugin-delayed-job-count/releases
ä¾ãã°ãã®ãã㪠Chef ã¬ã·ããæ¸ãã°ã/usr/local/bin/mackerel-plugin-delayed-job-count ã¨ãã¦ã¤ã³ã¹ãã¼ã«åºæ¥ã¾ããRuby ã¹ã¯ãªããã¨éã£ã¦ãã¬ã·ãã«ä¾åé¢ä¿ãåºæ¥ãªãã¦è¯ãã§ããã
remote_file '/usr/local/bin/mackerel-plugin-delayed-job-count' do
version = 'v0.0.1'
checksum = 'db8c1460da2f393b76a3717ed39d036d1cea3445e6b65557654d81cad217ffc1'
source "https://github.com/masutaka/mackerel-plugin-delayed-job-count/releases/download/#{version}/mackerel-plugin-delayed-job-count_linux_amd64"
checksum checksum
mode 0755
end
ãã¨ã¯ /etc/mackerel-agent/mackerel-agent.conf ã«ä»¥ä¸ã追è¨ã mackerel-agent ã reload ããã°ãMackerel ã¸ã®éä¿¡ãå§ã¾ãã¾ãã
[plugin.metrics.delayed_job_count]
command = "/usr/local/bin/mackerel-plugin-delayed-job-count -dsn='DSN'"
DSN 㯠AWS ã§ããã° id:password@tcp(your-amazonaws-uri.com:3306)/dbname
ã¨ãã£ãæ¸å¼ã§ãã詳ãã㯠https://github.com/go-sql-driver/mysql/#dsn-data-source-name ãã©ããã
æ©ãã§ãããã¨
- å
¬å¼ã® mackerelio/mackerel-agent-plugins ã« PR ãåºãã¹ãã
- ãã¹ããæ¸ãã¦ããªã
- delayed_job ã§å¿ è¦ãªã¡ããªã¯ã¹ã¯ç¨éã«ãã£ã¦éããããPR ãåºãåã«ãªãã·ã§ã³ã§æå®å¯è½ã«ãã¹ãã
- 社å
ã® Mackerel plugin ãè¤æ°ã®ãªãã¸ããªã«æ£ãã°ã£ã¦ãã
- å°ãªãã¨ã Ruby ã¹ã¯ãªãããããã¯ï¼ã¤ã®ãªãã¸ããªã«ã¾ã¨ãããã