Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
hangoutsbot cpu usage logger
import asyncio
import logging
import time
import os
logger = logging.getLogger(__name__)
import plugins
def _initialise(bot):
def cpuusage(bot, event, *args):
process_start = time.process_time()
monotonic_start = time.monotonic()
yield from asyncio.sleep(10)
process_diff = time.process_time() - process_start
monotonic_diff = time.monotonic() - monotonic_start
cpu = process_diff / monotonic_diff * 100 # percent"[{}] cpu = {}%".format(os.getpid(), round(cpu,2)))
def tick(bot):
monotonic_last = 0
while True:
if time.monotonic() - monotonic_last > INTERVAL:
yield from cpuusage(bot, False, False)
monotonic_last = time.monotonic()
yield from asyncio.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.