/sysstat_parser

parser for sysstat commands, such as sar.

Primary LanguageRuby

Sysstat parsers written in ruby.

* Commands
** sar2csv.rb
*** Usage: sar2csv [--os OS | --exclude REGEXP | --dump | --debug LEVEL | --header-only] SAR_OUTPUT
         parse SAR_OUTPUT and print in CSV format.
         OS is an operating system on which SAR_OUTPUT created.
           "linux", "macosx", and "solaris" are supported.
         SAR_OUTPUT is output of "sar -f SARDATA".
         You can exclude metrics using REGEXP.

*** Mappings between sar metrics and CSV columns:
Sar output has 3 kinds of formats.
  (1) metrics contains 1 counter, such as proc/s statistics (-c)
  (2) metrics contains some counters, such as memory statistics (-R)
  (3) metrics contains multiple instances where each has some counters, such as CPU usage (-P ALL), network statistics (-n DEV)

CSV column names have their conventions:
  (i) "metric.counter" for (1) and (2)
      e.g. proc:proc/s, memory:frmpg/s
  (ii) "metric.instance":counter" for (3)
      e.g. cpu.0:%user, net_edev.eth0:rxdrop/s

For example, when the sar output is like this:
  17:00:59       proc/s
  17:01:09        11.89
  17:01:19         0.00
  17:01:29         0.00

  17:00:59      frmpg/s   bufpg/s   campg/s
  17:01:09        30.27      3.30     65.73
  17:01:19        81.00      2.00      1.50
  17:01:29        80.80      1.90      1.90
  
  17:00:59          CPU     %user     %nice   %system   %iowait    %steal     %idle
  17:01:09          all      0.07      0.00      0.10      0.02      0.00     99.80
  17:01:09            0      0.10      0.00      0.10      0.00      0.00     99.80
  17:01:09            1      0.20      0.00      0.40      0.00      0.00     99.40
  17:01:19          all      0.01      0.00      0.02      0.00      0.00     99.97
  17:01:19            0      0.00      0.00      0.00      0.00      0.00    100.00
  17:01:19            1      0.00      0.00      0.20      0.00      0.00     99.80
  17:01:29          all      0.00      0.00      0.01      0.00      0.00     99.99
  17:01:29            0      0.00      0.00      0.00      0.00      0.00    100.00
  17:01:29            1      0.00      0.00      0.00      0.00      0.00    100.00

then converted CSV lines are:
  time, cpu.all:%user, cpu.all:%nice, cpu.all:%system, cpu.all:%iowait, cpu.all:%steal, cpu.all:%idle, cpu.0:%user, cpu.0:%nice, cpu.0:%system, cpu.0:%iowait, cpu.0:%steal, cpu.0:%idle, cpu.1:%user, cpu.1:%nice, cpu.1:%system, cpu.1:%iowait, cpu.1:%steal, cpu.1:%idle, memory:frmpg/s, memory:bufpg/s, memory:campg/s, proc:proc/s,
  17:01:09, 0.07, 0.00, 0.10, 0.02, 0.00, 99.80, 0.10, 0.00, 0.10, 0.00, 0.00, 99.80, 0.20, 0.00, 0.40, 0.00, 0.00, 99.40, 30.27, 3.30, 65.73, 11.89,
  17:01:19, 0.01, 0.00, 0.02, 0.00, 0.00, 99.97, 0.00, 0.00, 0.00, 0.00, 0.00, 100.00, 0.00, 0.00, 0.20, 0.00, 0.00, 99.80, 81.00, 2.00, 1.50, 0.00,
  17:01:29, 0.00, 0.00, 0.01, 0.00, 0.00, 99.99, 0.00, 0.00, 0.00, 0.00, 0.00, 100.00, 0.00, 0.00, 0.00, 0.00, 0.00, 100.00, 80.80, 1.90, 1.90, 0.00,

** vmstat2csv.rb
*** Usage: vmstat2csv.rb [--os OS | --dump | --debug LEVEL] VMSTAT_OUTPUT
         parse VMSTAT_OUTPUT and print in CSV format.
         OS is an operating system on which VMSTAT_OUTPUT created.
           "linux", "macosx", and "solaris" are supported.

** iostat2csv.rb
*** Usage: iostat2csv.rb [--os OS | --exclude REGEXP | --dump | --debug LEVEL] IOSTAT_OUTPUT
         parse VMSTAT_OUTPUT and print in CSV format.
         OS is an operating system on which IOSTAT_OUTPUT created.
           "linux" is supported.
         You can exclude devices using REGEXP.

* Supported/Tested sysstat commands:
** RHEL4, 5, 6
  - sar
  - vmstat
  - iostat

** MacOSX 10.6
  - sar
  - vmstat

** Solaris10
  - sar
  - vmstat

* Modules
** Sysstat::Sar
*** How to use:
  require 'sysstat/sar'

  # create an instance
  sar = Sysstat::SarFactory.create(%x{uname -s})

  # parse output of "sar -f sardata"
  sar.parse(filename)

  # you can filter unneeded metrics
  sar.exclude_filter = /intr_xall|net_e?dev\.(lo|sit|usb)/

  # print in CSV format
  sar.print_csv_header
  sar.print_csv_data

*** Metrics of sar
  name		sar option	description
  ----		----------	-----------
  proc		-b		process creation activity
  cswch		-w		system switching activity
  cpu		-u		CPU utilization
  intr_cpu	-I		statistics for a given interrupt
  intr_xall	-I XALL 	statistics for a given interrupt
  swap		-W		swapping statistics
  tps		-b		I/O and transfer rate statistics
  memory	-R		memory statistics
  net_dev	-n DEV		network statistics
  net_edev	-n EDEV		network statistics
  net_nfs	-n NFS		network statistics
  net_nfsd	-n NFSD		network statistics
  net_sock	-n SOCK		network statistics
  paging	-B		paging statistics
  memswap	-r		memory and swap space utilization statistics
  inode		-v		status of inode, file and other kernel tables
  runq		-q		queue length and load averages
  blkdev	-d		activity for each block device
  pid		-x pid|SELF|ALL	statistics for a given process
  ppid		-X pid|SELF|ALL	statistics for the child processes of the process
  tty		-y		TTY device activity