I am trying to create a dictionary using data produced by a load balancing admin tool and aggregate the results.

 

 

When I invoke the tool from within the shell (‘sudo ~/ZLBbalctl --action="" the following output is produced:

 

Load Balancer 1 usage, over the last 30 seconds

Port 80, rules - /(nol)|(ws)

  server001      alive 18.1%     2 requests/s 14536543 total

  server002      alive 43.1%     7 requests/s 14842618 total

  server003      alive 21.2%     2 requests/s 14884487 total

  server004      alive 17.3%     2 requests/s 15092053 total

 

 

Load Balancer 2 usage, over the last 30 seconds

Port 80, rules - /(nol)|(ws)

  server001      alive 11.6%     2 requests/s 14482578 total

  server002      alive 35.6%     9 requests/s 14820991 total

  server003      alive 28.7%     6 requests/s 14928991 total

  server004      alive 23.7%     5 requests/s 15147525 total

 

 

 

I have managed to get something close to what I’m looking for using lists i.e. the aggregate of the fourth column (requests/s)

 

lbstat = commands.getoutput("sudo ~/ZLBbalctl --action="" | awk '$1 ~ /^server00/ { print $4 }'") 

rLst = lbstat.split('\n')

rLst = [ int(rLst[i]) for i in range(len(rLst)) ]

rTotal = reduce(operator.add, rLst)

 

However here’s what I’m now trying to do:

 

1)       Not have to rely on using awk at all.

 

 

2)       Create a dictionary with server names for keys e.g. server001, server002 etc and the aggregate of the request for that server as the value part of the pairing.

 

 

I got this far with part 1)

 

lbstat = commands.getoutput("sudo ~/ZLBbalctl --action="">

tmpLst = lbstat.split('\n')

 

rLst = []

for i in tmpLst:

    m = re.search(' server[0-9]+', i)

    if m:

        rLst.append(i)

 

for i in rLst:

        print i, type(i)

 

 

 

  server001      alive 22.3%     6 requests/s 14527762 total <type 'str'>

  server002      alive 23.5%     7 requests/s 14833265 total <type 'str'>

  server003      alive 38.2%    14 requests/s 14872750 total <type 'str'>

  server004      alive 15.6%     4 requests/s 15083443 total <type 'str'>

  server001      alive 24.1%     8 requests/s 14473672 total <type 'str'>

  server002      alive 23.2%     7 requests/s 14810866 total <type 'str'>

  server003      alive 30.2%     8 requests/s 14918322 total <type 'str'>

  server004      alive 22.1%     6 requests/s 15137847 total <type 'str'>

 

 

 

 

At this point I ran out of ideas and began to think that there must be something fundamentally wrong with my approach. Not least of my concerns was the fact that I needed integers and these were strings.

 

Any help would be much appreciated.

 

Regards,

 

Paul

 

 

 

 

 

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to