-
-
Save sherwind/962fabb187769517e93a0ac57bf88f4e to your computer and use it in GitHub Desktop.
Revisions
-
sherwind revised this gist
Sep 13, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,7 @@ Usage: $0 [options] rds_instance_id OPTIONS: -s or --start-time=t Optional: Specify the start time in seconds since the Unix epoch -m or --sort-by-mem Optional: Sorts output by memory. Default is to sort by CPU EOF } -
sherwind revised this gist
Sep 13, 2019 . 1 changed file with 18 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ # Usage: # ./rds-top.sh rds-instance # ./rds-top.sh --start-time=$(date -v-13d +%s) rds-instance # ./rds-top.sh --sort-by-mem --start-time=$(date -j -f "%Y-%m-%dT%H:%M:%S%z" "2019-09-12T13:05:00+0000" +%s) rds-instance | grep -v 'idle$' set -e @@ -32,7 +33,11 @@ do case $i in -s=*|--start-time=*) START_TIME="${i#*=}" shift ;; -m | --sort-by-mem ) SORT_BY_MEM=1 shift ;; *) # unknown option @@ -42,12 +47,12 @@ done INSTANCE_ID="$1" if [[ "$INSTANCE_ID" == "" ]] then error "You have to supply an instance ID!" usage exit fi # Get resource id @@ -82,6 +87,12 @@ jq -r '.diskIO[] | "Disk \(.device): \(.tps) tps, \(.rrqmPS) rrqm/s, \(.wrqmPS) echo sort_by=".cpuUsedPc" if [[ $SORT_BY_MEM -eq 1 ]] then sort_by=".memoryUsedPc" fi echo "${message_json}" | jq -r '["PID", "PPID", "VSS", "RSS", "%CPU", "%MEM", "COMMAND"], (.processList | sort_by('"$sort_by"') | reverse[] | [.id, .parentID, .vss, .rss, .cpuUsedPc, .memoryUsedPc, .name]) | @tsv' | column -t -s $'\t' -
sherwind revised this gist
Aug 29, 2019 . 2 changed files with 76 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,87 @@ #!/bin/bash # rds-top.sh # by <[email protected]>, 20190822 # based on the work of Matheus de Oliveira <[email protected]> # # Usage: # ./rds-top.sh rds-instance # ./rds-top.sh --start-time=$(date -v-13d +%s) rds-instance set -e function usage() { cat << EOF Usage: $0 [options] rds_instance_id OPTIONS: -s or --start-time=t Optional: Specify the start time in seconds since the Unix epoch EOF } if [ $# -eq 0 ] then usage exit fi for i in "$@" do case $i in -s=*|--start-time=*) START_TIME="${i#*=}" shift # past argument=value ;; *) # unknown option ;; esac done INSTANCE_ID="$1" if [[ "$INSTANCE_ID" == "" ]]; then error "You have to supply an instance ID!"; usage; exit; fi; # Get resource id resource_id="$(aws rds describe-db-instances --db-instance-identifier "$INSTANCE_ID" --output json | jq -r '.DBInstances[].DbiResourceId')" [[ "$resource_id" == "" ]] && exit 1 # Build logs parameters params=(--log-group-name RDSOSMetrics --log-stream-name "$resource_id" --limit 1 --output json) if [[ "$START_TIME" =~ ^[[:digit:]]+$ ]]; then params+=(--start-time "$((START_TIME * 1000))" --start-from-head) fi # Get log events message_json=$(aws logs get-log-events "${params[@]}" | jq -r '.events[].message') echo "${message_json}" | jq -r '"\(.instanceID) - \(.timestamp) - \(.uptime) up, load average: \(.loadAverageMinute.one), \(.loadAverageMinute.five), \(.loadAverageMinute.fifteen) Tasks: \(.tasks.total) total, \(.tasks.running) running, \(.tasks.sleeping) sleeping, \(.tasks.stopped) stopped, \(.tasks.zombie) zombie %Cpu(s): \(.cpuUtilization.user) us, \(.cpuUtilization.system) sy, \(.cpuUtilization.nice) ni, \(.cpuUtilization.idle) id, \(.cpuUtilization.wait) wa, \(.cpuUtilization.steal) st MiB Mem: \(.memory.total / 1024) total, \(.memory.free / 1024) free, \((.memory.total - .memory.free) / 1024) used, \((.memory.cached + .memory.buffers) / 1024) buff/cache MiB Swap: \(.swap.total / 1024) total, \(.swap.free / 1024) free, \(.swap.cached) cached"' echo echo "${message_json}" | jq -r '.network[] | "Net \(.interface): \(.rx) rx, \(.tx) tx"' # Mimic `iostat -x` echo "${message_json}" | jq -r '.diskIO[] | "Disk \(.device): \(.tps) tps, \(.rrqmPS) rrqm/s, \(.wrqmPS) wrqm/s, \(.writeKbPS) wKB/S, \(.readKbPS) rKB/S, \(.avgReqSz) avgrq-sz, \(.avgQueueLen) avgqu-sz, \(.await) await, \(.util) %util"' echo echo "${message_json}" | jq -r '["PID", "PPID", "VSS", "RSS", "%CPU", "%MEM", "COMMAND"], (.processList | sort_by(.cpuUsedPc) | reverse[] | [.id, .parentID, .vss, .rss, .cpuUsedPc, .memoryUsedPc, .name]) | @tsv' | column -t -s $'\t' -
matheusoliveira revised this gist
Mar 29, 2018 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,8 @@ To use, you have to export variables to use aws-cli, like `AWS_PROFILE`, `AWS_DE watch ./rds-top.sh <your instance name> Requirements: * Before using it, you need to enable enhanced monitoring on your RDS instance. * You need to install [aws-cli](https://github.com/aws/aws-cli) and [jq](https://stedolan.github.io/jq/). -
matheusoliveira revised this gist
Mar 29, 2018 . 2 changed files with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ This is a very simple script, so don't expect something great. You can change it, distribute, do whatever you like, I don't mind. But if you improve it, you could share it back ;) To use, you have to export variables to use aws-cli, like `AWS_PROFILE`, `AWS_DEFAULT_REGION`, etc. Then just call the script using `watch` (or however you like) and giving the RDS instance name: This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ #!/bin/sh # Author: Matheus de Oliveira <[email protected]> # Gist: https://gist.github.com/matheusoliveira/0e9b13d2fca6e7ab993c03e946806503 instanceid="$1" -
matheusoliveira created this gist
Mar 29, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ This is a very simple script, so don't expect something great. You can change it, distribute, do whatever you like, I don't mind ;) To use, you have to export variables to use aws-cli, like `AWS_PROFILE`, `AWS_DEFAULT_REGION`, etc. Then just call the script using `watch` (or however you like) and giving the RDS instance name: watch ./rds-top.sh <your instance name> Before using it, you need to enable enhanced monitoring on your RDS instance. This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/bin/sh # Author: Matheus de Oliveira <[email protected]> instanceid="$1" resourceid="$( aws rds describe-db-instances | jq -r '.DBInstances[] | select(.DBInstanceIdentifier == "'${instanceid}'") | .DbiResourceId' )" message_json="$( aws logs get-log-events --log-group-name RDSOSMetrics --log-stream-name "${resourceid}" --limit 1 | jq -r '"\(.events[].message)"' )" echo "${message_json}" | jq -r \ '"\(.instanceID) - \(.timestamp) - \(.uptime) up, load average: \(.loadAverageMinute.one), \(.loadAverageMinute.five), \(.loadAverageMinute.fifteen) Tasks: \(.tasks.total) total, \(.tasks.running) running, \(.tasks.sleeping) sleeping, \(.tasks.stopped) stopped, \(.tasks.zombie) zombie %Cpu(s): \(.cpuUtilization.user) us, \(.cpuUtilization.system) sy, \(.cpuUtilization.nice) ni, \(.cpuUtilization.idle) id, \(.cpuUtilization.wait) wa, \(.cpuUtilization.steal) st MiB Mem: \(.memory.total / 1024) total, \(.memory.free / 1024) free, \((.memory.total - .memory.free) / 1024) used, \((.memory.cached + .memory.buffers) / 1024) buff/cache MiB Swap: \(.swap.total / 1024) total, \(.swap.free / 1024) free, \(.swap.cached) cached"' echo "${message_json}" | jq -r '.network[] | "Net \(.interface): \(.rx) rx, \(.tx) tx"' # Mimic `iostat -x` echo "${message_json}" | jq -r '.diskIO[] | "Disk \(.device): \(.tps) tps, \(.rrqmPS) rrqm/s, \(.wrqmPS) wrqm/s, \(.writeKbPS) wKB/S, \(.readKbPS) rKB/S, \(.avgReqSz) avgrq-sz, \(.avgQueueLen) avgqu-sz, \(.await) await, \(.util) %util"' echo tab="$( echo -ne "\t")" { echo -e "PID\tVSS\tRSS\t%CPU\t%MEM\tCOMMAND" echo "${message_json}" | jq -r '.processList[] | "\(.id)\t\(.vss)\t\(.rss)\t\(.cpuUsedPc)\t\(.memoryUsedPc)\t\(.name)"' | sort -nrk 4 } | column -t -s "${tab}"