package POEDaemon::System::Stats; use strict; use warnings FATAL => 'all'; no warnings 'redefine'; use Data::Dumper; use POE; use POEDaemon; sub states { return $_[0], [qw( stats )]; } sub stats { my $heap = $_[HEAP]; my $poesession_mode = cfg->{poesession_mode} || ''; unless ($poesession_mode eq 'shcp') { log_enabled && logline "\nHEAP:\n%s", Dumper $heap; } my @out; push @out, '> children (id, name, prog)'; while (my ($id, $child) = each %{$heap->{wheel_run}->{children_by_wid} || {}}) { push @out, sprintf "%5s %15s %s", $id || '', $child->{args}->{name} || '', join('|', @{$child->{args}->{prog} || []}) || ''; } push @out, '> servers (id, proto, family, addr, port, type)'; while (my ($id, $server) = each %{$heap->{tcpserver}->{servers} || {}}) { my @extra; push @extra, 'SSL' if $server->{ssl}; push @extra, 'HTTP' if $server->{http}; push @out, sprintf "%5s %5s %5s %10s %5s%s", $id || '', $server->{socket_protocol} || '', $server->{sockinfo_local}->{family} || '', $server->{sockinfo_local}->{addr} || '', $server->{sockinfo_local}->{port} || '', (@extra ? sprintf " %s", join ' ', @extra : ''); } push @out, '> banlist (addr, reason)'; while (my ($addr, $item) = each %{$heap->{tcpserver}->{client_banlist} || {}}) { push @out, sprintf "%34s %s", $addr || '', $item->{reason} || ''; } push @out, '> clients (id, addr, port, conntime, type, rtt)'; while (my ($id, $client) = each %{$heap->{tcpserver}->{connections} || {}}) { my ($conntime, @extra); my $conn_ts = $client->{connect_time}; if ($conn_ts && $conn_ts =~ /^\d+(?:\.\d+)?$/) { $conntime = concise_duration time_hires - $conn_ts; } push @extra, 'SSL' if $client->{ssl}; push @extra, 'HTTP' if $client->{http}; push @extra, 'WS' if $client->{websocket}; foreach (qw(rtt rtt_min rtt_max)) { my $name = $_; $name =~ s/^rtt$/last/i; $name =~ s/^rtt_//gi; my $rtt = $client->{sprintf "%s_%s", $client->{websocket} ? 'websocket' : 'poeclient', $_}; next unless $rtt; push @extra, sprintf "%s=%.3fms", $name, $rtt * 1000; } push @out, sprintf "%5s %34s %5s %7s%s", $id || '', $client->{client_addr} || '', $client->{client_port} || '', $conntime || '', (@extra ? sprintf " %s", join ' ', @extra : ''); } push @out, '> cache (url, content-type, size)'; while (my ($url, $item) = each %{$heap->{httpclient}->{cache} || {}}) { push @out, sprintf "%-70s %10s %10s", $url || '', $item->{content_type} || '', format_bytes(length($item->{content} || '')); } push @out, '> sessions (number, addr)'; { my $i = 0; while (my ($id, $session) = each %{$heap->{shcp}->{sessions} || {}}) { push @out, sprintf "%5s %s", ++$i || '', $session->{client_addr} || ''; } } push @out, sprintf "> reloads %s", $heap->{reload}->{count} || ''; log_enabled && console_output sprintf "%s\n%s\n%s", '-' x 80, join("\n", @out), '-' x 80; } 1;