Skip to content

Instantly share code, notes, and snippets.

@krzysztofantczak
Created February 8, 2024 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzysztofantczak/e7e0aa4a5cf4887ebe833402dd4113d9 to your computer and use it in GitHub Desktop.
Save krzysztofantczak/e7e0aa4a5cf4887ebe833402dd4113d9 to your computer and use it in GitHub Desktop.
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