Skip to main content

Posts about sysadmin

Setup SAR on Alpine Linux

There are several good articles on setting up SAR for debian (sar on ubuntu/debian) and redhat systems but I could find few on Alpine (perhaps because it is simple).

In any event, here's my process for setting up sar to run periodically via cron to track server stats.

Install

Install with: apk add sysstat

Setup

Not a lot of setup is required, you may want to review the /etc/sysconfig/sysstat file for options.

Running Via cron

Create a cron task as you like to kick off sar periodically, the following will run sar every 2 minutes.

# Run sar to gather stats
*/2 * * * *   /usr/lib/sa/sa1 1 1
# Additional run at 23:59 to rotate the statistics file
59 23 * * *   /usr/lib/sa/sa1 60 2

Logs

Alpine's sysstats logs are in /var/log/sa

Use sendmail over mail

mail (from mailutils) is a common sysadmin tool for sending system mail, however, it brings in unneeded/undesired packages (e.g. mysql/mariadb tools). sendmail is much lighter and can usually get the job done.

Typical mail Scenario

The following cron entry runs deborphan every Monday at 14:33, emailing the results to the drad user.

33 14 * * Mon   deborphan --guess-all | mail -s "Weekly deborphan Report" drad

Using sendmail Instead

sendmail does not have a -s (subject parameter). You need to preface your message with "Subject: {your subject}" followed by a new line and then the body such as follows:

33 14 * * Mon   ( echo "Subject: Weekly deborphan Report"; echo; deborphan --guess-all ) | /usr/sbin/sendmail drad

The sendmail route is a little more verbose but gets the job done and now you do not need mailutils!

Summary

mail (mailutils) is a common and useful mail tool but depends on several packages which may not be desirable. You can fully replace mail with sendmail to avoid the dependencies and yet provide the same system mail functionality.