User Tools

Site Tools


load_logger

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
load_logger [2020/04/14 00:47]
neil cpu usage needs tweaked - current version probably adds to 100+ on multiple cores
— (current)
Line 1: Line 1:
-====== Load logger ====== 
-A simple bash script to log the datetime and system load to a file every 30 seconds. 
  
-It saves data in the following format: Server ID, Date/Time, CPU usage (%), Memory Total (Mb), Memory Used (Mb), Memory Free (Mb), Memory Shared (Mb), Memory Buffered/​Cached (Mb), Memory Available (Mb), 1 minute load average, 5 minute load average, 15 minute load average, process count 
- 
- 
-<code bash save_load.sh>​ 
-#!/bin/bash 
-ID='​SERVER1'​ 
-while [ true ]  
-do 
-    printf -v date '​%(%Y-%m-%d %H:​%M:​%S)T'​ -1 
-    CPU_USAGE=`ps -heo pcpu | paste "​-sd+"​ | bc` 
-    MEM_USAGE=`free -m | grep '​Mem:'​ | awk -v OFS=","​ '​{print ($2,​$3,​$4,​$5,​$6,​$7)}'​` 
-    LOAD_AVG=`awk -v OFS=","​ '​{split($4,​arr,"/"​)} {print $1,​$2,​$3,​arr[2]}'​ /​proc/​loadavg` 
-    echo -e $ID','​$date','​$CPU_USAGE','​$MEM_USAGE','​$LOAD_AVG 
-    sleep 30; 
-done 
-</​code>​ 
-Example: 
-<​code>​ 
-SERVER1,​2020-04-13 22:​59:​59,​3.86818,​15929,​2082,​9545,​273,​4301,​13258,​0.27,​0.31,​0.24,​703 
-SERVER1,​2020-04-13 23:​06:​04,​3.87079,​15929,​2127,​9497,​276,​4304,​13211,​0.22,​0.25,​0.22,​708 
-SERVER1,​2020-04-13 23:​06:​22,​3.87107,​15929,​2127,​9494,​278,​4307,​13208,​0.36,​0.28,​0.24,​710 
-</​code>​ 
- 
-I use a cronjob to check every 5 minutes to make sure it's always running: 
-<code bash check_load.sh>​ 
-#!/bin/bash 
-if [[ ! `pidof -s save_load.sh` ]]; then 
-  /​bin/​save_load.sh >> /​logs/​stats.log 
-fi 
-</​code>​ 
load_logger.1586821669.txt.gz ยท Last modified: 2020/04/14 00:47 by neil