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
load_logger [2020/04/19 17:29]
admin removed
— (current)
Line 1: Line 1:
-====== Load logger ====== 
-A simple bash script to log the datetime and system load to a file every minute. ​ I wanted something that didn't rely on having any other programs installed. 
- 
-It saves data in the following format: Server ID, Date/Time, CPU usage (%), CPU max, 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, network usage (one column per interface in the format [interface name, received bytes, transmitted bytes]) 
- 
- 
-<code bash save_load.sh>​ 
-#!/bin/bash 
-ID='​SERVER1'​ 
-CPU_COUNT=`cat /​proc/​cpuinfo | grep processor | wc -l` 
-MAX_CPU=$(($CPU_COUNT * 100)) 
-    printf -v date '​%(%Y-%m-%d %H:​%M:​%S)T'​ -1 
-    CPU_USAGE=`ps -ax -h -o 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` 
-    NET_USAGE=`awk -v ORS=","​ '​NR>​2{print $1,​$2,​$9}'​ /​proc/​net/​dev` 
-    OUTPUT=$ID','​$date','​$CPU_USAGE','​$MAX_CPU','​$MEM_USAGE','​$LOAD_AVG','​$NET_USAGE 
-    # to trim that last awkward comma 
-    echo $OUTPUT | awk '​{gsub(/,​$/,""​);​ print $0}' 
-</​code>​ 
-Example output 
-<​code>​ 
-SERVER1,​2020-04-19 17:​42:​13,​17.1,​400,​15929,​3401,​6050,​545,​6477,​11664,​0.28,​0.24,​0.26,​798,​eno1:​ 0 0,lo: 43147702 0,pan1: 0 0,wlp2s0: 29433068499 0 
-SERVER1,​2020-04-19 17:​42:​41,​17.1,​400,​15929,​3404,​6042,​551,​6483,​11656,​0.17,​0.21,​0.25,​795,​eno1:​ 0 0,lo: 43148718 0,pan1: 0 0,wlp2s0: 29433079099 0 
-</​code>​ 
  
load_logger.1587317383.txt.gz ยท Last modified: 2020/04/19 17:29 by admin