Networker

Re: [Networker] How to count concurrent sessions (scripted)

2011-03-14 15:51:03
Subject: Re: [Networker] How to count concurrent sessions (scripted)
From: Yaron Zabary <yaron AT ARISTO.TAU.AC DOT IL>
To: NETWORKER AT LISTSERV.TEMPLE DOT EDU
Date: Mon, 14 Mar 2011 21:49:22 +0200
  You could feed nsradmin with:

. type: NSR
show session
print


 Or use the following perl script (watch out for broken lines):

#!/usr/bin/perl

use lib "/usr/local/TAUSRC/Local/ToolBox";
use Nsradmin;

set_nsradmin("/usr/sbin/nsradmin");

$server = "legato";
$query  = "type: NSR ";
$show   = "session";
$options = "";

@reslist = query($server, $query, $show, $options);

#
# A reslist is a list of resources.  Resources are a
# hash of attributes, which have a name and value lists.
#

foreach $res (@reslist) {
      %attrlist = %{$res};
      $attr = "session";
      @vallist = @{$attrlist{$attr}};
      foreach $val (@vallist) {
         printf "$val\n";
      }
}


  Where Nsradmin.pm is

# cat /usr/local/TAUSRC/Local/ToolBox/Nsradmin.pm

package Nsradmin;
require Exporter;
@ISA    = qw(Exporter);
@EXPORT = qw(
        set_nsradmin
        create_tmpfile
        query
        write_lines
        $nsradmin
);

# Courtesy of Byron Servies bservies AT PACANG DOT COM

$nsradmin = "nsradmin";

1;

sub set_nsradmin {
        my ($path) = @_;
        $nsradmin = $path;
}

