jabber: update prosody-stats.rb to newer prosody version

This commit is contained in:
Astro 2022-06-04 01:16:42 +02:00
parent dbe42641d8
commit bb2afd3394

View File

@ -19,24 +19,36 @@ def recv sock
results
end
=begin
def parse_table lines
fields = lines.shift.split(/\|/).collect { |s| s.strip }
p :fields => fields
lines.collect { |s|
data = s.split(/\|/).collect { |s| s.strip }
obj = {}
fields.each_with_index do |field,i|
obj[field] = data[i]
end
obj
}
end
=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)"
encrypted = line.index(" secure ") or line.index(" TLSv")
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 "->"
@ -44,13 +56,12 @@ loop do
else
next
end
encrypted = line.index " (encrypted)"
ipv6 = line.index " (IPv6)"
encrypted = line.index " TLSv"
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)