wrote some scripts to record stats of various services

This commit is contained in:
XeonSquared 2019-09-26 04:35:56 -04:00
parent 23b4043620
commit 19ebd99941
3 changed files with 51 additions and 0 deletions

29
collectd/gitea-collectd.lua Executable file
View File

@ -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

17
collectd/prosody-collectd.lua Executable file
View File

@ -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

5
collectd/types.custom.db Normal file
View File

@ -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