NetsGraph (https://github.com/fubralimited/NetsGraph) is a simple Free Open Source PHP class to generate statistical graphics from network data transfer.
While several free tools are available to create graphs from network data, after some quick research I couldn’t find a good fit for our needs here at CatN. So I decided to create a new tool that we can use for Customer reports, statistical analysis and billing purposes – that tool is NetsGraph.
The NetsGraph class accepts as input a list of samples representing the average network data transfer on a specified interval, and is able to create native SVG graphics or PNG format. It is also possible to get an array of data containing statistical information.
Usually the source data comes from a router in the format of an array (list) of elements composed by a time-stamp string (YYYY-MM-DD HH:MM:SS) and a 32 bit rolling counter in B/s (bytes-per-second).
Several arrays of this type can be combined on the same graph, so we can merge for instance the incoming and outgoing traffic. For example:
$data = array( array ( '2012-03-01 00:00:05' => 3.69538e+09, '2012-03-01 00:01:05' => 3.93893e+09, '2012-03-01 00:02:05' => 4.18751e+09, '2012-03-01 00:03:04' => 1.20553e+08, '2012-03-01 00:04:05' => 3.41505e+08, '2012-03-01 00:05:05' => 5.86818e+08, // ... ), );
Is it also possible to specify as input a pre-processed array were the keys are UNIX EPOCH timestamps and the values are the differential value in the sampling interval expressed in bit/s (bits-per-second).
$data = array( 1330560125 => 33144000 1330560184 => 30916650.169492, 1330560245 => 28977311.47541, 1330560305 => 32708400, 1330560365 => 30713466.666667, 1330560425 => 25576133.333333, // ... );
The class can export data as SVG vector graph, PNG image or simple array of statistics.
The SVG format allows to store the graphs using a small amount of memory, post-process them without losing quality and use them for high-quality printed reports or real-time monitoring display.
Two main graphs types are available:
a) Time Graph
This graph shows the variation of network data rate on the selected time interval.
b) Percentile Graph
This graph shows the ordered data samples and the 95th percentile info.
The 95th percentile calculation is used for billing purposes, is a way to meter bandwidth usage that allows a customer to burst beyond their committed base rate.
The grid lines intervals and units of measure multipliers are automatically selected depending of input data and graph size.
Numerous options are available to change and tune the graphic output. Is it possible to change the colours, the size of the lines and fonts. It is also possible to display/hide the statistical box containing the following information:
- samples: total number of data samples.
- tot data: total amount of data transfer (the integral of the curve).
- sum: sum of all samples.
- min: minimum sample value.
- max: maximum sample value.
- range: difference between the maximum and minimum value on data samples.
- mean: the arithmetic mean of the data samples values.
- median: the numerical value separating the higher half of samples.
- mode: the value that occurs most frequently in data samples.
- stddev: standard deviation – shows how much variation or “dispersion” exists from the mean value.
- skewness: measure the symmetry or asymmetry of the curve.
- kurtosis: measure whether the data are peaked or flat relative to a normal distribution.
- 95th prc: the value of data sample below which a certain percent (95%) of observations fall.
- prc/max: ratio between 95th percentile and maximum value.
- mean/prc: ratio between mean and 95th percentile.
- med/prc: ratio between median and 95th percentile.
- mode/prc: ratio between mode and 95th percentile.
This class is freely available at https://github.com/fubralimited/NetsGraph and, since it is still at experimental stage, your feedback and suggestions are welcome.