This time, I was how to monitor server CPU and memory

background

A new project in conjunction with business performance tests. N times the performance test done for me, this time some housewife in trouble without straw feeling. Previous projects, servers are deployed on AWS or Ali cloud, the cloud server vendors such as this can be real-time monitoring of the entire system easily configure the server through a variety of new energy Dashboard. However, this time, the cloud server is not on, and does not allow connections to external networks. That a similar server CPU and memory usage in real-time line chart, how?

Thinking

Results-oriented, is a pressing need to measure server CPU and memory line chart, then how to draw? Excel can insert a similar line chart, then the data is how come? Some Linux commands can be recorded at the time of the server CPU and memory, if there is a script or command to record the data in real time down, and to export the data to a csv file, then Excel will be able to help get the results we want.

process

script

#!/bin/bash
fileName=$1

echo "CPU%,MEM%,TIME" > $fileName
for (( i = 0; i < 3000; i++ )) do
    output=`top -b -n1 | grep "Cpu(s)" | awk '{print $2 ","}' | tr -d '\n' && free -m | grep 'Mem' | awk '{print $3/$2 * 100 ","}' | tr -d '\n' && date | awk '{print $4}'`>temp
    echo "$output" >> $fileName
    sleep 1
done

Generated map

Guess you like

Origin www.cnblogs.com/chenyongblog/p/11831498.html