statgen / gotcloud

Genomes on the Cloud, Mapping & Variant Calling Pipelines
http://genome.sph.umich.edu/wiki/GotCloud
32 stars 19 forks source link

Track job resource usage on Flux #19

Closed pjvandehaar closed 8 years ago

pjvandehaar commented 8 years ago
pjvandehaar commented 8 years ago

Here's python to retrieve emails and when they were sent:

from __future__ import print_function
import imaplib, getpass, email, dateutil.parser, sys
m = imaplib.IMAP4_SSL('imap.gmail.com')
m.login('<your_email_here>@gmail.com', getpass.getpass())
# use m.list() to find the right mailbox
m.select('"[Gmail]/All Mail"') # Beware the awkward doubled quotes
rv = m.search(None, 
     '(SUBJECT "PBS JOB") (SUBJECT "Execution terminated") (FROM "hpc-support")')
message_ids = rv[1][0].split()
rv = m.fetch(message_ids[0], '(RFC822)')
if sys.version_info.major > 2:
    msg = email.message_from_bytes(rv[1][0][1])
else:
    msg = email.message_from_string(rv[1][0][1])
print(dateutil.parser.parse(msg['Date']))
for line in msg.get_payload().split('\n'):
    line = line.strip() # I hate "\r"
    for line_start in ['resources_used.cput=', 'resources_used.mem=', 
            'resources_used.walltime=', 'Job Name:', 'PBS Job Id:']:
        if line.startswith(line_start):
            print(line_start, 'is', line.lstrip(line_start).strip())
pjvandehaar commented 8 years ago

For an MVP:

ascii plotting libraries:

Raw gnuplot works:

import subprocess, random
rows, columns = (int(r) for r in subprocess.check_output([b'stty', b'size']).split())

data1 = [(x*0.1, random.gauss(40,3) - 30*(x/100.)**2) for x in range(0,100)]
data2 = [(x*0.1, random.gauss(20,3) + 30*(x/100.)**2) for x in range(0,100)]

gnuplot = subprocess.Popen("/usr/bin/gnuplot", stdin=subprocess.PIPE)
gnuplot.stdin.write("set term dumb {} {}\n".format(columns - 3, rows - 3).encode())
gnuplot.stdin.write(b"set rmargin 0\nset tmargin 0\n")
gnuplot.stdin.write(b"plot '-' title 'foo', '-' title 'bar'\n")
for data in (data1, data2):
    for x,y in data:
        gnuplot.stdin.write("{} {}\n".format(x,y).encode())
    gnuplot.stdin.write(b"e\n")
gnuplot.stdin.write(b"exit\n")
gnuplot.wait()
pjvandehaar commented 8 years ago

Once I have something decent, I will post it to http://genome.sph.umich.edu/wiki/Using_Gotcloud_on_Flux and make links to that page from others.

pjvandehaar commented 8 years ago

Oh well, nevermind.