Created
February 13, 2014 20:27
-
-
Save warmans/8983167 to your computer and use it in GitHub Desktop.
Add colouring to Cassandra nodetool status output
This file contains 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
#! /usr/bin/python | |
import sys, re | |
# To use run | |
# | |
# $ nodetool status | ./ntcolour.py | |
# | |
# or to refresh forever use: | |
# | |
# $ while true; do status="$(nodetool status)"; clear; date; echo "$status" | ./ntcolour.py; sleep 10; done | |
red = '\033[97;41m{0}\033[0m' | |
green = "\033[30;42m{0}\033[0m" | |
yellow = '\033[30;103m{0}\033[0m' | |
status = sys.stdin.read().strip() | |
for line in status.split("\n"): | |
#DC | |
dc = re.match("Datacenter\: (.+)", line) | |
if dc: | |
print "\033[1m{0}\033[m".format(dc.group(1)) | |
continue; | |
#column headings | |
if re.match("^--.+", line): | |
print line | |
# up normal | |
if re.match("^UN .+", line): | |
print green.format(line) | |
continue | |
# up normal/joining/leaving/moving | |
if re.match("^U[NLJM] .+", line): | |
print yellow.format(line) | |
continue | |
# down normal/joining/leaving/moving | |
if re.match("^D[NLJM] .+", line): | |
print red.format(line) | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment