LoginSignup
14
14

More than 5 years have passed since last update.

MackerelでResqueのキュー数を可視化する

Posted at

Resqueのキューがどんな感じになっているのか可視化したくなったから、Mackerelを使ってみた。

MackerelにResqueサービスとDBロールとRedisが動いているホストを追加して、下記のようなスクリプト書いた。REDIS_HOST PORT MACKEREL_API_KEY HOST_IDはよしなに設定する。

#!/bin/bash
redis='redis-cli -h REDIS_HOST -p PORT'
timestamp=`date +%s`
apikey=MACKERL_API_KEY
hostid=HOST_ID
json=''
sum=0

for name in `$redis SMEMBERS resque:queues` ; do
    depth=`$redis LLEN resque:queue:${name}`
    sum=`expr $sum + $depth`
    json="$json,{\"hostId\":\"$hostid\",\"name\":\"${name}_queue_depth\",\"time\":$timestamp,\"value\":$depth}"
done

json="[{\"hostId\":\"$hostid\",\"name\":\"queue_depth\",\"time\":$timestamp,\"value\":$sum}$json]"

curl https://mackerel.io/api/v0/tsdb \
    -H "X-Api-Key: $apikey" \
    -H "Content-Type: application/json" \
    -d "$json"

Resqueは resque:queues というSetの中にキューの名前が入っていて、それぞれに対して resque:queue:NAME というListがあり、それの一つ一つの要素がタスクの内容になっているので、Listの大きさがその瞬間のタスク数ということになる。

あとはこれをcronで毎分動かすようにしたらあとはMackerelがいい感じにグラフ化してくれた。

Screen Shot 2014-07-02 at 12.58.36 PM.png
こんな感じ

Mackerelについて

APIがシンプルで使いやすかった。

14
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
14