def on_swap_output(self, tak, line):
        now = int(time.time())
        out = line.split()

        try:
            free = (self.task.path + '.memory.swap_free', (now, out[-1]))
            used = (self.task.path + '.memory.swap_used', (now, out[-2]))
            total = (self.task.path + '.memory.swap_total', (now, out[-3]))

            payload = pickle.dumps([free, used, total], protocol=2)
            header = struct.pack("!L", len(payload))

            if SendGraphitePayload(self.destination, header, payload):
                logger.debug('Sent:\n%s', [free, used, total])

        except:
            logger.error(traceback.format_exc)
Exemple #2
0
    def on_output(self, task, line):
        if 'Permission denied' in line:
            logger.error("Permission denied")
            return
        now = int(time.time())
        out = line.split()

        try:
            disk_name = out[5].replace('/', '_')
            path = self.task.path + '.disk.' + disk_name
            free = (path + '.free', (now, out[1].replace('M', '')))
            used = (path + '.used', (now, out[2].replace('M', '')))
            total = (path + '.available', (now, out[3].replace('M', '')))
            percent = (path + '.used_percent',
                       (now, out[4].replace('M', '').replace('%', '')))

            payload = pickle.dumps([free, used, total, percent], protocol=2)
            header = struct.pack("!L", len(payload))

            if SendGraphitePayload(self.destination, header, payload):
                logger.debug('Sent:\n%s', [free, used, total, percent])
        except:
            logger.error(traceback.format_exc)
    def on_output(self, task, line):
        # pid  user                                       CPU  MEM
        # 1566 root      20   0  719932  20128   7784 S   0.0  1.0  9:02.08  {p}
        if not line:
            return

        if 'unknown option' in line or 'TERM' in line:
            logger.error(line)
            return

        now = int(time.time())
        out = line.split()

        path = self.path + "." + self.current['process'].replace(
            '/', '_').replace('.', '_') + ".thread." + out[-1]
        mem = (path + '.memory_percent', (now, out[-3]))
        cpu = (path + '.cpu_percent', (now, out[-4]))

        payload = pickle.dumps([mem, cpu], protocol=2)
        header = struct.pack("!L", len(payload))

        if SendGraphitePayload(self.destination, header, payload):
            logger.debug('Sent:\n%s', [mem, cpu])