Example #1
0
 def report(self):
     if psi is None:
         return
     for process in watcher.processes.values():
         if process.state == utils.watch.Running:
             try:
                 stats = psi.process.Process(process.pid)
             except psi.process.NoSuchProcessError:
                 warning("Process {} dissapeared when looking for stats".format(process.p.name))
                 continue
             curr_time, cputime = time.time(), stats.cputime.float()
             try:
                 last_time, last_cputime = process.__last_times
                 cpu_percent = (cputime - last_cputime) / (curr_time - last_time)
             except AttributeError:
                 cpu_percent = 0
                 pass
             process.__last_times = (curr_time, cputime)
             statmsg = messaging.ProcessStatusMessage(socket.gethostname(), process.p.name, True, 'Running', cpu_percent, stats.rss, stats.nthreads)
             self.node.send(statmsg)
         elif process.cause_of_death:
             statmsg = messaging.ProcessStatusMessage(socket.gethostname(), process.p.name, False, process.cause_of_death, 0, 0, 0)
             #reset cause of death once reported
             process.cause_of_death = ""
             self.node.send(statmsg)
         elif self.report_all:
             statmsg = messaging.ProcessStatusMessage(socket.gethostname(), process.p.name, False, 'Not started', 0, 0, 0)
             self.node.send(statmsg)
     self.report_all = False #dont report all until requested to again
    + r).streamline()
p_TelemetryMessage.setParseAction(lambda x: messaging.TelemetryMessage(*x[0]))
p_BatteryUseMessage = pp.Group(l \
    + p_float + c \
    + p_float + c \
    + p_float \
    + r).streamline()
p_BatteryUseMessage.setParseAction(lambda x: messaging.BatteryUseMessage(*x[0]))
p_ProcessStatusMessage = pp.Group(l \
    + p_str + c \
    + p_str + c \
    + p_float + c \
    + p_float + c \
    + p_int \
    + r).streamline()
p_ProcessStatusMessage.setParseAction(lambda x: messaging.ProcessStatusMessage(*x[0]))
p_LocationMessage = pp.Group(l \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_floatXYZ \
    + r).streamline()
p_LocationMessage.setParseAction(lambda x: messaging.LocationMessage(*x[0]))
p_GPSLocationMessage = pp.Group(l \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_float \
    + r).streamline()
p_BatteryUseMessage = pp.Group(l \
    + p_float + c \
    + p_float + c \
    + p_float \
    + r).streamline()
p_BatteryUseMessage.setParseAction(
    lambda x: messaging.BatteryUseMessage(*x[0]))
p_ProcessStatusMessage = pp.Group(l \
    + p_str + c \
    + p_str + c \
    + p_float + c \
    + p_float + c \
    + p_int \
    + r).streamline()
p_ProcessStatusMessage.setParseAction(
    lambda x: messaging.ProcessStatusMessage(*x[0]))
p_LocationMessage = pp.Group(l \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_floatXYZ \
    + r).streamline()
p_LocationMessage.setParseAction(lambda x: messaging.LocationMessage(*x[0]))
p_GPSLocationMessage = pp.Group(l \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_float + c \
    + p_float \
    + r).streamline()