示例#1
0
#!/usr/bin/python
"""Log currect active window to file.
You must have xdotool installed.
"""

import util

CMD = 'xwininfo -display :0 -id "$(xdotool getactivewindow)" | grep xwininfo'

def parse(out_str):
  #return out_str
  fields = out_str.split('"')
  return fields[-2]

val = parse(util.run(CMD))
print util.now_datetime(), val 
示例#2
0
#!/usr/bin/python
"Parse `uptime` to output current 5m CPU load to a file."

import util

def parse_uptime(uptime_str):
  fields = uptime_str.split()
  fields = [f.rstrip(',') for f in fields]
  vals = {
        'time'    : fields[0],
        'users'   : fields[-7],
        'load_1m' : fields[-3],
        'load_5m' : fields[-2],
        'load_15m': fields[-1],
        }
  if fields[3].startswith('day'):
    vals['updays'] = fields[2]
  else:
    vals['updays'] = 0
  return vals


uptime = util.run('uptime')
fields = parse_uptime(uptime)

print util.now_datetime(), fields['load_5m']

示例#3
0
    return float(unit[:-3])
  elif unit.endswith('MiB'):
    return float(unit[:-3])*1000.0
  elif unit.endswith('GiB'):
    return float(unit[:-3])* 1000.0 * 1000.0
  elif unit.endswith('B'):
    return float(unit[:-1])/1000.0

def parse_bmon(bmon_str):
  rxs = []
  txs = []
  for line in bmon_str.split('\n')[2:]:
    fields = line.split()
    rx = fields[1]
    tx = fields[3]
    rx = rescale_to_kib(rx)
    tx = rescale_to_kib(tx)
    rxs.append(rx)
    txs.append(tx)
  return (avg(rxs), avg(txs))


bmon = util.run(CMD)
(bw_in, bw_out) = parse_bmon(bmon)
bw_in = '%.2f' % bw_in
bw_out = '%.2f' % bw_out

now = util.now_datetime()
print '%s\tin\t%s' % (now, bw_in)
print '%s\tout\t%s' % (now, bw_out)