Fix: Delete graph image if server not running
All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 36s
All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 36s
This commit is contained in:
@@ -765,7 +765,7 @@ class PterodactylBot(commands.Bot):
|
|||||||
embed.add_field(name="ℹ️ Status", value="✅ `Active`", inline=True)
|
embed.add_field(name="ℹ️ Status", value="✅ `Active`", inline=True)
|
||||||
|
|
||||||
# Add resource usage if server is running
|
# Add resource usage if server is running
|
||||||
if current_state.lower() == "running":
|
if current_state.lower() != "offline":
|
||||||
# Current usage
|
# Current usage
|
||||||
cpu_usage = round(resource_attributes.get('resources', {}).get('cpu_absolute', 0), 2)
|
cpu_usage = round(resource_attributes.get('resources', {}).get('cpu_absolute', 0), 2)
|
||||||
memory_usage = round(resource_attributes.get('resources', {}).get('memory_bytes', 0) / (1024 ** 2), 2)
|
memory_usage = round(resource_attributes.get('resources', {}).get('memory_bytes', 0) / (1024 ** 2), 2)
|
||||||
@@ -952,8 +952,8 @@ class PterodactylBot(commands.Bot):
|
|||||||
|
|
||||||
# 4. Force update every 10 minutes for running servers (for uptime counter)
|
# 4. Force update every 10 minutes for running servers (for uptime counter)
|
||||||
elif (current_state == 'running' and
|
elif (current_state == 'running' and
|
||||||
(last_force_update is None or
|
(last_force_update is None or
|
||||||
current_time - last_force_update >= 600)): # 10 minutes = 600 seconds
|
current_time - last_force_update >= 600)): # 10 minutes = 600 seconds
|
||||||
logger.debug(f"Executing 10-minute force update for running server {server_name}")
|
logger.debug(f"Executing 10-minute force update for running server {server_name}")
|
||||||
needs_update = True
|
needs_update = True
|
||||||
# Update the last force update time
|
# Update the last force update time
|
||||||
@@ -972,20 +972,28 @@ class PterodactylBot(commands.Bot):
|
|||||||
|
|
||||||
# Fetch and update the existing message
|
# Fetch and update the existing message
|
||||||
message = await channel.fetch_message(int(location['message_id']))
|
message = await channel.fetch_message(int(location['message_id']))
|
||||||
# Generate and attach graph images if available
|
|
||||||
|
# Check if server is transitioning to offline/stopping state
|
||||||
|
# and remove image attachment if present
|
||||||
files = []
|
files = []
|
||||||
server_graphs = self.metrics_manager.get_server_graphs(server_id)
|
server_graphs = self.metrics_manager.get_server_graphs(server_id)
|
||||||
if server_graphs and server_graphs.has_sufficient_data:
|
|
||||||
# Generate CPU graph
|
# Only include graph images if server is running AND has sufficient data
|
||||||
|
if (current_state == 'running' and
|
||||||
|
server_graphs and
|
||||||
|
server_graphs.has_sufficient_data):
|
||||||
|
# Generate metrics graph
|
||||||
combined_graph = server_graphs.generate_combined_graph()
|
combined_graph = server_graphs.generate_combined_graph()
|
||||||
if combined_graph:
|
if combined_graph:
|
||||||
files.append(discord.File(combined_graph, filename=f"metrics_graph_{server_id}.png"))
|
files.append(discord.File(combined_graph, filename=f"metrics_graph_{server_id}.png"))
|
||||||
|
logger.debug(f"Including metrics graph for running server {server_name}")
|
||||||
# Update message with embed, view, and graph files
|
|
||||||
if files:
|
|
||||||
await message.edit(embed=embed, view=view, attachments=files)
|
|
||||||
else:
|
else:
|
||||||
await message.edit(embed=embed, view=view)
|
# Server is offline/stopping - ensure no image is attached
|
||||||
|
logger.debug(f"Server {server_name} is {current_state}, removing image attachment if present")
|
||||||
|
# We'll update without files to remove any existing attachments
|
||||||
|
|
||||||
|
# Update message with embed, view, and files (empty files list removes attachments)
|
||||||
|
await message.edit(embed=embed, view=view, attachments=files)
|
||||||
update_count += 1
|
update_count += 1
|
||||||
logger.debug(f"Updated status for {server_name}")
|
logger.debug(f"Updated status for {server_name}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user