Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hangoutsbot cpu usage logger
import asyncio
import logging
import time
import os
logger = logging.getLogger(__name__)
import plugins
INTERVAL = 300
def _initialise(bot):
plugins.start_asyncio_task(tick)
plugins.register_admin_command(["cpuusage"])
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
logger.info("[{}] cpu = {}%".format(os.getpid(), round(cpu,2)))
@asyncio.coroutine
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.