From 6578d39c9bad1564b39bbe4f178fb4b2bcd10d24 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 26 May 2016 17:46:16 -0700 Subject: [PATCH] quick draft of munin plugins --- misc/munin/wormhole_channels | 85 +++++++++++++++++++++++++++++++++ misc/munin/wormhole_errors | 91 ++++++++++++++++++++++++++++++++++++ misc/munin/wormhole_events | 91 ++++++++++++++++++++++++++++++++++++ misc/munin/wormhole_messages | 73 +++++++++++++++++++++++++++++ misc/munin/wormhole_transit | 81 ++++++++++++++++++++++++++++++++ 5 files changed, 421 insertions(+) create mode 100755 misc/munin/wormhole_channels create mode 100755 misc/munin/wormhole_errors create mode 100755 misc/munin/wormhole_events create mode 100755 misc/munin/wormhole_messages create mode 100755 misc/munin/wormhole_transit diff --git a/misc/munin/wormhole_channels b/misc/munin/wormhole_channels new file mode 100755 index 0000000..10e5f2c --- /dev/null +++ b/misc/munin/wormhole_channels @@ -0,0 +1,85 @@ +#! /usr/bin/env python + +""" +Use the following in /etc/munin/plugin-conf.d/wormhole : + +[wormhole_*] +env.serverdir /path/to/your/wormhole/server +""" + +import os, sys, time, sqlite3 + +def count_events(): + serverdir = os.environ["serverdir"] + dbfile = os.path.join(serverdir, "relay.sqlite") + if not os.path.exists("relay.sqlite"): + print "cannot find relay.sqlite, please set env.serverdir" + sys.exit(1) + db = sqlite3.connect(dbfile) + db.row_factory = sqlite3.Row + + c_list = [] + c_dict = {} + def add(key, value): + c_list.append((key, value)) + c_dict[key] = value + def q(query, values=()): + return db.execute(query, values).fetchone()[0] + OLD = time.time() - 10*60 + add("apps", q("SELECT COUNT(DISTINCT(`app_id`)) FROM `nameplates`")) + + add("total nameplates", q("SELECT COUNT() FROM `nameplates`")) + add("waiting nameplates", q("SELECT COUNT() FROM `nameplates`" + " WHERE `second` is null")) + add("connected nameplates", q("SELECT COUNT() FROM `nameplates`" + " WHERE `second` is not null")) + add("stale nameplates", q("SELECT COUNT() FROM `nameplates`" + " where `updated` < ?", (OLD,))) + + add("total mailboxes", q("SELECT COUNT() FROM `mailboxes`")) + add("waiting mailboxes", q("SELECT COUNT() FROM `mailboxes`" + " WHERE `second` is null")) + add("connected mailboxes", q("SELECT COUNT() FROM `mailboxes`" + " WHERE `second` is not null")) + + stale_mailboxes = 0 + for mbox_row in db.execute("SELECT * FROM `mailboxes`").fetchall(): + newest = db.execute("SELECT `server_rx` FROM `messages`" + " WHERE `app_id`=? AND `mailbox_id`=?" + " ORDER BY `server_rx` DESC LIMIT 1", + (mbox_row["app_id"], mbox_row["id"])).fetchone() + if newest and newest[0] < OLD: + stale_mailboxes += 1 + add("stale mailboxes", stale_mailboxes) + + add("messages", q("SELECT COUNT() FROM `messages`")) + + return c_dict + +CONFIG = """\ +graph_title Magic-Wormhole Active Channels +graph_vlabel Channels +graph_category network +nameplates.label Total Nameplates +nameplates.draw LINE2 +nameplates.type GAUGE +waiting_nameplates.label Waiting Nameplates +waiting_nameplates.draw LINE2 +waiting_nameplates.type GAUGE +mailboxes.label Total Mailboxes +mailboxes.draw LINE2 +mailboxes.type GAUGE +waiting_mailboxes.label Waiting Mailboxes +waiting_mailboxes.draw LINE2 +waiting_mailboxes.type GAUGE +""" + +if len(sys.argv) > 1 and sys.argv[1] == "config": + print CONFIG.rstrip() + sys.exit(0) + +c = count_events() +print "nameplates.value", c["total nameplates"] +print "waiting_nameplates.value", c["waiting nameplates"] +print "mailboxes.value", c["total mailboxes"] +print "waiting_mailboxes.value", c["waiting mailboxes"] diff --git a/misc/munin/wormhole_errors b/misc/munin/wormhole_errors new file mode 100755 index 0000000..aa73b5f --- /dev/null +++ b/misc/munin/wormhole_errors @@ -0,0 +1,91 @@ +#! /usr/bin/env python + +""" +Use the following in /etc/munin/plugin-conf.d/wormhole : + +[wormhole_*] +env.serverdir /path/to/your/wormhole/server +""" + +import os, sys, sqlite3 + +def count_events(): + serverdir = os.environ["serverdir"] + dbfile = os.path.join(serverdir, "relay.sqlite") + if not os.path.exists("relay.sqlite"): + print "cannot find relay.sqlite, please set env.serverdir" + sys.exit(1) + db = sqlite3.connect(dbfile) + + c_list = [] + c_dict = {} + def add(key, value): + c_list.append((key, value)) + c_dict[key] = value + def q(query, values=()): + return db.execute(query, values).fetchone()[0] + + add("apps", q("SELECT COUNT(DISTINCT(`app_id`)) FROM `nameplate_usage`")) + + add("total nameplates", q("SELECT COUNT() FROM `nameplate_usage`")) + add("happy nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='happy'")) + add("lonely nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='lonely'")) + add("pruney nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='pruney'")) + add("crowded nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='crowded'")) + + add("total mailboxes", q("SELECT COUNT() FROM `mailbox_usage`")) + add("happy mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='happy'")) + add("scary mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='scary'")) + add("lonely mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='lonely'")) + add("errory mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='errory'")) + add("pruney mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='pruney'")) + add("crowded mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='crowded'")) + + add("total transit", q("SELECT COUNT() FROM `transit_usage`")) + add("happy transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='happy'")) + add("lonely transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='lonely'")) + add("errory transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='errory'")) + + add("transit bytes", q("SELECT SUM(`total_bytes`) FROM `transit_usage`")) + + return c_dict + +CONFIG = """\ +graph_title Magic-Wormhole Server Errors +graph_vlabel Events per time +graph_category network +nameplates.label Nameplates +nameplates.draw LINE +nameplates.type DERIVE +nameplates.min 0 +mailboxes.label Mailboxes +mailboxes.draw LINE +mailboxes.type DERIVE +mailboxes.min 0 +transit.label Transit +transit.draw LINE +transit.type DERIVE +transit.min 0 +""" + +if len(sys.argv) > 1 and sys.argv[1] == "config": + print CONFIG.rstrip() + sys.exit(0) + +c = count_events() +print "nameplates.value", c["total nameplates"] - c["happy nameplates"] +print "mailboxes.value", c["total mailboxes"] - c["happy mailboxes"] +print "transit.value", c["total transit"] - c["happy transit"] diff --git a/misc/munin/wormhole_events b/misc/munin/wormhole_events new file mode 100755 index 0000000..3c15ea9 --- /dev/null +++ b/misc/munin/wormhole_events @@ -0,0 +1,91 @@ +#! /usr/bin/env python + +""" +Use the following in /etc/munin/plugin-conf.d/wormhole : + +[wormhole_*] +env.serverdir /path/to/your/wormhole/server +""" + +import os, sys, sqlite3 + +def count_events(): + serverdir = os.environ["serverdir"] + dbfile = os.path.join(serverdir, "relay.sqlite") + if not os.path.exists("relay.sqlite"): + print "cannot find relay.sqlite, please set env.serverdir" + sys.exit(1) + db = sqlite3.connect(dbfile) + + c_list = [] + c_dict = {} + def add(key, value): + c_list.append((key, value)) + c_dict[key] = value + def q(query, values=()): + return db.execute(query, values).fetchone()[0] + + add("apps", q("SELECT COUNT(DISTINCT(`app_id`)) FROM `nameplate_usage`")) + + add("total nameplates", q("SELECT COUNT() FROM `nameplate_usage`")) + add("happy nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='happy'")) + add("lonely nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='lonely'")) + add("pruney nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='pruney'")) + add("crowded nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='crowded'")) + + add("total mailboxes", q("SELECT COUNT() FROM `mailbox_usage`")) + add("happy mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='happy'")) + add("scary mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='scary'")) + add("lonely mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='lonely'")) + add("errory mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='errory'")) + add("pruney mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='pruney'")) + add("crowded mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='crowded'")) + + add("total transit", q("SELECT COUNT() FROM `transit_usage`")) + add("happy transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='happy'")) + add("lonely transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='lonely'")) + add("errory transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='errory'")) + + add("transit bytes", q("SELECT SUM(`total_bytes`) FROM `transit_usage`")) + + return c_dict + +CONFIG = """\ +graph_title Magic-Wormhole Server Events +graph_vlabel Events per time +graph_category network +nameplates.label Nameplates +nameplates.draw LINE +nameplates.type DERIVE +nameplates.min 0 +mailboxes.label Mailboxes +mailboxes.draw LINE +mailboxes.type DERIVE +mailboxes.min 0 +transit.label Transit +transit.draw LINE +transit.type DERIVE +transit.min 0 +""" + +if len(sys.argv) > 1 and sys.argv[1] == "config": + print CONFIG.rstrip() + sys.exit(0) + +c = count_events() +print "nameplates.value", c["total nameplates"] +print "mailboxes.value", c["total mailboxes"] +print "transit.value", c["total transit"] diff --git a/misc/munin/wormhole_messages b/misc/munin/wormhole_messages new file mode 100755 index 0000000..aa3e5af --- /dev/null +++ b/misc/munin/wormhole_messages @@ -0,0 +1,73 @@ +#! /usr/bin/env python + +""" +Use the following in /etc/munin/plugin-conf.d/wormhole : + +[wormhole_*] +env.serverdir /path/to/your/wormhole/server +""" + +import os, sys, time, sqlite3 + +def count_events(): + serverdir = os.environ["serverdir"] + dbfile = os.path.join(serverdir, "relay.sqlite") + if not os.path.exists("relay.sqlite"): + print "cannot find relay.sqlite, please set env.serverdir" + sys.exit(1) + db = sqlite3.connect(dbfile) + db.row_factory = sqlite3.Row + + c_list = [] + c_dict = {} + def add(key, value): + c_list.append((key, value)) + c_dict[key] = value + def q(query, values=()): + return db.execute(query, values).fetchone()[0] + OLD = time.time() - 10*60 + add("apps", q("SELECT COUNT(DISTINCT(`app_id`)) FROM `nameplates`")) + + add("total nameplates", q("SELECT COUNT() FROM `nameplates`")) + add("waiting nameplates", q("SELECT COUNT() FROM `nameplates`" + " WHERE `second` is null")) + add("connected nameplates", q("SELECT COUNT() FROM `nameplates`" + " WHERE `second` is not null")) + add("stale nameplates", q("SELECT COUNT() FROM `nameplates`" + " where `updated` < ?", (OLD,))) + + add("total mailboxes", q("SELECT COUNT() FROM `mailboxes`")) + add("waiting mailboxes", q("SELECT COUNT() FROM `mailboxes`" + " WHERE `second` is null")) + add("connected mailboxes", q("SELECT COUNT() FROM `mailboxes`" + " WHERE `second` is not null")) + + stale_mailboxes = 0 + for mbox_row in db.execute("SELECT * FROM `mailboxes`").fetchall(): + newest = db.execute("SELECT `server_rx` FROM `messages`" + " WHERE `app_id`=? AND `mailbox_id`=?" + " ORDER BY `server_rx` DESC LIMIT 1", + (mbox_row["app_id"], mbox_row["id"])).fetchone() + if newest and newest[0] < OLD: + stale_mailboxes += 1 + add("stale mailboxes", stale_mailboxes) + + add("messages", q("SELECT COUNT() FROM `messages`")) + + return c_dict + +CONFIG = """\ +graph_title Magic-Wormhole Queued Messages +graph_vlabel Messages +graph_category network +messages.label Total Messages +messages.draw LINE2 +messages.type GAUGE +""" + +if len(sys.argv) > 1 and sys.argv[1] == "config": + print CONFIG.rstrip() + sys.exit(0) + +c = count_events() +print "messages.value", c["messages"] diff --git a/misc/munin/wormhole_transit b/misc/munin/wormhole_transit new file mode 100755 index 0000000..49646cb --- /dev/null +++ b/misc/munin/wormhole_transit @@ -0,0 +1,81 @@ +#! /usr/bin/env python + +""" +Use the following in /etc/munin/plugin-conf.d/wormhole : + +[wormhole_*] +env.serverdir /path/to/your/wormhole/server +""" + +import os, sys, sqlite3 + +def count_events(): + serverdir = os.environ["serverdir"] + dbfile = os.path.join(serverdir, "relay.sqlite") + if not os.path.exists("relay.sqlite"): + print "cannot find relay.sqlite, please set env.serverdir" + sys.exit(1) + db = sqlite3.connect(dbfile) + + c_list = [] + c_dict = {} + def add(key, value): + c_list.append((key, value)) + c_dict[key] = value + def q(query, values=()): + return db.execute(query, values).fetchone()[0] + + add("apps", q("SELECT COUNT(DISTINCT(`app_id`)) FROM `nameplate_usage`")) + + add("total nameplates", q("SELECT COUNT() FROM `nameplate_usage`")) + add("happy nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='happy'")) + add("lonely nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='lonely'")) + add("pruney nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='pruney'")) + add("crowded nameplates", q("SELECT COUNT() FROM `nameplate_usage`" + " WHERE `result`='crowded'")) + + add("total mailboxes", q("SELECT COUNT() FROM `mailbox_usage`")) + add("happy mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='happy'")) + add("scary mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='scary'")) + add("lonely mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='lonely'")) + add("errory mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='errory'")) + add("pruney mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='pruney'")) + add("crowded mailboxes", q("SELECT COUNT() FROM `mailbox_usage`" + " WHERE `result`='crowded'")) + + add("total transit", q("SELECT COUNT() FROM `transit_usage`")) + add("happy transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='happy'")) + add("lonely transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='lonely'")) + add("errory transit", q("SELECT COUNT() FROM `transit_usage`" + " WHERE `result`='errory'")) + + add("transit bytes", q("SELECT SUM(`total_bytes`) FROM `transit_usage`")) + + return c_dict + +CONFIG = """\ +graph_title Magic-Wormhole Transit Usage +graph_vlabel Bytes per time +graph_category network +transit.label Transit Bytes +transit.draw LINE +transit.type DERIVE +transit.min 0 +""" + +if len(sys.argv) > 1 and sys.argv[1] == "config": + print CONFIG.rstrip() + sys.exit(0) + +c = count_events() +print "nameplates.value", c["transit bytes"]