Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

redis replication check (for master or slave) #32

Merged
merged 7 commits into from Oct 4, 2011

Conversation

Projects
None yet
2 participants
@ghost
Contributor

ghost commented Oct 2, 2011

example:

$ ./redis_replication_check.rb --help
Checks redis replication status.
    -h, --host                 connect to redis running on .  defaults to localhost
    -p, --port                 connect to redis running on .  defaults to 6379
    -r, --role         redis should be master or slave
    -c, --connected_slaves      master should have  slaves.  must be used with -r/--role master.  defaults to 1
    -l, --replication_lag       master io cannot be more than  seconds behind.  used with -r/--role slave.  default is 0
        --help                       Display this screen

$ ./redis_replication_check.rb -r slave
status ok ok
metric master_last_io_seconds_ago int 0

$ ./redis_replication_check.rb -r slave
status err redis thinks it is slave, master is up and last io was 3s.
metric master_last_io_seconds_ago int 3

$ ./redis_replication_check.rb -r slave -l 5
status ok ok
metric master_last_io_seconds_ago int 3

$ ./redis_replication_check.rb -h someremotehost -r master -c 10
status err redis thinks it is master with 1 slaves.

$ ./redis_replication_check.rb -h someremotehost -r master -c 1
status ok ok

@ghost
Contributor

ghost commented Oct 3, 2011

(added change to some other scripts that said "critical" instead of "err" on status because github did it for me :). let me know if you prefer a second pull request!)

@Kami Kami commented on the diff Oct 4, 2011

redis_replication_check.rb
+if options[:role] == "slave"
+ expectedlag = options[:slave_lag].to_i || 0
+ if status["role"] =~ /slave/ \
+ && status["master_link_status"] =~ /up/ \
+ && status["master_last_io_seconds_ago"].to_i <= expectedlag
+
+ puts "status ok ok"
+ else
+ puts "status err redis thinks it is #{status["role"]}, master is #{status["master_link_status"]} and last io was #{status["master_last_io_seconds_ago"]}s."
+ end
+ puts "metric master_last_io_seconds_ago int #{status["master_last_io_seconds_ago"]}"
+else
+ expectedslaves = options[:connected_slaves] || 1
+ actualslaves = status["connected_slaves"].to_i
+ if status["role"] =~ /master/ && actualslaves == expectedslaves
+
@Kami

Kami Oct 4, 2011

Member

Here you could also print the role and connected_slaves metric.

Otherwise the pull requests looks fine.

@ghost
Contributor

ghost commented Oct 4, 2011

Commited Kami. Thanks!

Kami added a commit that referenced this pull request Oct 4, 2011

Merge pull request #32 from flores/master
redis replication check (for master or slave)

@Kami Kami merged commit 5c3289c into cloudkick:master Oct 4, 2011

Member

Kami commented Oct 4, 2011

Merged, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment