Skip to content

Instantly share code, notes, and snippets.

View polius's full-sized avatar

Pol Alzina polius

View GitHub Profile
@polius
polius / mysql-locks-monitor.sql
Last active November 13, 2024 18:34
MySQL query to identify and retrieve detailed information about queries causing locks.
-- Requirement: performance_schema = ON
SELECT
lw.waiting_pid,
lw.waiting_query,
lw.waiting_trx_age AS 'waiting_time',
lw.blocking_pid,
(
SELECT h.SQL_TEXT
@polius
polius / rds-export-logs.py
Last active October 2, 2024 08:27
Retrieve all error logs from an Amazon RDS instance.
import boto3
import argparse
class main:
def __init__(self):
# Grab parameters
parser = argparse.ArgumentParser()
parser.add_argument('--region', required=True, help='AWS region name (eu-west-1)')
parser.add_argument('--instance', required=True, help='Database instance name')
parser.add_argument('--profile', required=False, help='AWS profile name ($ aws configure --profile customer)')
@polius
polius / ec2-volumes-scan.py
Created May 13, 2024 09:19
Generate a CSV file listing all EC2 volumes in an AWS account, along with some cost-saving recommendations.
import csv
import boto3
import numpy as np
import argparse
import threading
from datetime import datetime, timedelta, timezone
class main:
def __init__(self):
# Grab parameters
@polius
polius / rds-snapshots.sh
Last active May 8, 2024 14:27
Extract all AWS RDS manual snapshots from all regions into a CSV file.
account="123456789"
echo "Account, Region, SnapshotCreateTime, DBSnapshotIdentifier, DBInstanceIdentifier, Engine, AllocatedStorage" > "$account.csv"
for region in $(aws ec2 describe-regions --profile customer --query "Regions[].RegionName" --output text); do
echo "Region: $region"
snapshots=$(aws rds describe-db-snapshots --profile customer --region $region --query "DBSnapshots[?SnapshotType=='manual'].[SnapshotCreateTime, DBSnapshotIdentifier, DBInstanceIdentifier, Engine, AllocatedStorage]" --output json)
if [ -n "$snapshots" ]; then
echo "$snapshots" | jq -r --arg account "$account" --arg region "$region" '.[] | "\"\($account)\",\"\($region)\"," + @csv' >> "$account.csv"
fi
done
@polius
polius / dynamodb-scan.py
Last active October 18, 2024 20:45
A comprehensive tool for analyzing the workload of a DynamoDB table and extracting valuable insights.
# Install dependencies: python3 -m pip install boto3 numpy rich
import json
import boto3
import argparse
import numpy as np
from decimal import Decimal
from datetime import datetime, timedelta
from rich.console import Console
from rich.table import Table
@polius
polius / rds-scan.py
Last active February 12, 2025 10:07
Retrieve the AWS RDS pricing for an Aurora cluster comparing Aurora Standard and Aurora I/O-Optimized modes.
# Install dependencies: python3 -m pip install boto3 rich
import json
import boto3
import argparse
from decimal import Decimal
from datetime import datetime, timedelta, timezone
from rich.console import Console
from rich.table import Table
from rich.tree import Tree