Changeset 560


Ignore:
Timestamp:
Dec 9, 2010, 11:22:32 PM (10 years ago)
Author:
zerodeux
Message:

jobq 0.8.2 released

Location:
jobq
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • jobq/NEWS

    r535 r560  
     1jobq 0.8.2
     2
     3    * jobq-stat would parse any logged stdout job output
     4    * jobq-{stat,profile} has a better --help
     5    * jobq-{stat,profile} accepts -u user option
     6    * jobq-{stat,profile} defaults to parsing /var/log/user.log
     7    * jobq-profile nows accepts a list of logfiles like jobq-stat
     8    * jobq-profile is now helpful when no data is found
     9
    110jobq 0.8.1
    211
  • jobq/TODO

    r457 r560  
    11* Job cancelation
    22* Queue runner list/stop
    3 * Interrupt idle 'sleep 5' to chain jobs immediatly
    43* Man page (--help gets bulky, and DFSG requires it)
    54* Check security issues wrt job files
  • jobq/debian/changelog

    r535 r560  
     1jobq (0.8.2) stable; urgency=low
     2
     3  * Upstream update
     4
     5 -- Vincent CARON <vcaron@bearstech.com>  Thu, 09 Dec 2010 23:20:25 +0100
     6
    17jobq (0.8.1) stable; urgency=low
    28
  • jobq/jobq

    r534 r560  
    2222
    2323PROGRAM=jobq
    24 VERSION=0.8.1
     24VERSION=0.8.2
    2525
    2626# Hardcoded value for now, should fit most people
    27 JOBPATH=/tmp/$PROGRAM-$LOGNAME
     27JOBPATH=/tmp/jobq-$LOGNAME
    2828
    2929
     
    4343add_job() {
    4444  set -e
     45  # Make sure the queue path exists so we can write our job file
    4546  mkdir -m 0700 -p $JOBPATH/$queue
    4647  cd $JOBPATH/$queue
     
    115116  # - --chdir PWD is needed to invoke $0 because s-s-d chdir to / as a default
    116117  /sbin/start-stop-daemon --quiet \
     118    --start --startas "$0" \
     119    --chdir "$PWD" \
     120    --background \
    117121    --make-pidfile --pidfile $pidfile \
    118     --chdir "$PWD" \
    119     --background --start --startas "$0" -- \
    120     --runner --queue "$queue"
     122    -- --runner --queue "$queue"
    121123  if [ $? = 1 ]; then
    122     # Daemon is already running, wake it up to process new job immediatly
    123     kill -USR1 $(cat "$pidfile")
     124    # Daemon is already running, wake it up (send USR1) to process new job immediatly
     125    /sbin/start-stop-daemon --quiet --stop --signal USR1 --pidfile $pidfile
    124126  fi
    125127  if [ $? != 0 ]; then
  • jobq/jobq-profile

    r535 r560  
    2626use Getopt::Long;
    2727
    28 my $program = 'jobq-stat';
    29 my $version = '0.8.1';
     28my $program = 'jobq-profile';
     29my $version = '0.8.2';
    3030
    3131my %job_by_id;
     
    3333my %jobcall;
    3434
    35 my $queue = 'default';
    36 GetOptions('q|queue=s' => \$queue) or die "Usage: $0 [-q queue] < /var/log/user.log";
     35sub usage {
     36    print STDERR <<EOF;
     37Usage: $0 [-u user] [-q queue] [/var/log/user.log] [...]
    3738
    38 my $ctx = $ENV{LOGNAME}."/$queue/";
     39Show number of calls and cumulated (wall clock) time for every job
     40run via jobq, sorted by cumulated time.
    3941
    40 while (<STDIN>) {
    41   if (/job\[$ctx(\d+)\]: start \(.*?\): (.*)/) {
    42     $job_by_id{$1} = $2;
    43     next;
    44   }
    45   if (/job\[$ctx(\d+)\]: done \(time:(\d+)/) {
    46     my $cmd = $job_by_id{$1};
    47     next if not defined $cmd;
    48     $jobtime{$cmd} += $2,
    49     $jobcall{$cmd}++;
    50     next;
    51   }
     42Since jobq sends statistics to the 'user' syslog facility, jobq-profile
     43defaults to parsing 'user.log'. The default user is the current user
     44(\$LOGNAME). The default queue is 'default'.
     45
     46EOF
     47    exit 1;
    5248}
    5349
    54 print  "Calls  Time(sec)  Command\n";
    55 printf("%5d  %9d  %s\n", $jobcall{$_}, $jobtime{$_}, $_) foreach sort { $jobtime{$b} - $jobtime{$a} } keys %jobtime;
     50my $queue = 'default';
     51my $user  = $ENV{LOGNAME};
     52usage() if not GetOptions(
     53    'u|user=s'  => \$user,
     54    'q|queue=s' => \$queue
     55);
     56
     57my @logfiles = @ARGV;
     58@logfiles = ('/var/log/user.log') if not @logfiles;
     59
     60my $ctx = "$user/$queue/";
     61
     62while (@logfiles) {
     63    my $logfile = shift @logfiles;
     64    open(my $log, '-|', 'zcat', '-f', $logfile) or warn "$logfile: $!";
     65
     66    while (<$log>) {
     67        if (/job\[$ctx(\d+)\]: start \(.*?\): (.*)/) {
     68            $job_by_id{$1} = $2;
     69            next;
     70        }
     71        if (/job\[$ctx(\d+)\]: done \(time:(\d+)/) {
     72            my $cmd = $job_by_id{$1};
     73            next if not defined $cmd;
     74            $jobtime{$cmd} += $2,
     75            $jobcall{$cmd}++;
     76            next;
     77        }
     78    }
     79
     80    close($log) if $log;
     81}
     82
     83if (not keys %jobtime) {
     84    print "No jobq event found for user '$user' and queue '$queue'\n";
     85    exit;
     86}
     87print  "Calls Time(sec) Command\n";
     88printf("%5d%9d  %s\n", $jobcall{$_}, $jobtime{$_}, $_) foreach sort { $jobtime{$b} - $jobtime{$a} } keys %jobtime;
  • jobq/jobq-stat

    r535 r560  
    44# can fire an automatic report after the usual log rotation with:
    55#
    6 #   jobq-stat /var/log/user.log.0 | mail -s "jobq daily report" admin@foo.com
     6#   jobq-stat /var/log/user.log.1 | mail -s "jobq daily report" admin@foo.com
    77#
    88# ... or get the current picture from current log with:
     
    2626
    2727PROGRAM=jobq-stat
    28 VERSION=0.8.1
    29 
    30 # Hardcoded value for now, must be sync'ed with jobq's.
    31 JOBPATH=/tmp/jobq-$LOGNAME
     28VERSION=0.8.2
    3229
    3330
    3431help() {
    35   echo "Usage: $PROGRAM [-q <queue>] logfiles..."
     32  cat <<EOF >&2
     33Usage: $PROGRAM [-u user] [-q <queue>] [/var/log/user.log] [...]
     34
     35Show statistics for the given job queue: number of pending jobs,
     36run jobs, delays, etc.
     37
     38Since jobq sends statistics to the 'user' syslog facility, jobq-stat
     39defaults to parsing 'user.log'. The default user is the current user
     40(\$LOGNAME). The default queue is 'default'.
     41
     42EOF
    3643  exit 1
    3744}
     
    4249}
    4350
     51user="$LOGNAME"
    4452queue=default
    4553
     
    4755while [ $parse_opt != "done"  ] ; do
    4856  case "$1" in
     57    -u|--user)    shift; user="$1"; shift;;
    4958    -q|--queue)   shift; queue="$1"; shift;;
    5059    -h|--help)    help;;
     
    5867logfiles="$*"
    5968if [ -z "$logfiles" ]; then
    60   help
     69  logfiles=/var/log/user.log
    6170fi
    6271
    63 cd $JOBPATH/$queue 2>/dev/null || { echo "No such job queue '$queue'" >&2; exit 1; }
     72# Hardcoded value for now, must be sync'ed with jobq's.
     73JOBPATH=/tmp/jobq-$user
     74cd $JOBPATH/$queue 2>/dev/null || { echo "No such job queue '$queue' for user '$user'" >&2; exit 1; }
    6475
    6576now=$(date +%s)
     
    7384todo_max=0
    7485done_max=0
    75 zegrep " job\[$LOGNAME/$queue/[0-9]+\]: " $logfiles | {
     86zegrep " job\[$user/$queue/[0-9]+\]: (start|stop) " $logfiles | {
    7687  while read l; do
    7788    _done=$(echo "$l" | sed -ne 's/.*: done (time:\([0-9]\+\) sec.*/\1/p')
     
    127138
    128139echo
    129 zcat -f $logfiles | jobq-profile -q "$queue"
     140jobq-profile -u "$user" -q "$queue" $logfiles
    130141
    131142if [ $queue_len -gt 0 ]; then
Note: See TracChangeset for help on using the changeset viewer.