]> dxcluster.net Git - spider.git/commitdiff
sh/cl and dmesg changes
authorDirk Koopman <djk@tobit.co.uk>
Sat, 25 Apr 2020 22:33:09 +0000 (23:33 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Sat, 25 Apr 2020 22:33:09 +0000 (23:33 +0100)
Add max no of local users seen since node start
Add ability to show last n lines of the debug ring buffer

Changes
cmd/show/cluster.pl
cmd/show/debug_ring.pl
perl/DXCommandmode.pm
perl/DXDebug.pm
perl/DXProt.pm
perl/Messages
perl/Route.pm

diff --git a/Changes b/Changes
index 6f79cd19e1fcf710cd9105f41fbbb8dcd74fb5a0..12c44037d0256e8640d044cc303b35bdfcc8cf52 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+25Apr20=======================================================================
+1. Add maximum no of users on node to show/cluster.
+2. Add ability to show last n lines of debugging ring buffer.
 24Apr20=======================================================================
 1. Add 'progress' debugging for showing that stuff is happening in nologchan
    a.k.a ringbuffer only mode. 
index 066ef7bf4c8424b1d17ad40fef1e372badf5dbe5..ea137856504d369cfb90b31789edf5369a9fe988 100644 (file)
@@ -1,4 +1,9 @@
 #
 # show some statistics
 #
-return (1, Route::cluster() );
+
+my $self = shift;
+
+my ($nodes, $tot, $users, $maxlocalusers, $maxusers, $uptime, $localnodes) = Route::cluster();
+
+return (1, $self->msg('cluster', $localnodes, $nodes, $users, $tot, $maxlocalusers, $maxusers, $uptime));
index 9a2eb01a3334f3e5b13803674431f6f11c0981f3..272da35c2bb7d69ca86a07f391c5d7e33ac146d8 100644 (file)
@@ -7,7 +7,15 @@ my $self = shift;
 my $line = shift;;
 return (1, $self->msg('e5')) unless $self->priv >= 9;
 
-DXDebug::dbgprintring();
-DXDebug::dbgclearring() if $line =~ /^clear$/;
+my @args = split /\s+/, $line;
+my $n;
+my $doclear;
+
+for (@args) {
+       $n = 0+$_ if /^\d+$/;
+       $doclear++ if /^clear$/;
+}
+DXDebug::dbgprintring($n);
+DXDebug::dbgclearring() if $doclear;
 
 return (1, 'Contents of debug ring buffer logged. View with watchdbg.');
index 74e53b10b1547a9af6cd729903b7397d33d26ea1..6306b7fbed905902abea96f23d9a14c219e98e31 100644 (file)
@@ -48,7 +48,7 @@ use Mojo::UserAgent;
 
 use strict;
 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug
-       $maxbadcount $msgpolltime $default_pagelth $cmdimportdir);
+       $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers);
 
 %Cache = ();                                   # cache of dynamically loaded routine's mod times
 %cmd_cache = ();                               # cache of short names
@@ -59,7 +59,8 @@ $maxbadcount = 3;                             # no of bad words allowed before disconnection
 $msgpolltime = 3600;                   # the time between polls for new messages 
 $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing command scripts 
                                           # this does not exist as default, you need to create it manually
-#
+$users = 0;                                      # no of users on this node currently
+$maxusers = 0;                           # max no users on this node for this run
 
 #
 # obtain a new connection this is derived from dxchannel
@@ -549,7 +550,10 @@ sub run_cmd
                                }
                                my $t0 = [gettimeofday];
                                eval { @ans = &{"${package}::handle"}($self, $args) };
