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
1 changed files with 32 additions and 21 deletions

View File

@ -19,37 +19,48 @@ 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)"
k = "c2s:#{encrypted ? 'encrypted' : 'unencrypted'}-#{ipv6 ? 'ipv6' : 'ipv4'}"
stats[k] = 0 unless stats[k]
stats[k] += 1
end
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
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
out = if line.index "<-"
false
elsif line.index "->"
true
else
next
end
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
stats.each do |k,v|