Difference between revisions of "Sar/Visualize CPU data"

From braindump
Jump to navigation Jump to search
(Created page with "This is a five minute guide how to visualize Linux's <tt>sar</tt> data provided by the <tt>sysstat</tt> utility without a lot of mangeling the data. == Goal == Create CPU gr...")
 
Line 12: Line 12:
=== Dumping the <tt>sar</tt> data with <tt>sadf</tt> ===
=== Dumping the <tt>sar</tt> data with <tt>sadf</tt> ===
The data <tt>sar</tt> collects is in binary format and needs to be converted first to a format that can be imported into <tt>R</tt>. This is done with the <tt>sadf</tt> command which converts the collected data into tabular data delimited by semicolon.
The data <tt>sar</tt> collects is in binary format and needs to be converted first to a format that can be imported into <tt>R</tt>. This is done with the <tt>sadf</tt> command which converts the collected data into tabular data delimited by semicolon.
sadf -t -d -P ALL <sar file> > <output>
sadf -t -d -P ALL <span class="input"><sar-file></span> > <span class="input"><output></span>


=== Importing the data into R ===
=== Importing the data into R ===

Revision as of 20:40, 8 June 2014

This is a five minute guide how to visualize Linux's sar data provided by the sysstat utility without a lot of mangeling the data.

Goal

Create CPU graphs in R from the sar utility without massaging the output data too much.

Prerequisites

  • The Linux sysstat package installed and configured to report performance data.
  • R
  • ggplot2 R library

Howto

Dumping the sar data with sadf

The data sar collects is in binary format and needs to be converted first to a format that can be imported into R. This is done with the sadf command which converts the collected data into tabular data delimited by semicolon.

sadf -t -d -P ALL <sar-file> > <output>

Importing the data into R

The next step is to read the tabular data into R and print the graphs there are just a handful of commands to do this. In R type the following commands.

library( ggplot2 )
cpu.data <- read.csv( file="<sadf output>", sep=";" )
cpu.data$timestamp <- as.POSIXct( cpu.data$timestamp )
cpu.data$CPU[ cpu.data$CPU == "-1" ] <- "all"
ggplot( data=cpu.data, aes( x=timestamp, y=user, group=CPU, colour=CPU ) ) + geom_line()