Created
February 8, 2024 08:04
-
-
Save krzysztofantczak/e7e0aa4a5cf4887ebe833402dd4113d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import pandas as pd | |
import re | |
# Read the data from the text file | |
with open("my-services.txt", "r") as file: | |
data = file.readlines() | |
# Initialize lists to store parsed data | |
server_names = [] | |
container_names = [] | |
cpu_usages = [] | |
mem_usages = [] | |
# Parse each line of data | |
for line in data: | |
# Extract server name | |
server_match = re.match(r'^ap-foo(\d+)t', line) | |
if server_match: | |
server_names.append(server_match.group(0)) | |
# Extract container name, CPU usage, and memory usage | |
container_match = re.search(r'\w+$', line) | |
if container_match: | |
container_names.append(container_match.group(0)) | |
stats = re.findall(r'\d+\.\d+%|\d+M', line) | |
cpu_usages.append(stats[0]) | |
mem_usages.append(stats[1]) | |
# Create a DataFrame | |
df = pd.DataFrame({ | |
"Server": server_names, | |
"Container": container_names, | |
"CPU Usage": cpu_usages, | |
"Memory Usage": mem_usages | |
}) | |
# Write the DataFrame to an Excel file | |
df.to_excel("docker_stats.xlsx", index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment