ans2dev.general.sar_facts module – Collect info from sar.

Note

This module is part of the ans2dev.general collection (version 0.2.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install ans2dev.general.

To use it in a playbook, specify: ans2dev.general.sar_facts.

New in ans2dev.general 0.1.0

Synopsis

  • Retrieves SAR data using the sar command from system logs.

  • Supports filtering by date range, time range, and partition details.

  • Returns performance metrics such as CPU utilization, memory usage, disk activity, and network statistics.

  • ans2dev.general.sar_facts only supports sar data with a 12H time format and automatically converts format to 24H.

Parameters

Parameter

Comments

average

boolean

Whether to retrieve only the average values.

Choices:

  • false ← (default)

  • true

date_end

string

End date for collecting SAR data (format YYYY-MM-DD).

date_start

string

Start date for collecting SAR data (format YYYY-MM-DD).

partition

boolean

Whether to retrieve partition-specific disk statistics.

Choices:

  • false ← (default)

  • true

time_end

string

End time for collecting SAR data (format HH:MM:SS).

time_start

string

Start time for collecting SAR data (format HH:MM:SS).

type

string / required

Type of SAR data to retrieve.

Choices:

  • "cpu"

  • "memory"

  • "swap"

  • "network"

  • "disk"

  • "load"

Examples

# Gather CPU performance metrics for a specific date and time range.
- name: Gather CPU SAR facts between 08:00 and 10:00
  ans2dev.general.sar_facts:
    date_start: "2025-05-01"
    date_end: "2025-05-01"
    time_start: "08:00:00"
    time_end: "10:00:00"
    type: cpu

# Gather memory usage SAR data for a single day.
- name: Retrieve memory usage data for a day
  ans2dev.general.sar_facts:
    date_start: "2025-05-01"
    type: memory

# Retrieve disk statistics with partition details.
- name: Gather disk usage statistics with partition information
  ans2dev.general.sar_facts:
    date_start: "2025-05-01"
    type: disk
    partition: true

# Retrieve average load statistics.
- name: Gather average load statistics
  ans2dev.general.sar_facts:
    date_start: "2025-05-01"
    type: load
    average: true

Returned Facts

Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.

Key

Description

sar_cpu

dictionary

Dictionary that contains cpu data from sar.

It contains date, time and all others keys from sar data.

Most common keys are %user, %nice, %system, %idle and others.

Returned: when type is cpu.

sar_disk

dictionary

Dictionary that contains disk data from sar.

It contains date, time and all others keys from sar data.

Most common keys are DEV, %util, await, rkB/s, wkB/s and others.

Returned: when type is disk.

sar_load

dictionary

Dictionary that contains load data from sar.

It contains date, time and all others keys from sar data.

Most common keys are ldavg-1, ldavg-5, ldavg-15 and others.

Returned: when type is load.

sar_mem

dictionary

Dictionary that contains memory data from sar.

It contains date, time and all others keys from sar data.

Most common keys are %memused, %commit and others.

Returned: when type is memory.

sar_net

dictionary

Dictionary that contains network data from sar.

It contains date, time and all others keys from sar data.

Most common keys are IFACE, rxpck/s, txpck/s, %ifutil and others.

Returned: when type is network.

sar_swap

dictionary

Dictionary that contains swap data from sar.

It contains date, time and all others keys from sar data.

Most common keys are %swpused, %swpcad and others.

Returned: when type is swap.

Authors

  • Marco Noce (@NomakCooper)