dev.DevCog.panel_command()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 35
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 27
nop 1
dl 0
loc 35
rs 9.232
c 0
b 0
f 0
1
import psutil
2
from pincer.objects import Embed
3
4
from pincer_bot.core.command import guild_command
5
6
7
class DevCog:
8
9
    @guild_command(name="panel")
10
    async def panel_command(self) -> Embed:
11
        """Panel status command."""
12
        mb: int = 1024 ** 2
13
14
        vm = psutil.virtual_memory()
15
        cpu_freq = psutil.cpu_freq()
16
        cpu_percent = psutil.cpu_percent()
17
        disk = psutil.disk_usage('../app/cogs')
18
19
        stats = {
20
            'ram': (
21
                100 * (vm.used / vm.total),
22
                f'{(vm.total / mb) / 1000:,.3f}',
23
                'Gb'
24
            ),
25
            'cpu': (
26
                cpu_percent,
27
                f"{cpu_freq.current / 1000:.1f}`/`{cpu_freq.max / 1000:.1f}",
28
                'Ghz'
29
            ),
30
            'disk': (
31
                100 * (disk.used / disk.total),
32
                f'{disk.total / mb:,.0f}', 'Mb'
33
            )
34
        }
35
36
        return Embed(
37
            title="Panel Stats",
38
            description="The pincer_bot is hosted on a private vps."
39
        ).add_fields(
40
            stats.items(),
41
            map_title=lambda name: name.upper(),
42
            map_values=lambda percent, info, unit: (
43
                f"> `{percent:.3f}` **%**\n- `{info}` **{unit}**"
44
            )
45
        )
46
47
48
setup = DevCog
49