Scripts

Script for extracting the maximum hourly transfer rate, latency and quality over a certain link.

#!/usr/bin/python
#
import sys,os.path
import string,time
import urllib,urllib2
import xml.dom.minidom
from xml.dom.minidom import Node


def GetTransferResults(fromsite,tosite,nfiles,starttime,delta=86400):
  url="https://cmsweb.cern.ch/phedex/datasvc/xml/debug/TransferHistory?from="+fromsite+"&to="+tosite+"&binwidth=300&starttime="+str(starttime)+"&endtime="+str(int(starttime)+int(delta))
  xmldata = urllib2.urlopen(url).read() 
  dom = xml.dom.minidom.parseString(xmldata) 

  done={}
  fail={}
  for node in dom.getElementsByTagName('transfer'): 
    done_files=node.attributes["done_files"].value
    fail_files=node.attributes["fail_files"].value
    time_bin=node.attributes["timebin"].value
    done[time_bin]=done_files
    fail[time_bin]=fail_files

  sumdone=0
  sumfail=0
  lastkey=0
  now=time.ctime()
  for key in sorted(done.iterkeys()):
    sumdone+=int(str(done[key]))
    sumfail+=int(str(fail[key]))
    if ( sumdone >= nfiles ) :
      lastkey=int(str(key))
      break
    if ( key > now ) :
      break

  url2="https://cmsweb.cern.ch/phedex/datasvc/xml/debug/TransferHistory?from="+fromsite+"&to="+tosite+"&binwidth=3600&starttime="+str(starttime)+"&endtime="+str(lastkey)
  xmldata2 = urllib2.urlopen(url2).read() 
  dom2 = xml.dom.minidom.parseString(xmldata2) 
  maxrate=0.
  for node in dom2.getElementsByTagName('transfer'): 
    rate=float(str(node.attributes["rate"].value))
    if ( rate > maxrate ) :
      maxrate=rate

  maxrate/=(1024.*1024)
  latency=float(int(lastkey)-int(starttime))/3600.
  if latency < 0 :
    latency=-1
  try :
    quality=float(sumdone)/float(sumdone+sumfail)*100
  except ZeroDivisionError :
    quality=-1

  print sumdone, "files completed"
  print("%.1f" % maxrate),"MiB/s"
  print("%.1f" % latency),"h"
  print("%.1f" % quality),"%"

  return

fromsite=sys.argv[1]
tosite=sys.argv[2]
nfiles=sys.argv[3]
starttime=sys.argv[4]
GetTransferResults(fromsite,tosite,nfiles,starttime)

-- JamesLetts - 2011/05/17

Edit | Attach | Print version | History: r9 | r7 < r6 < r5 < r4 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r5 - 2011/05/21 - 03:37:56 - JamesLetts
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback