Created
May 13, 2014 12:56
-
-
Save gavinheavyside/9057cba4536a84dd89d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example program | |
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/garyburd/redigo/redis" | |
) | |
func errHndlr(err error) { | |
if err != nil { | |
fmt.Println("error:", err) | |
os.Exit(1) | |
} | |
} | |
type queueLengths map[string]int | |
func printQueueLengths(queuelengths queueLengths) string { | |
queues := "" | |
for queue, size := range queuelengths { | |
queues += fmt.Sprintf("%s: %d ", queue, size) | |
} | |
return queues | |
} | |
func main() { | |
warning_size := 50 | |
critical_size := 100 | |
conn, err := redis.Dial("tcp", ":6379") | |
errHndlr(err) | |
defer conn.Close() | |
queues, err := redis.Strings(conn.Do("SMEMBERS", "resque:queues")) | |
errHndlr(err) | |
warning_queuelengths := make(queueLengths) | |
critical_queuelengths := make(queueLengths) | |
for _, queue := range queues { | |
queuesize, err := redis.Int(conn.Do("LLEN", fmt.Sprintf("resque:queue:%s", queue))) | |
errHndlr(err) | |
if queuesize >= warning_size { | |
warning_queuelengths[queue] = queuesize | |
} | |
if queuesize >= critical_size { | |
critical_queuelengths[queue] = queuesize | |
} | |
} | |
if len(critical_queuelengths) > 0 { | |
fmt.Println("CRITICAL -", printQueueLengths(critical_queuelengths)) | |
os.Exit(2) | |
} else if len(warning_queuelengths) > 0 { | |
fmt.Println("WARNING -", printQueueLengths(warning_queuelengths)) | |
os.Exit(1) | |
} else { | |
fmt.Println("OK - all queue lengths below thresholds") | |
os.Exit(0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment