@commands.command(hidden=True)
@commands.is_owner()
async def bothealth(self, ctx):
    'Various bot health monitoring tools.'
    HEALTHY = discord.Colour(value=4437377)
    UNHEALTHY = discord.Colour(value=15747399)
    WARNING = discord.Colour(value=15769159)
    total_warnings = 0
    embed = discord.Embed(title='Bot Health Report', colour=HEALTHY)
    pool = self.bot.pool
    total_waiting = len(pool._queue._getters)
    current_generation = pool._generation
    description = [f'Total `Pool.acquire` Waiters: {total_waiting}', f'Current Pool Generation: {current_generation}', f'Connections In Use: {(len(pool._holders) - pool._queue.qsize())}']
    questionable_connections = 0
    connection_value = []
    for (index, holder) in enumerate(pool._holders, start=1):
        generation = holder._generation
        in_use = (holder._in_use is not None)
        is_closed = ((holder._con is None) or holder._con.is_closed())
        display = f'gen={holder._generation} in_use={in_use} closed={is_closed}'
        questionable_connections += any((in_use, (generation != current_generation)))
        connection_value.append(f'<Holder i={index} {display}>')
    joined_value = '\n'.join(connection_value)
    embed.add_field(name='Connections', value=f'''```py
{joined_value}
```''', inline=False)
    spam_control = self.bot.spam_control
    being_spammed = [str(key) for (key, value) in spam_control._cache.items() if (value._tokens == 0)]
    description.append(f"Current Spammers: {(', '.join(being_spammed) if being_spammed else 'None')}")
    description.append(f'Questionable Connections: {questionable_connections}')
    total_warnings += questionable_connections
    if being_spammed:
        embed.colour = WARNING
        total_warnings += 1
    try:
        task_retriever = asyncio.Task.all_tasks
    except AttributeError:
        task_retriever = asyncio.all_tasks
    else:
        all_tasks = task_retriever(loop=self.bot.loop)
    event_tasks = [t for t in all_tasks if (('Client._run_event' in repr(t)) and (not t.done()))]
    cogs_directory = os.path.dirname(__file__)
    tasks_directory = os.path.join('discord', 'ext', 'tasks', '__init__.py')
    inner_tasks = [t for t in all_tasks if ((cogs_directory in repr(t)) or (tasks_directory in repr(t)))]
    bad_inner_tasks = ', '.join((hex(id(t)) for t in inner_tasks if (t.done() and (t._exception is not None))))
    total_warnings += bool(bad_inner_tasks)
    embed.add_field(name='Inner Tasks', value=f'''Total: {len(inner_tasks)}
Failed: {(bad_inner_tasks or 'None')}''')
    embed.add_field(name='Events Waiting', value=f'Total: {len(event_tasks)}', inline=False)
    command_waiters = len(self._data_batch)
    is_locked = self._batch_lock.locked()
    description.append(f'Commands Waiting: {command_waiters}, Batch Locked: {is_locked}')
    yesterday = (datetime.datetime.utcnow() - datetime.timedelta(days=1))
    total_resumes = sum((1 for dt in self._resumes if (dt > yesterday)))
    identifies = {shard_id: sum((1 for dt in dates if (dt > yesterday))) for (shard_id, dates) in self._identifies.items()}
    absolute_total_identifies = sum(identifies.values())
    resume_info_builder = [f'Total RESUMEs: {total_resumes}', f'Total IDENTIFYs: {absolute_total_identifies}']
    for (shard_id, total) in identifies.items():
        resume_info_builder.append(f'Shard ID {shard_id} IDENTIFYs: {total}')
    if (absolute_total_identifies >= (len(self.bot.shards) * 5)):
        total_warnings += 1
        embed.colour = WARNING
    embed.add_field(name='Gateway (last 24 hours)', value='\n'.join(resume_info_builder), inline=False)
    memory_usage = (self.process.memory_full_info().uss / (1024 ** 2))
    cpu_usage = (self.process.cpu_percent() / psutil.cpu_count())
    embed.add_field(name='Process', value=f'''{memory_usage:.2f} MiB
{cpu_usage:.2f}% CPU''', inline=False)
    global_rate_limit = (not self.bot.http._global_over.is_set())
    description.append(f'Global Rate Limit: {global_rate_limit}')
    if (command_waiters >= 8):
        total_warnings += 1
        embed.colour = WARNING
    if (global_rate_limit or (total_warnings >= 9)):
        embed.colour = UNHEALTHY
    embed.set_footer(text=f'{total_warnings} warning(s)')
    embed.description = '\n'.join(description)
    (await ctx.send(embed=embed))
