Last active
January 7, 2019 13:52
-
-
Save alexott/afd2d4764f7136b705ededcd7c65f40d to your computer and use it in GitHub Desktop.
Scripts for generation DSE service discovery JSON files for Prometheus
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
from dse.cluster import Cluster | |
import sys | |
import json | |
if (len(sys.argv) < 3): | |
print("Usage: generate.py contact_point file_name") | |
exit(1) | |
cluster = Cluster([sys.argv[1]]) | |
session = cluster.connect() | |
metadata = cluster.metadata | |
host_list = [host.broadcast_address for host in metadata.all_hosts()] | |
data = {'labels': {'cluster': metadata.cluster_name}, 'targets': host_list} | |
print('data: ' + json.dumps(data)) | |
with open(sys.argv[2], 'w') as f: | |
json.dump(data, f) |
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
#!/bin/bash | |
# | |
# File: generate.sh | |
# | |
# Created: Thursday, January 3 2019 | |
# | |
if [ $# -lt 2 ]; then | |
echo "Usage: generate-dse-topology.sh filename port" | |
fi | |
FILE=$1 | |
PORT=$2 | |
TMPFILE=generate-$$.tmp | |
echo '[{"targets": [' > $TMPFILE | |
cnt=0 | |
for node in `nodetool status|grep -e '^[UD][NLJM] '|sed -e 's|^[UD][NLJM] *\([^ ]*\) .*$|\1|'`; do | |
if [ $cnt -gt 0 ]; then | |
echo -n ", " >> $TMPFILE | |
fi | |
echo -n "\"$node:$PORT\"" >> $TMPFILE | |
cnt=$((1 + cnt)) | |
done | |
CLUSTER_NAME=`nodetool describecluster|grep 'Name:'|sed -e 's|^.*Name: \(.*\)$|\1|'` | |
echo "" >> $TMPFILE | |
echo "],\"labels\": {\"cluster\": \"$CLUSTER_NAME\"}}]" >> $TMPFILE | |
mv $TMPFILE $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment