jabber: add stats, automatic prosody restart
This commit is contained in:
parent
dce89059e3
commit
d5bff54d43
|
@ -40,6 +40,15 @@ in
|
||||||
# TODO: allowedSCTPPorts
|
# TODO: allowedSCTPPorts
|
||||||
};
|
};
|
||||||
|
|
||||||
|
c3d2 = {
|
||||||
|
isInHq = false;
|
||||||
|
hq.statistics.enable = true;
|
||||||
|
};
|
||||||
|
services.collectd.plugins.exec = ''
|
||||||
|
Exec "${config.services.collectd.user}" "${pkgs.ruby}/bin/ruby" "${./prosody-stats.rb}"
|
||||||
|
'';
|
||||||
|
systemd.services.collectd.requires = [ "prosody.service" ];
|
||||||
|
|
||||||
security.acme.certs."${domain}" = {
|
security.acme.certs."${domain}" = {
|
||||||
extraDomainNames = [
|
extraDomainNames = [
|
||||||
"chat.c3d2.de"
|
"chat.c3d2.de"
|
||||||
|
@ -70,7 +79,6 @@ in
|
||||||
};
|
};
|
||||||
} ];
|
} ];
|
||||||
};
|
};
|
||||||
#TODO: candy?
|
|
||||||
#TODO: txt records?
|
#TODO: txt records?
|
||||||
services.prosody = {
|
services.prosody = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
@ -87,10 +95,13 @@ in
|
||||||
websocket = true;
|
websocket = true;
|
||||||
http_files = true;
|
http_files = true;
|
||||||
|
|
||||||
|
admin_telnet = true;
|
||||||
announce = true;
|
announce = true;
|
||||||
mam = true;
|
mam = true;
|
||||||
carbons = true;
|
carbons = true;
|
||||||
|
proxy65 = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ssl = {
|
ssl = {
|
||||||
key = "/var/lib/acme/${domain}/key.pem";
|
key = "/var/lib/acme/${domain}/key.pem";
|
||||||
cert = "/var/lib/acme/${domain}/fullchain.pem";
|
cert = "/var/lib/acme/${domain}/fullchain.pem";
|
||||||
|
@ -106,7 +117,7 @@ in
|
||||||
|
|
||||||
c2sRequireEncryption = true;
|
c2sRequireEncryption = true;
|
||||||
s2sRequireEncryption = true;
|
s2sRequireEncryption = true;
|
||||||
|
|
||||||
virtualHosts = {
|
virtualHosts = {
|
||||||
"${domain}" = {
|
"${domain}" = {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
@ -181,8 +192,13 @@ in
|
||||||
-- proxy65_ports = { 5000 }
|
-- proxy65_ports = { 5000 }
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
# Allow binding ports <1024
|
systemd.services.prosody.serviceConfig = {
|
||||||
systemd.services.prosody.serviceConfig.AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
# Allow binding ports <1024
|
||||||
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
||||||
|
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = "3";
|
||||||
|
};
|
||||||
|
|
||||||
services.coturn = {
|
services.coturn = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require 'socket'
|
||||||
|
|
||||||
|
INTERVAL = ENV['COLLECTD_INTERVAL'].to_i
|
||||||
|
HOSTNAME = ENV['COLLECTD_HOSTNAME']
|
||||||
|
|
||||||
|
|
||||||
|
def recv sock
|
||||||
|
results = []
|
||||||
|
loop do
|
||||||
|
line = sock.gets
|
||||||
|
if line.start_with? "| OK:"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
results << line.chomp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
results
|
||||||
|
end
|
||||||
|
|
||||||
|
sock = TCPSocket.new "localhost", 5582
|
||||||
|
loop do
|
||||||
|
stats = {}
|
||||||
|
|
||||||
|
sock.puts "c2s:show()"
|
||||||
|
recv(sock).each do |line|
|
||||||
|
if line.start_with? "| "
|
||||||
|
encrypted = line.index " (encrypted)"
|
||||||
|
ipv6 = line.index " (IPv6)"
|
||||||
|
k = "c2s:#{encrypted ? 'encrypted' : 'unencrypted'}-#{ipv6 ? 'ipv6' : 'ipv4'}"
|
||||||
|
stats[k] = 0 unless stats[k]
|
||||||
|
stats[k] += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sock.puts "s2s:show()"
|
||||||
|
recv(sock).each do |line|
|
||||||
|
if line.start_with? "| "
|
||||||
|
out = if line.index "<-"
|
||||||
|
false
|
||||||
|
elsif line.index "->"
|
||||||
|
true
|
||||||
|
else
|
||||||
|
next
|
||||||
|
end
|
||||||
|
encrypted = line.index " (encrypted)"
|
||||||
|
ipv6 = line.index " (IPv6)"
|
||||||
|
k = "s2s-#{out ? 'out' : 'in'}:#{encrypted ? 'encrypted' : 'unencrypted'}-#{ipv6 ? 'ipv6' : 'ipv4'}"
|
||||||
|
stats[k] = 0 unless stats[k]
|
||||||
|
stats[k] += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
stats.each do |k,v|
|
||||||
|
k1, k2 = k.split(":", 2)
|
||||||
|
puts "PUTVAL \"#{HOSTNAME}/exec-prosody-#{k1}/current_connections-#{k2}\" interval=#{INTERVAL} N:#{v}"
|
||||||
|
end
|
||||||
|
|
||||||
|
ensure
|
||||||
|
sleep INTERVAL
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue