-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics
executable file
·37 lines (32 loc) · 1.19 KB
/
metrics
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/local/bin/python
import click
import psutil
@click.group()
def main():
pass
@main.command(short_help="Prints CPU metrics")
@click.argument('cpu', nargs=-1, required=False)
def cpu(cpu):
cpu = psutil.cpu_times()
templ = "%-5s %4s"
print (templ % ('system.cpu.idle:', int(cpu.idle)))
print (templ % ('system.cpu.user:', int(cpu.user)))
print (templ % ('system.cpu.guest:', int(cpu.guest)))
print (templ % ('system.cpu.iowait:', int(cpu.iowait)))
print (templ % ('system.cpu.steal:', int(cpu.steal)))
print (templ % ('system.cpu.system:', int(cpu.system)))
@main.command(short_help="Prints RAM metrics")
@click.argument('mem', nargs=-1, required=False)
def mem(mem):
virt = psutil.virtual_memory()
swap = psutil.swap_memory()
templ = "%-5s %12s"
print(templ % ('virtual total:', int(virt.total)))
print(templ % ('virtual used:', int(virt.used)))
print(templ % ('virtual free:', int(virt.free)))
print(templ % ('virtual.shared:', int(getattr(virt, 'shared'))))
print(templ % ('swap total:', int(swap.total)))
print(templ % ('swap used:', int(swap.used)))
print(templ % ('swap free:', int(swap.free)))
if __name__ == "__main__":
main()