[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Condor-users] [?????]



John,

> What I want is something that looks the same as condor_status as
> normal.  The best way to do that is to use the condor-status output,
> then if someone compares the current condor_status with my web page,
> they will look the same.
> 
> My perl routines work with "ps", and other tabular outputs, they
> shouldn't have to have a patch in for [?????] which they do at
> present just so I can parse condor_status output.

I have been frustrated with the formatting of condor_status as well.

Looking at the source code it seems the problem is that the ActvtyTime
is printed with a "%s" format and the string is 12 characters long,
except in the case when it is undefined and the 7 character "[?????]"
value is used.  The Condor people could fix this by either padding
this value with 5 leading blanks or simply using a "%12s" format.

Below you will find a gawk script I use which exactly duplicates the
output from condor_status, but with the "%12s" format (actually there
is one small difference, condor_status sorts names in a case sensitive
manner, but its -sort option is case insensitve, go figure) I actually
use a further modified version which changes many of the field widths
to suit my needs (longer Name, shorthand OpSys/Arch, etc.).

Note that this script relies on ClassAd functions that are only
available in Condor 6.8/6.9.  I hope you find this of some use.

---

#!/bin/gawk -f
BEGIN \
{
   CMD = "condor_status"
#
# Add command line arguments here
#
   for (I = 1; I < ARGC; ++I) {
      CMD = CMD" '"gensub(/'/,"'\\\\''","g",ARGV[I])"'"
      if (substr("-format",1,length(ARGV[I])) == \
	  substr(ARGV[I],1,length("-format"))) {
	 FMT = 1
      }
   }
#
# Invoke as-is if a format was specified
#
   if (FMT) {
      system(CMD)
      exit
   }
#
# Otherwise format the parameters we need
#
   CMD = CMD" -format '%s\\t'" \
" 'ifThenElse(isUndefined(Name),\"[???????????]\",Name)'" \
	    " -format '%s\\t'" \
" 'ifThenElse(isUndefined(OpSys),\"[?????????]\",OpSys)'" \
	    " -format '%s\\t'" \
" 'ifThenElse(isUndefined(Arch),\"[????]\",Arch)'" \
	    " -format '%s\\t'" \
" 'ifThenElse(isUndefined(State),\"[????????]\",State)'" \
	    " -format '%s\\t'" \
" 'ifThenElse(isUndefined(Activity),\"[????????]\",Activity)'" \
	    " -format '%f\\t'" \
" 'ifThenElse(isUndefined(LoadAvg),-1,LoadAvg)'" \
	    " -format '%d\\t'" \
" 'ifThenElse(isUndefined(Memory),-1,Memory)'" \
	    " -format '%s\\n'" \
" 'ifThenElse(isUndefined(LastHeardFrom - EnteredCurrentActivity)," \
"\" [Unknown]\",interval(LastHeardFrom - EnteredCurrentActivity))'" \
	    " -sort OpSys" \
	    " -sort Arch" \
	    " -sort Machine" \
	    " -sort Name"
   FS = "\t"
   while (CMD | getline) {
      if (NF != 8) {
	 print
	 continue
      }
      if (!("T" in Total)) {
	 print ""
	 printf "%-13.13s %-11.11s %-6.6s %-10.10s %-10.10s %-6.6s %-4.4s  %s\n\n",
		"Name", "OpSys", "Arch", "State",
		"Activity", "LoadAvg", "Mem", "ActvtyTime"
      }
#
# Convert the non-string values to strings
#
      $6 = ($6 < 0) ? "[???]" : sprintf("%.3f",$6)
      $7 = ($7 < 0) ? "[??]" : sprintf("%4d",$7)
      printf "%-13.13s %-11.11s %-6.6s %-10.10s %-10.10s %s  %s%12s\n",
	      $1,      $2,      $3,    $4,      $5,      $6, $7, $8
#
# Keep track of the totals by Arch/OpSys
#
      Types[$3"/"$2]++
      Count[$3"/"$2,substr($4,1,1)]++
      Total["T"]++
      Total[substr($4,1,1)]++
   }
#
# Sort and print out the totals
#
   printf "%20s%6.6s %5.5s %7.7s %9.9s %7.7s %10.10s %8.8s\n\n",
	  "", "Total", "Owner", "Claimed",
	  "Unclaimed", "Matched", "Preempting", "Backfill"
   for (T in Types)
      Sort[++N] = T
   asort(Sort)
   for (I = 1; I <= N && T = Sort[I]; ++I)
      printf "%20s%6d %5d %7d %9d %7d %10d %8d\n",
	     T, Types[T], Count[T,"O"], Count[T,"C"],
	     Count[T,"U"], Count[T,"M"], Count[T,"P"], Count[T,"B"]
   printf "\n%20s%6d %5d %7d %9d %7d %10d %8d\n",
	  "Total", Total["T"], Total["O"], Total["C"],
	  Total["U"], Total["M"], Total["P"], Total["B"]
}

-- 
Daniel K. Forrest	Laboratory for Molecular and
forrest@xxxxxxxxxxxxx	Computational Genomics
(608) 262 - 9479	University of Wisconsin, Madison