• sysstat rc switch

    From jayjwa@jayjwa@atr2.ath.cx.invalid to alt.os.linux.slackware on Thu Sep 3 11:51:57 2026
    From Newsgroup: alt.os.linux.slackware

    sysstat comes with an rc switch, but it doesn't do much of anything. For
    years I've had another one around here but decided yesterday to shine it
    up and post it in the hopes someone would find it useful. It can be used
    to start, stop, and also output a graph in SVG.

    rc.sysstat
    sysstat version 12.8.0
    (C) Sebastien Godard (sysstat <at> orange.fr)
    [+] systat data collection server run control switch
    Usage:
    rc.sysstat <start | stop | restart | graph>

    In the sysstat manpage, the cron daemon runs it but I prefer to have the
    daemon running and have it sample every N minutes. Then cron only needs
    to generate the reports.

    sar
    ...
    10:34:16 AM CPU %user %nice %system %iowait %steal %idle 10:49:16 AM all 20.67 0.00 2.18 0.10 0.00 77.05 Average: all 19.38 0.00 2.59 0.23 0.00 77.80

    Clobber /etc/rc.d/rc.sysstat, set executable, make sure it's hooked into
    the startup scripts, and read the script comments for the rest of the
    inner workings. Inkscape will view the SVG graphs.

    #!/bin/bash
    ##
    ## $Id: rc.sysstat,v 1.1 2026/09/02 17:52:19 jayjwa Exp $
    ##
    ## Script to control the stats gathering suite of programs,
    ## sysstat. "sadc" is the backend of "sar" that collects the
    ## data. This script launches, stops, and restarts the main
    ## collector. A graph can also be requested via this script.
    ## Other scripts, as cron jobs under root and systab
    ## (the virtual user for the system itself for fcrontab),
    ## will see to it that system report summaries are made at
    ## the right times.
    ##
    ## The following examples are in fcrontab format:
    # Enter a "restart" mark in the data file for sadc and make sure that
    # data file is created just after midnight each day so that the 'sar'
    # command will always produce output instead of 'file not found'.
    #& 1 0 * * * /usr/lib64/sa/sadc -
    ##
    # Generate a summary of process accounting each midnight
    # This is only the report generation, but is still needed.
    #%nightly * 23 /usr/lib64/sa/sa2 -A
    #%nightly * 23 /usr/lib64/sa/sa1 --rotate
    ##
    ## Default options set in this script:
    ## -S = Specify which optional activities should be collected by sadc
    ## -F = Force creation of logfile (if something messes it up, this
    ## command will ensure it gets reset correctly.)
    ## -L = Lock the logfile during write to avoid corruption of it
    ## [first numeric position] = make a record at this interval, in seconds
    ## [second numeric position] = make this many records then stop (count)
    ##
    ## $Log: rc.sysstat,v $
    ## Revision 1.1 2026/09/02 17:52:19 jayjwa
    ## Initial revision
    ##
    ##
    ## --------------------------------------------------------------------

    ## [Script data] ------------------------------------------------------
    # Color codes for fancy output
    readonly RED='\033[0;31m' # Error conditions
    readonly GREEN='\033[0;32m' # Operation was successful readonly BLUE='\033[0;34m' # Informational and other readonly NC='\033[0m' # Shut off color output

    # The user's function to perform: must be one of
    # (start, stop, restart), else give usage message.
    command=$1

    # The 'sadc' binary itself. As per Slackware64 Current: SADC="/usr/lib64/sa/sadc"

    # The options to pass to sadc. See 'man sadc'.
    options="-F -S XALL -L"

    # Take system activity data record every (sample_rate) seconds.
    # 60s per minute, 900/60 = every 15 minutes record data
    sample_rate=900

    # Help/usage text function
    usage() {
    printf "${BLUE}"
    # Announce program version, too
    $SADC -V
    printf "%s${NC}\\n\\n" \
    "[+] systat data collection server run control switch
    Usage:
    $(basename ${0}) <start | stop | restart | graph>"
    }

    # Sanity function. The directory /var/log/sa must exit for the data
    # files to be written correctly.
    sane() {
    mkdir -p /var/log/sa
    }

    ## [Execution mode] ------------------------------------------------------------
    case ${command} in
    'start')
    # Start the collector, sadc, and log to syslog
    if ! ps -C sadc 1> /dev/null; then
    # Not running, start it as per options given, log restart
    sane
    $SADC -
    $SADC ${options} ${sample_rate} - &
    printf "${GREEN}%s${NC}\\n" "[+] sysstat data collection server started"
    printf "${GREEN}%s${NC}\\n" " Rate: ${sample_rate}"
    # Note operation in syslog. 'logger' is part of util-linux
    logger -t sysstat -p daemon.info -- "sysstat data collector started, sampling at every ${sample_rate} seconds"
    else
    # Don't do anything if it's already running except note this fact
    printf "${BLUE}%s${NC}\\n" "[+] systat is already running"
    fi
    ;;

    'stop')
    # Stop sadc
    if ps -C sadc 1> /dev/null; then
    killall -q sadc
    printf "${GREEN}%s${NC}\\n" "[+] sysstat halted"
    logger -t sysstat -p daemon.notice -- "sysstat shut down by rc script"
    else
    printf "${RED}%s${NC}\\n" "[-] sysstat not running"
    fi
    ;;

    'restart')
    # If it's not running, this shouldn't error out
    killall -q sadc
    sleep 1
    sane
    # Write a restart note and then proceed as in 'start' function
    $SADC -
    $SADC ${options} ${sample_rate} - &
    printf "${GREEN}%s${NC}\\n" "[+] sysstat data collection server restarted"
    printf "${GREEN}%s${NC}\\n" " Rate: ${sample_rate}"
    # Note operation in syslog.
    logger -t sysstat -p daemon.info -- "sysstat data collector restarted, sampling at every ${sample_rate} seconds"
    ;;

    'graph')
    # Output a graph to date-labeled file as an SVG image in
    # the users's home directory (which should always be writable).
    # If someone can write into the user's home for symlink attacks
    # then there are larger problems to solve.
    # 'sadf' is in /usr/bin by default.
    sadf -P ALL -T -g > ~/sysstat-graph-$(date +%b-%d-%a-%H:%M).svg && \
    printf "${GREEN}%s${NC}\\n" "Graph written in SVG format to ~/" || \
    printf "${RED}%s${NC}" "Unable to write graph to ~/"
    ;;
    *)
    # Give help/usage message on all other input and exit
    usage
    exit 1
    esac

    ## EOF
    --
    PGP Key ID: 781C A3E2 C6ED 70A6 B356 7AF5 B510 542E D460 5CAE
    "The Internet should always be the Wild West!"
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Sylvain Robitaille@syl@therockgarden.ca to alt.os.linux.slackware on Thu Sep 3 21:19:20 2026
    From Newsgroup: alt.os.linux.slackware

    On 2026-09-03, jayjwa wrote:

    sysstat comes with an rc switch, but it doesn't do much of anything.

    "an rc switch?" Do you mean the start/stop script? It starts and stops
    the data collection daemon, which if I understand things correctly, is
    what it's intended to do ...

    For years I've had another one around here but decided yesterday
    to shine it up and post it in the hopes someone would find it
    useful. It can be used to start, stop, and also output a graph in SVG.

    Your graph idea is likely useful to some, but here's what I hope
    doesn't seem like an odd question: Why not leave the start/stop
    script as it is, and just create a script to graph the collected data?
    That would strike me as a much "cleaner" approach. Simpler sometimes
    really is better.
    --
    ----------------------------------------------------------------------
    Sylvain Robitaille syl@therockgarden.ca ----------------------------------------------------------------------
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From jayjwa@jayjwa@atr2.ath.cx.invalid to alt.os.linux.slackware on Fri Sep 4 14:49:54 2026
    From Newsgroup: alt.os.linux.slackware

    Sylvain Robitaille <syl@therockgarden.ca> writes:

    Your graph idea is likely useful to some, but here's what I hope
    doesn't seem like an odd question: Why not leave the start/stop
    script as it is, and just create a script to graph the collected data?
    Because it doesn't work. No data is collected by the stock one that
    ships. Here, I stopped sysstat (really sadc) and used the stock
    rc.sysstat:

    ...
    11:49:16 AM all 14.18 0.00 1.76 0.13 0.00 83.92 12:04:16 PM all 16.87 0.01 2.27 0.15 0.00 80.70 12:19:16 PM all 15.95 0.00 1.94 0.12 0.00 81.99 Average: all 14.73 0.00 2.04 0.14 0.00 83.09

    12:34:05 PM LINUX RESTART (8 CPU) <-- stock restart here

    It is now 14:36:17 EDT 2026 (roughly two hours later) and there was no
    data reported/collected during that time frame. Of course you can run
    sa1 in a cron job but why bother cron every few minutes when the data
    collector itself (sadc) can periodically collect that data?

    The stock rc.sysstat does nothing but write a restart record. The
    status and stop clauses of the case switch do nothing but return an exit
    code to the caller.

    ./rc.sysstat.old start
    Calling the system activity data collector (sadc)...
    ps aux | grep sadc
    root 1210 0.0 0.0 6808 2716 pts/5 S+ 12:34 0:00 grep sadc

    No sadc running. My script starts/stops/restarts the whole thing. Thus,
    there's data to examine and I only rely on cron nightly to generate the reports.
    --
    PGP Key ID: 781C A3E2 C6ED 70A6 B356 7AF5 B510 542E D460 5CAE
    "The Internet should always be the Wild West!"
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Sylvain Robitaille@syl@therockgarden.ca to alt.os.linux.slackware on Sat Sep 5 16:26:52 2026
    From Newsgroup: alt.os.linux.slackware

    On 2026-09-04, jayjwa wrote:

    ... Why not leave the start/stop script as it is, and just create
    a script to graph the collected data?

    Because it doesn't work. No data is collected by the stock one that
    ships. ...
    ...
    12:34:05 PM LINUX RESTART (8 CPU) <-- stock restart here
    ...
    The stock rc.sysstat does nothing but write a restart record.

    You're right. That's exactly what it does: calls "/usr/lib/sa/sa1
    --boot", which according to the manual page,

    --boot This option tells sa1 that the sadc command should
    be called without specifying the interval and count
    parameters in order to insert a dummy record, marking
    the time when the counters restart from 0.

    Well, I apologize, then, for the dumb question. I agree that it would
    be better to have the start/stop script start the data collector
    *running*, perhaps with a "restart" mark first, and a configurable
    interval. When I call "/etc/rc.d/rc.${something} start", it seems
    to me that the intuitive result is that ${something} is running when
    that script exits.
    --
    ----------------------------------------------------------------------
    Sylvain Robitaille syl@therockgarden.ca ----------------------------------------------------------------------
    --- Synchronet 3.22a-Linux NewsLink 1.2