Various bot health monitoring tools.
@commands.command(hidden=True)
@commands.is_owner()
async def bothealth(self, ctx):
    
    HEALTHY = discord.Colour(value=4437377)
    UNHEALTHY = discord.Colour(value=15747399)
    WARNING = discord.Colour(value=15769159)
    total_warnings = 0
    embed = discord.Embed(title='Bot Health Report', colour=HEALTHY)
    pool = self.bot.pool
    total_waiting = len(pool._queue._getters)
    current_generation = pool._generation
    description = [f'Total `Pool.acquire` Waiters: {total_waiting}', f'Current Pool Generation: {current_generation}', f'Connections In Use: {(len(pool._holders) - pool._queue.qsize())}']
    questionable_connections = 0
    connection_value = []
    for (index, holder) in enumerate(pool._holders, start=1):
        generation = holder._generation
        in_use = (holder._in_use is not None)
        is_closed = ((holder._con is None) or holder._con.is_closed())
        display = f'gen={holder._generation} in_use={in_use} closed={is_closed}'
        questionable_connections += any((in_use, (generation != current_generation)))
        connection_value.append(f'<Holder i={index} {display}>')
    joined_value = '\n'.join(connection_value)
    embed.add_field(name='Connections', value=f'```py
{joined_value}
```', inline=False)
    spam_control = self.bot.spam_control
    being_spammed = [str(key) for (key, value) in spam_control._cache.items() if (value._tokens == 0)]
    description.append(f"Current Spammers: {(', '.join(being_spammed) if being_spammed else 'None')}")
    description.append(f'Questionable Connections: {questionable_connections}')
    total_warnings += questionable_connections
    if being_spammed:
        embed.colour = WARNING
        total_warnings += 1
    try:
        task_retriever = asyncio.Task.all_tasks
    except AttributeError:
        task_retriever = asyncio.all_tasks
    else:
        all_tasks = task_retriever(loop=self.bot.loop)
    event_tasks = [t for t in all_tasks if (('Client._run_event' in repr(t)) and (not t.done()))]
    cogs_directory = os.path.dirname(__file__)
    tasks_directory = os.path.join('discord', 'ext', 'tasks', '__init__.py')
    inner_tasks = [t for t in all_tasks if ((cogs_directory in repr(t)) or (tasks_directory in repr(t)))]
    bad_inner_tasks = ', '.join((hex(id(t)) for t in inner_tasks if (t.done() and (t._exception is not None))))
    total_warnings += bool(bad_inner_tasks)
    embed.add_field(name='Inner Tasks', value=f'Total: {len(inner_tasks)}
Failed: {(bad_inner_tasks or 'None')}')
    embed.add_field(name='Events Waiting', value=f'Total: {len(event_tasks)}', inline=False)
    command_waiters = len(self._data_batch)
    is_locked = self._batch_lock.locked()
    description.append(f'Commands Waiting: {command_waiters}, Batch Locked: {is_locked}')
    yesterday = (datetime.datetime.utcnow() - datetime.timedelta(days=1))
    total_resumes = sum((1 for dt in self._resumes if (dt > yesterday)))
    identifies = {shard_id: sum((1 for dt in dates if (dt > yesterday))) for (shard_id, dates) in self._identifies.items()}
    absolute_total_identifies = sum(identifies.values())
    resume_info_builder = [f'Total RESUMEs: {total_resumes}', f'Total IDENTIFYs: {absolute_total_identifies}']
    for (shard_id, total) in identifies.items():
        resume_info_builder.append(f'Shard ID {shard_id} IDENTIFYs: {total}')
    if (absolute_total_identifies >= (len(self.bot.shards) * 5)):
        total_warnings += 1
        embed.colour = WARNING
    embed.add_field(name='Gateway (last 24 hours)', value='\n'.join(resume_info_builder), inline=False)
    memory_usage = (self.process.memory_full_info().uss / (1024 ** 2))
    cpu_usage = (self.process.cpu_percent() / psutil.cpu_count())
    embed.add_field(name='Process', value=f'{memory_usage:.2f} MiB
{cpu_usage:.2f}% CPU', inline=False)
    global_rate_limit = (not self.bot.http._global_over.is_set())
    description.append(f'Global Rate Limit: {global_rate_limit}')
    if (command_waiters >= 8):
        total_warnings += 1
        embed.colour = WARNING
    if (global_rate_limit or (total_warnings >= 9)):
        embed.colour = UNHEALTHY
    embed.set_footer(text=f'{total_warnings} warning(s)')
    embed.description = '\n'.join(description)
    (await ctx.send(embed=embed))