-                               return (DXDebug::shortmess($@)) if $@;
+                               if ($@) {
+                                       dbgprintring(25);
+                                       return (DXDebug::shortmess($@));
+                               }
                                if (isdbg('progress')) {
                                        my $msecs = _diffms($t0);
                                        my $s = "CMD: '$cmd $args' by $call ip: $self->{hostname} ${msecs}mS";
@@ -587,7 +591,8 @@ sub process
        my $t = time;
        my @dxchan = DXChannel::get_all();
        my $dxchan;
-       
+
+       $users = 0;
        foreach $dxchan (@dxchan) {
                next unless $dxchan->is_user;  
        
@@ -602,6 +607,8 @@ sub process
                        $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
                        $dxchan->t($t);
                }
+               ++$users;
+               $maxusers = $users if $users > $maxusers;
        }
 
        while (my ($k, $v) = each %nothereslug) {
@@ -692,7 +699,7 @@ sub broadcast
 # gimme all the users
 sub get_all
 {
-       return grep {$_->is_user} DXChannel::get_all();
+       goto &DXChannel::get_all_users;
 }
 
 # run a script for this user
@@ -1304,7 +1311,14 @@ sub spawn_cmd
        no strict 'refs';
 
        # just behave normally if something has set the "one-shot" _nospawn in the channel
-       return ($cmdref->(@$args)) if $self->{_nospawn};
+       if ($self->{_nospawn}) {
+               eval { @out = $cmdref->(@$args); };
+               if ($@) {
+                       DXDebug::dbgprintring(25);
+                       push @out, DXDebug::shortmess($@);
+               }
+               return @out;
+       }
        
        my $fc = Mojo::IOLoop::Subprocess->new;
 #      $fc->serializer(\&encode_json);
@@ -1312,13 +1326,17 @@ sub spawn_cmd
        $fc->run(
                         sub {
                                 my $subpro = shift;
-                                if (isdbg('spawn_cmd')) {
+                                if (isdbg('progress')) {
                                         my $s = "line: $line";
                                         $s .= ", args: " . join(', ', @$args) if $args && @$args;
+                                        dbg($s);
+                                }
+                                eval { @out = $cmdref->(@$args); };
+                                if ($@) {
+                                        DXDebug::dbgprintring(25);
+                                        push @out, DXDebug::shortmess($@);
                                 }
-                                my @res = $cmdref->(@$args);
-#                               diffms("rcmd from $call 1", $line, $t0, scalar @res) if isdbg('chan');
-                                return @res;
+                                return @out;
                         },
 #                       $args,
                         sub {
@@ -1349,5 +1367,9 @@ sub spawn_cmd
        return @out;
 }
 
+sub user_count
+{
+       return ($users, $maxusers);
+}
 1;
 __END__
index 634bf97211bda5e8d70cb48621e69059342dffda..947923f2d4a4acb499f1d9b2fc5ef90a58809c08 100644 (file)
@@ -52,14 +52,14 @@ if (!defined $DB::VERSION) {
        local $^W=0;
        eval qq( sub confess { 
            \$SIG{__DIE__} = 'DEFAULT'; 
-        DXDebug::dbgprintring() if DXDebug('nologchan');
+        DXDebug::dbgprintring() if DXDebug::isdbg('nologchan');
         DXDebug::dbg(\$@);
                DXDebug::dbg(Carp::shortmess(\@_));
            exit(-1); 
        }
        sub croak { 
                \$SIG{__DIE__} = 'DEFAULT'; 
-        DXDebug::dbgprintring() if DXDebug('nologchan');
+        DXDebug::dbgprintring() if DXDebug::isdbg('nologchan');
         DXDebug::dbg(\$@);
                DXDebug::dbg(Carp::longmess(\@_));
                exit(-1); 
@@ -217,16 +217,18 @@ sub longmess
 sub dbgprintring
 {
        return unless $fp;
-       my $count = shift || $dbgringlth+1;
+       my $count = shift;
        my $first;
        my $l;
-       for ( ; $count > 0 && ($l = shift @dbgring); --$count) {
-               my ($t, $str) = split /\^/, $l, 2;
+       my $i = defined $count ? @dbgring-$count : 0;
+       $count = @dbgring;
+       for ( ; $i < $count; ++$i) {
+               my ($t, $str) = split /\^/, $dbgring[$i], 2;
                next unless $t;
                my $lt = time;
                unless ($first) {
                        $fp->writeunix($lt, "$lt^###");
-                       $fp->writeunix($lt, "$lt^### RINGBUFFER START");
+                       $fp->writeunix($lt, "$lt^### RINGBUFFER START at line $i (zero base)");
                        $fp->writeunix($lt, "$lt^###");
                        $first = $t;
                }
index 6d20b887407984956129ac06a22656078c6330a7..1f631120800c42db0de01096540941b08d981d48 100644 (file)
@@ -1218,21 +1218,31 @@ sub spawn_cmd
        my $fc = Mojo::IOLoop::Subprocess->new;
 
        # just behave normally if something has set the "one-shot" _nospawn in the channel
-       return ($cmdref->(@$args)) if $self->{_nospawn};
+       if ($self->{_nospawn}) {
+               eval { @out = $cmdref->(@$args); };
+               if ($@) {
+                       DXDebug::dbgprintring(25);
+                       push @out, DXDebug::shortmess($@);
+               }
+               return @out;
+       }
 
        #       $fc->serializer(\&encode_json);
 #      $fc->deserializer(\&decode_json);
        $fc->run(
                         sub {
                                 my $subpro = shift;
-                                if (isdbg('chan')) {
+                                if (isdbg('progress')) {
                                         my $s = "line: $line";
                                         $s .= ", args: " . join(', ', @$args) if $args && @$args;
+                                        dbg($s);
                                 }
-
-                                my @res = $cmdref->(@$args);
-#                               diffms("by $call 1", $line, $t0, scalar @res) if isdbg('chan');
-                                return @res;
+                                eval { @out = $cmdref->(@$args); };
+                                if ($@) {
+                                        DXDebug::dbgprintring(25);
+                                        push @out, DXDebug::shortmess($@);
+                                }
+                                return @out;
                         },
 #                       $args,
                         sub {
index 625fd5eeda12be66d50d09fe5584e926d70a2759..6c5f529b7947e325a89bdd88b05139a4b2917c53 100644 (file)
@@ -34,6 +34,7 @@ package DXM;
                                chatinst => 'Entering Chatmode on $_[0], /EX to end, /<cmd> to run a command',
                                chatprompt => 'Chat ($_[0])>',
                                chattoomany => 'Not allowed, already in $_[1], use /chat $_[0]',
+                               cluster => ' Nodes: $_[0] / $_[1] total  Users: $_[2] / $_[3] total  Max Users: $_[4] / $_[5] total\nUptime: $_[6]',
                                conother => 'Sorry $_[0] you are connected to me on another port',
                                concluster => 'Sorry $_[0] you are already connected elsewhere on the cluster (on $_[1])',
                                contomany => 'Sorry $_[0] but you are already connected to $_[1] other nodes (on $_[2])',
index c43fd34d7dc1cad6e93a0baec8504bedf0023de6..6c8c44a858653adc507374f7dea9099c6c2ff39f 100644 (file)
@@ -270,11 +270,14 @@ sub cluster
 {
        my $nodes = Route::Node::count();
        my $tot = Route::User::count();
-       my $users = scalar DXCommandmode::get_all();
+       my ($users, $maxlocalusers) = DXCommandmode::user_count();
        my $maxusers = Route::User::max();
        my $uptime = main::uptime();
+       my $localnodes = $DXChannel::count - $users;
+       
+       return ($nodes, $tot, $users, $maxlocalusers, $maxusers, $uptime, $localnodes);
+       
 
-       return " $nodes nodes, $users local / $tot total users  Max users $maxusers  Uptime $uptime";
 }
 
 #