Tuesday, May 7, 2024

How to monitor a linux server during Load Test | Monitor Linux server without any monitoring tool

Recently I came across a situation where my client doesn't have any monitoring tool but we need to monitor the servers during the load testify the server is windows we can directly use PERFMON default windows monitoring tool, but the Linux doesn't have any such features, so I have created a csv file with a simple command in Linux machine. i have triggered this for

$vmstat -n [delay [count]] | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'>{file path}

Example:  vmstat -n 1 10 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'>/tmp/vmstat.csv

The given command line combines the output of the vmstat command with awk to create a log file that records the current timestamp along with the system statistics. Here's how it works:

  • vmstat -n [delay [count]]: The vmstat command is used to monitor virtual memory statistics and system performance. The -n flag disables the header output, providing only data. The command accepts optional arguments:

    • delay: The time interval, in seconds, between data samples.
    • count: The number of data samples to collect.
  • awk '{now=strftime("%Y-%m-%d %T "); print now $0}': This part of the command processes each line of the vmstat output:

    • now=strftime("%Y-%m-%d %T "): This awk code creates a timestamp in the format Year-Month-Day Hour:Minute:Second.
    • print now $0: This prints the current timestamp followed by the original line from the vmstat output.
  • >{file path}: The output of the command, which is the timestamped vmstat data, is redirected to the specified file path. For example, /tmp/vmstat.txt.

No comments: