-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
from docker import DockerClient | ||
import asyncio | ||
import shutil | ||
|
||
|
||
class Metrics: | ||
update_loop: bool = False | ||
docker_client: DockerClient | ||
update_loop_active: bool = False | ||
|
||
storage_total: int | ||
storage_left: int | ||
storage_used: int | ||
running_container_count: int | ||
|
||
def __init__(self): | ||
def __init__(self, docker_client: DockerClient): | ||
self.docker_client = docker_client | ||
self.collect_metrics() | ||
|
||
def collect_metrics(self): | ||
disk_usage = shutil.disk_usage("/") | ||
self.storage_total, self.storage_used, self.storage_left = [ | ||
x // (2**30) for x in disk_usage] | ||
self.running_container_count = len( | ||
self.docker_client.containers.list()) | ||
|
||
async def update_loop(self): | ||
if self.update_loop: | ||
if self.update_loop_active: | ||
return | ||
|
||
self.update_loop = True | ||
while self.update_loop: | ||
self.update_loop_active = True | ||
while self.update_loop_active: | ||
self.collect_metrics() | ||
asyncio.sleep(60) | ||
await asyncio.sleep(60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import os | ||
import logging | ||
from enum import Enum, auto | ||
from subprocess import call | ||
|
||
log = logging.getLogger() | ||
|
||
class Emoji: | ||
|
||
class Emoji(Enum): | ||
ROCKET = "\U0001F680" | ||
CHECK_MARK = "\U00002705" | ||
CROSS_MARK = "\U0000274C" | ||
|
||
|
||
class ImportanceLevel(Enum): | ||
VERY_LOW = auto() | ||
LOW = auto() | ||
MEDIUM = auto() | ||
IMPORTANT = auto() | ||
URGENT = auto() | ||
|
||
|
||
def time_in_seconds(seconds: float = 0, minutes=0, hours=0, days=0) -> float: | ||
return seconds + minutes * 60 + hours * 60 * 60 + days * 60 * 60 * 24 | ||
|
||
|
||
def exec_sh(command: str) -> int: | ||
return os.system(command) | ||
|
||
|
||
def free_storage(): | ||
for item in ["image", "container"]: | ||
exec_sh(f"docker {item} prune -f") | ||
return call(command, shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters