Select Page
Welcome to our Support Center
< All Topics

How to Enable systat logging on an Ubuntu Server

How to Install and Enable sysstat Logging on an Ubuntu Server

 

Introduction

Monitoring server performance is crucial to understanding the health and resource utilization of your Ubuntu system. At HostingHome, we ensure that our servers run efficiently, and one of the essential tools for monitoring performance is the sysstat package. It provides a set of utilities to collect and analyze performance statistics such as CPU, memory, disk usage, and network activity. These tools, including sar, iostat, and mpstat, help administrators keep track of server performance over time.

Enabling sysstat logging on your Ubuntu server ensures you have a continuous record of system activity, allowing you to diagnose performance issues effectively. This article will guide you through the steps to install, configure, and enable sysstat logging on your Ubuntu server.

Step 1: Install the sysstat Package

First, make sure the sysstat package is installed on your server. If it’s not already installed, you can do so with the following command:

bash

$ sudo apt install sysstat

Step 2: Enable sysstat Data Collection

After installation, sysstat does not collect data by default. You need to enable data collection by editing the configuration file. Open the configuration file with your preferred text editor:

bash

$ sudo nano /etc/default/sysstat

Find the line that reads:

bash

$ ENABLED=”false”

Change it to:

bash

$ ENABLED=”true”

Save the file and exit (press CTRL + X, then Y, and hit Enter).

Step 3: Configure Logging Interval

By default, sysstat collects performance data every 10 minutes. You can modify this interval if needed by editing the cron job that runs sysstat. The cron job configuration is stored in /etc/cron.d/sysstat. Open it for editing:

bash

$ sudo nano /etc/cron.d/sysstat

You’ll see a line like this:

bash

$ ‘*/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1’

This command runs every 10 minutes (*/10). If you want to change the interval to, for example, 5 minutes, update the line as follows:
bash

$ ‘*/5 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1’

Save the file and exit (press CTRL + X, then Y, and hit Enter).

Step 4: Start and Enable the sysstat Service

To ensure that sysstat starts collecting data, you need to start and enable the sysstat service.

bash

$ sudo systemctl enable sysstat
$ sudo systemctl start sysstat

This will start the sysstat data collection and ensure it runs on boot.

Step 5: Verify sysstat Logging

After enabling sysstat, you can check if the logging is working by running the sar command, which will display the recorded statistics. Run the following command to view the current day’s statistics:

bash

$ sar

To view CPU usage, use:

bash

$ sar -u

To view Memory usage:

bash

$ sar -r

To view Load Average:

bash

$ sar -q

You can also view logs from previous days by using the -f option along with the log file, which is stored under /var/log/sysstat/:
bash

$ sar -f /var/log/sysstat/saXX

Replace XX with the specific day you want to analyze (e.g., sa01 for the first day of the month).