From d44d1d1c5d0f01167bf01d7b3493be5d20d40171 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sat, 11 Jun 2016 04:03:56 +0200 Subject: [PATCH 1/5] Add basic support for RethinkDB one graph with read/write docs and overall requests --- plugins/rethinkdb/rethinkdb_node_io | 132 ++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 plugins/rethinkdb/rethinkdb_node_io diff --git a/plugins/rethinkdb/rethinkdb_node_io b/plugins/rethinkdb/rethinkdb_node_io new file mode 100644 index 00000000..bdae09e0 --- /dev/null +++ b/plugins/rethinkdb/rethinkdb_node_io @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +""" + rethinkdb_node_io - A munin plugin for Linux to monitor the io count + per second on the local node + + This plugin is licensed under the AGPL 3.0 license + + AGPL 3.0 RubenKelevra + Author: @RubenKelevra - + + This plugin is written with the known limitation to a single instance per + host. Patches which remove this limitation are very welcome. + + The following munin configuration parameters are supported: + #%# family=auto contrib + #%# capabilities=autoconf + +""" + +from importlib.util import find_spec +from multiprocessing import Process +from os import environ as env +from shutil import which +from socket import gethostname +from sys import argv +from sys import exit as fatal_ +from sys import stderr + +# functions +def fatal(status): + fatal_("ERROR: " + status) + + +def rclose_async(): + conn.close() + + +def check_load_rethinkdb() -> bool: + try: + rdb_spec = find_spec("rethinkdb") + if rdb_spec is None: + return False + return True + except: + fatal("Unknown error while try to load RethinkDB-Driver") + + +def eprint(*args, **kwargs): + print(*args, file=stderr, **kwargs) + + +def getFirstLine(respond): + assert isinstance(respond, net.DefaultCursor) + for e in respond: + return e + + +def print_config(): + print("graph_title RethinkDB - Local Database IOPS and Queries") + print("graph_args --base 1000 -l 0") + print("graph_vlabel Operations / second") + print("graph_category rethinkdb") + print("total_qps.label queries per sec") + print("total_rdps.label read docs per sec") + print("total_wdps.label written docs per sec") + exit(0) + + +def check_autoconf() -> bool: + # this might be too easy, but gonna try. + if which("rethinkdb"): + return True + return False + + +if __name__ == '__main__': + if len(argv) > 2: + fatal("unsupported argument count") + elif len(argv) == 2: + if str(argv[1]) == "config": + print_config() + elif str(argv[1]) == "autoconf": + if check_autoconf(): + print("yes") + else: + print("no") + if not check_load_rethinkdb(): + # FIXME: Correct display of error message when driver is missing should be checked + fatal("RethinkDB-Driver not available!") + exit(0) + else: + fatal("unsupported argument") + + if not check_load_rethinkdb(): + fatal("RethinkDB-Driver not available!") + from rethinkdb import net, connect, db + + # load environment + try: + RETHINKDB_PORT = env['rethinkdb_port'] + except: + RETHINKDB_PORT = "28015" + + try: + RETHINKDB_HOST = env['rethinkdb_host'] + except: + RETHINKDB_HOST = "localhost" + + try: + RETHINKDB_SERVERNAME = env['rethinkdb_servername'] + except: + RETHINKDB_SERVERNAME = gethostname() + + try: + conn = connect(RETHINKDB_HOST, RETHINKDB_PORT) + except: + fatal("connection attempt to the rethinkdb-host \"%s\" via port \"%s\" failed" % ( + str(RETHINKDB_HOST), str(RETHINKDB_PORT))) + + query_engine_info = getFirstLine( + db('rethinkdb').table("stats").filter({"server": RETHINKDB_SERVERNAME}).pluck('query_engine').limit(1).run( + conn))['query_engine'] + + rclose = Process(target=rclose_async()) + rclose.start() + + print("total_qps.value %s" % (query_engine_info["queries_total"])) + print("total_rdps.value %s" % (query_engine_info["read_docs_total"])) + print("total_wdps.value %s" % (query_engine_info["written_docs_total"])) + + # wait for connection termination + rclose.join() From 3720ba7aea4151e50bb104c7a66c2e1312f89a82 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sat, 11 Jun 2016 05:08:16 +0200 Subject: [PATCH 2/5] add counter-definition to store values fetched from database in the right way as diff --- plugins/rethinkdb/rethinkdb_node_io | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/rethinkdb/rethinkdb_node_io b/plugins/rethinkdb/rethinkdb_node_io index bdae09e0..010fdb94 100644 --- a/plugins/rethinkdb/rethinkdb_node_io +++ b/plugins/rethinkdb/rethinkdb_node_io @@ -60,9 +60,12 @@ def print_config(): print("graph_args --base 1000 -l 0") print("graph_vlabel Operations / second") print("graph_category rethinkdb") - print("total_qps.label queries per sec") - print("total_rdps.label read docs per sec") - print("total_wdps.label written docs per sec") + print("total_qps.label queries per + print("total_qps.type COUNTER") + print("total_rdps.label read docs + print("total_rdps.type COUNTER") + print("total_wdps.label written do + print("total_wdps.type COUNTER") exit(0) From c5c3bfdb0d48e0abab2501e5e4160e91e5d8fdf1 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sat, 11 Jun 2016 05:13:44 +0200 Subject: [PATCH 3/5] add some infos about env-vars to the headertext --- plugins/rethinkdb/rethinkdb_node_io | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/rethinkdb/rethinkdb_node_io b/plugins/rethinkdb/rethinkdb_node_io index 010fdb94..69f874c8 100644 --- a/plugins/rethinkdb/rethinkdb_node_io +++ b/plugins/rethinkdb/rethinkdb_node_io @@ -7,9 +7,18 @@ AGPL 3.0 RubenKelevra Author: @RubenKelevra - - + This plugin is written with the known limitation to a single instance per host. Patches which remove this limitation are very welcome. + + If your port / host is somewhat else than the default + localhost:28015, and/or your database-server differes in name from + `hostname` (short hostname), you can add rethinkdb-node-io config vars + like: + [rethinkdb_*] + env.rethinkdb_port 12345 + env.rethinkdb_host localhost.com + env.rethinkdb_servername localhost.com The following munin configuration parameters are supported: #%# family=auto contrib From 3fab7aca7aa7486d3599e0a3380668b5dfda5862 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sat, 11 Jun 2016 05:16:13 +0200 Subject: [PATCH 4/5] fix dubios format errors --- plugins/rethinkdb/rethinkdb_node_io | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/rethinkdb/rethinkdb_node_io b/plugins/rethinkdb/rethinkdb_node_io index 69f874c8..edda7fa1 100644 --- a/plugins/rethinkdb/rethinkdb_node_io +++ b/plugins/rethinkdb/rethinkdb_node_io @@ -69,11 +69,11 @@ def print_config(): print("graph_args --base 1000 -l 0") print("graph_vlabel Operations / second") print("graph_category rethinkdb") - print("total_qps.label queries per - print("total_qps.type COUNTER") - print("total_rdps.label read docs + print("total_qps.label queries per sec") + print("total_qps.type COUNTER") + print("total_rdps.label read docs per sec") print("total_rdps.type COUNTER") - print("total_wdps.label written do + print("total_wdps.label written docs per sec") print("total_wdps.type COUNTER") exit(0) From 05d8c7c8089f17b2b7e7e032dd2f198c8f4308a4 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Wed, 22 Jun 2016 01:23:34 +0200 Subject: [PATCH 5/5] add a servername to the graph to support multiple graphs per munin-node --- plugins/rethinkdb/rethinkdb_node_io | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/plugins/rethinkdb/rethinkdb_node_io b/plugins/rethinkdb/rethinkdb_node_io index edda7fa1..ea7f9f40 100644 --- a/plugins/rethinkdb/rethinkdb_node_io +++ b/plugins/rethinkdb/rethinkdb_node_io @@ -1,18 +1,18 @@ #!/usr/bin/env python3 """ - rethinkdb_node_io - A munin plugin for Linux to monitor the io count + rethinkdb_node_io - A munin plugin for Linux to monitor the io count per second on the local node This plugin is licensed under the AGPL 3.0 license AGPL 3.0 RubenKelevra Author: @RubenKelevra - - + This plugin is written with the known limitation to a single instance per host. Patches which remove this limitation are very welcome. - - If your port / host is somewhat else than the default - localhost:28015, and/or your database-server differes in name from + + If your port / host is somewhat else than the default + localhost:28015, and/or your database-server differes in name from `hostname` (short hostname), you can add rethinkdb-node-io config vars like: [rethinkdb_*] @@ -35,6 +35,7 @@ from sys import argv from sys import exit as fatal_ from sys import stderr + # functions def fatal(status): fatal_("ERROR: " + status) @@ -64,17 +65,17 @@ def getFirstLine(respond): return e -def print_config(): - print("graph_title RethinkDB - Local Database IOPS and Queries") +def print_config(servername): + print("graph_title RethinkDB on '%s'- Local Database IOPS and Queries" % servername) print("graph_args --base 1000 -l 0") print("graph_vlabel Operations / second") print("graph_category rethinkdb") print("total_qps.label queries per sec") print("total_qps.type COUNTER") print("total_rdps.label read docs per sec") - print("total_rdps.type COUNTER") + print("total_rdps.type COUNTER") print("total_wdps.label written docs per sec") - print("total_wdps.type COUNTER") + print("total_wdps.type COUNTER") exit(0) @@ -86,11 +87,16 @@ def check_autoconf() -> bool: if __name__ == '__main__': + try: + RETHINKDB_SERVERNAME = env['rethinkdb_servername'] + except: + RETHINKDB_SERVERNAME = gethostname() + if len(argv) > 2: fatal("unsupported argument count") elif len(argv) == 2: if str(argv[1]) == "config": - print_config() + print_config(RETHINKDB_SERVERNAME) elif str(argv[1]) == "autoconf": if check_autoconf(): print("yes") @@ -118,11 +124,6 @@ if __name__ == '__main__': except: RETHINKDB_HOST = "localhost" - try: - RETHINKDB_SERVERNAME = env['rethinkdb_servername'] - except: - RETHINKDB_SERVERNAME = gethostname() - try: conn = connect(RETHINKDB_HOST, RETHINKDB_PORT) except: