Last active
January 24, 2025 15:13
-
-
Save nickkostov/f598f3206f9a155d9a15bacef556cd98 to your computer and use it in GitHub Desktop.
Datadog Logs
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
#!/bin/bash | |
# Function to log messages | |
log() { | |
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | |
} | |
log "###################################### STARTING DATADOG DEBUG SCRIPT ######################################" | |
# Check if the Datadog log file exists before processing | |
if [ -f /var/log/datadog/agent.log ]; then | |
log "###################################### Displaying the last 200 lines of the Datadog agent log: ######################################" | |
tail -200 /var/log/datadog/agent.log | |
log "###################################### Displaying the first 200 lines of the Datadog agent log: ######################################" | |
head -200 /var/log/datadog/agent.log | |
else | |
log "###################################### ERROR: Datadog agent log file not found at /var/log/datadog/agent.log. ######################################" | |
fi | |
# Check Datadog agent status | |
log "###################################### Checking Datadog agent status: ######################################" | |
sudo datadog-agent status | |
# Check Datadog agent health | |
log "###################################### Checking Datadog agent health:######################################" | |
sudo datadog-agent health | |
log "###################################### Checking Datadog agent hostname: ######################################" | |
sudo datadog-agent hostname | |
# List files in the Datadog configuration directory | |
DATADOG_DIR="/etc/datadog-agent" | |
if [ -d "$DATADOG_DIR" ]; then | |
log "Listing files in the Datadog configuration directory ($DATADOG_DIR):" | |
ls "$DATADOG_DIR" | |
else | |
log "ERROR: Datadog configuration directory not found at $DATADOG_DIR." | |
exit 0 | |
fi | |
# List all Docker containers | |
log "###################################### Listing all Docker containers: ######################################" | |
sudo docker ps -a | |
# Define the container names | |
containers=("kafka-dbz-ife-connect" "kafka-dbz-ccc-connect") | |
# Function to check the status of a container | |
check_container_status() { | |
local container_name=$1 | |
docker inspect -f '{{.State.Running}}' "$container_name" 2>/dev/null | |
} | |
# Function to start a container | |
start_container() { | |
local container_name=$1 | |
echo "Starting container: $container_name" | |
sudo docker start "$container_name" | |
} | |
# Main script execution | |
for container in "${containers[@]}"; do | |
status=$(check_container_status "$container") | |
if [ "$status" == "true" ]; then | |
echo "Container '$container' is already running." | |
else | |
echo "Container '$container' is not running or does not exist." | |
start_container "$container" | |
fi | |
done | |
# Output container statuses after starting them | |
echo -e "\nFinal container statuses:" | |
sudo docker ps -a | |
log "###################################### SCRIPT COMPLETED ######################################" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment