forked from scylladb/scylla-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genconfig.py
executable file
·42 lines (30 loc) · 1.39 KB
/
genconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
import argparse
import os
import yaml
scylla_port = 9180
node_exporter_port = 9100
def append_port(ips, port):
return ["%s:%s" % (x, port) for x in ips]
def gen_targets(servers, port):
return {"targets": append_port(servers, port)}
def dump_yaml(directory, filename, servers, port):
try:
os.mkdir(directory)
except OSError, err:
if err.errno != 17:
raise
pass
stream = file(os.path.join(directory, filename), 'w')
yaml.dump([gen_targets(servers, port)], stream)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate configuration for prometheus")
parser.add_argument('-d', '--directory', help="directory where to generate the configuration files", type=str, default="./")
parser.add_argument('-s', '--scylla', help="Generate scylla_servers.yml file", action='store_true')
parser.add_argument('-n', '--node', help="Generate node_exporter_servers.yml file", action='store_true')
parser.add_argument('servers', help="list of nodes to configure, separated by space", nargs='+', type=str, metavar='node_ip')
arguments = parser.parse_args()
if arguments.scylla:
dump_yaml(arguments.directory, 'scylla_servers.yml', arguments.servers, scylla_port)
if arguments.node:
dump_yaml(arguments.directory, 'node_exporter_servers.yml', arguments.servers, node_exporter_port)