sub query {
        my ($server, $query, $show, $options) = @_;
        my @lines;
        my @reslist;
        my @reslines;
        my %attrlist;
        my $cmd;
        my $append;
        my $append_next;

        # Prep the command to change display options
        $options = "option $options";

        # Prep the command for which attributes to show
        $show = "show $show";

        # Prep the command for the query to perform
        $query = "print $query";

        # Write the query to a temporary file
        $queryfile = &write_lines($options, $show, $query);

        # Determine the command to execute
        $cmd = "$nsradmin -s $server -i $queryfile";

        # Execute the query and parse the results
        $append = 0;
        open CMD, "$cmd |" || die "could not execute \"$cmd\"";
        while (<CMD>) {
                # Skip the option output
                next if (/^Dynamic|Hidden|Resource/o);

                # Skip the list of display options
                if (/^Display options:/) {
                        # Read the next 3 lines
                        $_ = <CMD>;
                        $_ = <CMD>;
                        $_ = <CMD>;
                        next;
                }

                # Skip any show lines
                next if (/^Will show all attributes/);

                if ($append == 0 && /^\s*$/) {
                        #
# Blank lines start a new resource, but only if we are not
                        # searching for the end of the previous attribute.
                        #
                        if (scalar @lines > 0) {
                                # The lines array represents a resource
                                push @reslines, [ @lines ];
                                @lines = ();
                        }
                        next;
                }

# Eliminate leading and trailing whitespace only if we are not
                # still searching for the end of an
                s/^\s+// unless ($append);
                s/\s+$// unless ($append);

                if (/\\\s*$/) {
# Remove the backslash from the input line if it exists
                        s/\\\s*$//;
                        $append_next = 1;
                }

# Determine if this line should be added to the previous line or not
                if ($append != 0) {
                        # Append this line to the last line in the array
                        $lines[$#lines] .= $_;
                } elsif ($#lines != -1 && $lines[$#lines] !~ /;\s*/) {
                        #
                        # The previous line does not end with a semi-colon.
                        # Add the current line to the previous line
                        #
                        $lines[$#lines] .= $_;
                } else {
                        # Add the ordinary line to the list of lines
                        push @lines, $_;
                }

                if ($lines[$#lines] !~ /;\s*/o) {
                        #
# The current line does not end with a semi-colon. The # next line must be appended until one is found and the
                        # value list is complete.
                        #
                        $append_next = 1;
                }
                $append = $append_next;
                $append_next = 0;
        }

        #
# Append the most recent set of lines to the results if there was no
        # blank line at the end of the output
        #
        if (scalar @lines > 0) {
                push @reslines, [ @lines ];
                @lines = ();
        }

        # Delete the query file.  The command pipeline closes itself.
        unlink $queryfile;

        #
# Separete the lines of each resource into a list of hashes. The hash
        # keys are the attribute names and their values are a list of the
        # attributes values.
        #
        foreach $lines (@reslines) {
                %attrlist = ();

# The lines are in and compressed. Now separated them into a hash
                foreach $line (@$lines) {
                        if ($line =~ /(^[\w\s]+):(.*)$/ms) {
                                $attrname = $1;
                                $2 =~ /^\s*(.*);$/ms;
                                $value = $1;

                                # The following loop is from the book
# "Mastering Regular Expressions", page 205. # Jeffrey Friedl, O'Reilly & Associates, Inc.
                                #
                                # It was modified to use the delimiter
                                # (, ) instead of a simle comma for use
                                # with RAP.
                                #
                                @vallist = ();
while ($value =~ m/"([^"\\]*(\\.[^"\\]*)*)"(,\s+)?|([^,]+)(,\s+)?|(,\s+)/g) { push(@vallist, defined($1) ? $1 : $4);
                                }
                                push(@vallist, undef) if $value =~ m/,$/;


                                #
                                # Make sure the attribute is in the array,
# regardless of how many values it may or may
                                # not have.
                                #
                                $attrlist{$attrname} = ();
                                foreach $value (@vallist) {
                                        #
# strip leading and trailing whitespace from
                                        # all values
                                        #
                                        $value =~ s/^\s+//;
                                        $value =~ s/\s+$//;

                                        # Skip empty values
                                        next if (length $value == 0);
push @{$attrlist{$attrname}}, $value;
                                }
                        }
                }

                # Add the attrlist hash to the resource list
                push @reslist, { %attrlist };

        }

        return @reslist;
}

sub create_tmpfile {
        my $filename;

        if (defined $ENV{TMPDIR}) {
                $filename = $ENV{TMPDIR} . "/" . "tmp$$";
        } elsif (defined $ENV{TMP}) {
                $filename = $ENV{TMP} . "/" . "tmp$$";
        } else {
                $filename = "/tmp/" . "tmp$$";
        }
}

sub write_lines {
        my @lines = @_;

        $tmpfile = &create_tmpfile;

open TMPFILE, "> $tmpfile" || die "could open $tmpfile for writting";
        print TMPFILE join "\n", @lines;
        print TMPFILE "\n";
        close TMPFILE;

        return $tmpfile;
}

1;



On 03/14/2011 07:13 PM, Will Parsons wrote:
Hi All,

Networker 7.6.0
Solaris10
500ish clients
4,000 save sets a night

We've had some issues over the past few weeks which I've finally pinned
down to server parallelism being set too low. I've temporarily resolved
it by adding two storage node licenses and increasing the server
parallelism from 96 to 160.

Before I spend too long digging through the tools, has anyone already
got a good command line way to get the number of current sessions that
NetWorker thinks are running or eligible to run? I'm thinking that
/usr/sbin/jobquery is my friend here, but I've yet to figure out which
type and/or status I need to be counting to see how far above "server
parallelism" I'm asking the system to go.

I know Thierry's got a way to tally up what has happened historically
(make a very nice display in nsr_reporter), but I'm looking for a
current sessions count, so that I can figure out if it's server
parallelism that's stopping the system from progressing. (and dump it in
my database for long term reference)

Many thanks
Will



To sign off this list, send email to listserv AT listserv.temple DOT edu and type 
"signoff networker" in the body of the email. Please write to networker-request 
AT listserv.temple DOT edu if you have any problems with this list. You can access the 
archives at http://listserv.temple.edu/archives/networker.html or
via RSS at http://listserv.temple.edu/cgi-bin/wa?RSS&L=NETWORKER

<Prev in Thread] Current Thread [Next in Thread>