forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CPU and RAM usage to Metrics (solana-labs#6968)
* Add CPU usage to Metrics * Add RAM usage and rename to system-stats * Shellcheck * Remove SC exception * Address review comments
- Loading branch information
1 parent
006c393
commit 3ce6248
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Reports cpu and ram usage statistics | ||
# | ||
set -e | ||
|
||
[[ $(uname) == Linux ]] || exit 0 | ||
|
||
# need to cd like this to avoid #SC1091 | ||
cd "$(dirname "$0")/.." | ||
source scripts/configure-metrics.sh | ||
|
||
while true; do | ||
# collect the total cpu usage by subtracting idle usage from 100% | ||
cpu_usage=$(top -bn1 | grep '%Cpu(s):' | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}') | ||
# collect the total ram usage by dividing used memory / total memory | ||
ram_total_and_usage=$(top -bn1 | grep 'MiB Mem'| sed "s/.*: *\([0-9.]*\)%* total.*, *\([0-9.]*\)%* used.*/\1 \2/") | ||
read -r total used <<< "$ram_total_and_usage" | ||
ram_usage=$(awk "BEGIN {print $used / $total * 100}") | ||
|
||
report="cpu_usage=$cpu_usage,ram_usage=$ram_usage" | ||
./scripts/metrics-write-datapoint.sh "system-stats,hostname=$HOSTNAME $report" | ||
sleep 1 | ||
done |