From 19ebd999419e41e43ce37bc443345612682c4249 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 26 Sep 2019 04:35:56 -0400 Subject: [PATCH] wrote some scripts to record stats of various services --- collectd/gitea-collectd.lua | 29 +++++++++++++++++++++++++++++ collectd/prosody-collectd.lua | 17 +++++++++++++++++ collectd/types.custom.db | 5 +++++ 3 files changed, 51 insertions(+) create mode 100755 collectd/gitea-collectd.lua create mode 100755 collectd/prosody-collectd.lua create mode 100644 collectd/types.custom.db diff --git a/collectd/gitea-collectd.lua b/collectd/gitea-collectd.lua new file mode 100755 index 0000000..4ee7456 --- /dev/null +++ b/collectd/gitea-collectd.lua @@ -0,0 +1,29 @@ +#!/usr/bin/env lua +local gitdir = "/home/git/gitea-repositories/" + +local socket = require "socket" +local fs = require "lfs" + +local hostname = os.getenv("COLLECTD_HOSTNAME") or os.getenv("HOSTNAME") or "lain.church" +local interval = os.getenv("COLLECTD_INTERVAL") or 60 + +while true do + local users, repos, gopherholes = 0, 0, 0 + for user in fs.dir(gitdir) do + if user:sub(1,1) ~= "." then + users = users + 1 + for repo in fs.dir(gitdir..user) do + if repo:sub(1,1) ~= "." then + repos = repos + 1 + if repo == "gopherhole.git" then + gopherholes = gopherholes + 1 + end + end + end + end + end + socket.sleep(interval) + print(string.format("PUTVAL %s/exec-gitea/gitea_active_users interval=%d N:%d",hostname,interval,users)) + print(string.format("PUTVAL %s/exec-gitea/gitea_repositories interval=%d N:%d",hostname,interval,repos)) + print(string.format("PUTVAL %s/exec-gitea/gitea_gopherholes interval=%d N:%d",hostname,interval,gopherholes)) +end diff --git a/collectd/prosody-collectd.lua b/collectd/prosody-collectd.lua new file mode 100755 index 0000000..b0b9ac1 --- /dev/null +++ b/collectd/prosody-collectd.lua @@ -0,0 +1,17 @@ +#!/usr/bin/env lua +local rquri = "http://localhost:5280/serverinfo" + +local http = require "socket.http" +local socket = require "socket" + +local hostname = os.getenv("COLLECTD_HOSTNAME") or os.getenv("HOSTNAME") or "lain.church" +local interval = os.getenv("COLLECTD_INTERVAL") or 60 + +while true do + socket.sleep(interval) + local request = {http.request(rquri)} + local online,registered = request[1]:match('{"connected":(%d+),"registered":(%d+)}') + online,registered = tonumber(online),tonumber(registered) + print(string.format("PUTVAL %s/exec-prosody/prosody_connected interval=%d N:%d",hostname,interval,online)) + print(string.format("PUTVAL %s/exec-prosody/prosody_registered interval=%d N:%d",hostname,interval,registered)) +end diff --git a/collectd/types.custom.db b/collectd/types.custom.db new file mode 100644 index 0000000..7e39c9b --- /dev/null +++ b/collectd/types.custom.db @@ -0,0 +1,5 @@ +prosody_registered value:ABSOLUTE:0:U +prosody_connected value:ABSOLUTE:0:U +gitea_active_users value:ABSOLUTE:0:U +gitea_repositories value:ABSOLUTE:0:U +gitea_gopherholes value:ABSOLUTE:0:U