lain.church-fe/collectd/gitea-collectd.lua

30 lines
965 B
Lua

#!/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