3

I am trying to monitor the swapping activity in a Linux Server in the last, say, 1, 5 or 15 minutes.

One way is to run vmstat and keep watching si and so counters during these intervals.

However how can I check as a "one-shot" action (e.g. through a Nagios plugin) for a value showing the swapping activity during the aforementioned intervals?

In other words I need a way to instantly check whether my Server is actively swapping.

trikelef
  • 381
  • 1
  • 4
  • 13

1 Answers1

1

Believe you could use /proc/vmstat output, say with

cat /proc/vmstat | grep pswp

command.

This will show you swap in and swap out counters.

Or:

only si:

vmstat 1 1 | awk 'NR == 1 {next} NR == 2 {for (i = 1; i <= NF; i++) fields[$i] = i; next} {split($0, data); item = data[fields["si"]]; print item; totals[fields["si"]] += item} NR >= 6 + 2 {exit}'

only so:

vmstat 1 1 | awk 'NR == 1 {next} NR == 2 {for (i = 1; i <= NF; i++) fields[$i] = i; next} {split($0, data); item = data[fields["si"]]; print item; totals[fields["so"]] += item} NR >= 6 + 2 {exit}'
Bart
  • 2,151
  • 1
  • 10
  • 26
  • 2
    alternatively, if you intend to use it in Nagios, try https://exchange.nagios.org/directory/Plugins/System-Metrics/Memory/Check-swap-activity-on-Linux/details – Bart Jul 26 '19 at 12:00