forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapacity-analysis.sh
More file actions
executable file
路69 lines (60 loc) 路 2.46 KB
/
Copy pathcapacity-analysis.sh
File metadata and controls
executable file
路69 lines (60 loc) 路 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
set -euo pipefail
AWS_REGION="${AWS_REGION:-us-east-1}"
LOOKBACK_DAYS="${LOOKBACK_DAYS:-30}"
REPORT_FILE="/tmp/capacity-analysis-$(date +%Y%m%d).txt"
log() { echo "[$(date +%H:%M:%S)] $*" | tee -a "${REPORT_FILE}"; }
START_TIME=$(date -u -d "${LOOKBACK_DAYS} days ago" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null \
|| date -u -v-"${LOOKBACK_DAYS}"d +%Y-%m-%dT%H:%M:%SZ)
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
log "=== GistPin Capacity Analysis ==="
log "Region: ${AWS_REGION} | Period: last ${LOOKBACK_DAYS} days"
# EKS node CPU utilization
log "[1/4] EKS node CPU utilization (avg over ${LOOKBACK_DAYS}d)"
aws cloudwatch get-metric-statistics \
--region "${AWS_REGION}" \
--namespace ContainerInsights \
--metric-name node_cpu_utilization \
--dimensions Name=ClusterName,Value=gistpin \
--statistics Average Maximum \
--period 86400 \
--start-time "${START_TIME}" \
--end-time "${END_TIME}" \
--query 'sort_by(Datapoints, &Timestamp)[].[Timestamp,Average,Maximum]' \
--output table | tee -a "${REPORT_FILE}" || log "CloudWatch data unavailable"
# EKS node memory utilization
log "[2/4] EKS node memory utilization"
aws cloudwatch get-metric-statistics \
--region "${AWS_REGION}" \
--namespace ContainerInsights \
--metric-name node_memory_utilization \
--dimensions Name=ClusterName,Value=gistpin \
--statistics Average Maximum \
--period 86400 \
--start-time "${START_TIME}" \
--end-time "${END_TIME}" \
--query 'sort_by(Datapoints, &Timestamp)[].[Timestamp,Average,Maximum]' \
--output table | tee -a "${REPORT_FILE}" || log "CloudWatch data unavailable"
# RDS storage and connections
log "[3/4] RDS storage and connection trends"
for METRIC in FreeStorageSpace DatabaseConnections; do
log " Metric: ${METRIC}"
aws cloudwatch get-metric-statistics \
--region "${AWS_REGION}" \
--namespace AWS/RDS \
--metric-name "${METRIC}" \
--dimensions Name=DBInstanceIdentifier,Value=gistpin-db \
--statistics Average Maximum \
--period 86400 \
--start-time "${START_TIME}" \
--end-time "${END_TIME}" \
--query 'sort_by(Datapoints, &Timestamp)[].[Timestamp,Average,Maximum]' \
--output table | tee -a "${REPORT_FILE}" || true
done
# Current HPA status
log "[4/4] Current HPA scaling status"
kubectl get hpa -n gistpin 2>/dev/null | tee -a "${REPORT_FILE}" \
|| log "kubectl not available, skipping HPA status"
log ""
log "Analysis complete. Report: ${REPORT_FILE}"
log "Run forecast-usage.py for growth projections."