User Tools

Site Tools


linux:serverstats_howto

[HOWTO] Serverstats

Descripción

Como poner a trabajar la herramienta serverstats

Plugins adicionales

diskinfo

He modificado el plugin ya que tenía alguna función deprecated en php y fallaba al situar los parámetros devueltos por “df

Instalación

  • Copiar el php del plugin a sources/
  • Editar el fichero config/sources.php y añadir la linea:
$config['diskinfo']['module'] = new diskinfo('/dev/mapper/partition'); 
  • Editar el fichero config/graph.php y añadir:
    • Para una gráfica porcentual:
$config['list'][] = array(
        'title' => '% /partition',
        'upperLimit' => 100,
        'lowerLimit' => 0,
        'altAutoscaleMax' => true,
        'content' => array(
                array(  
                        'type' => 'AREA',
                        'source' => 'diskinfo',
                        'ds' => 'usedpercentage',
                        'cf' => 'AVERAGE',
                        'legend' => '%',
                        'color' => 'FF0000'
                )
        )
);
  • Para una gráfica con datos reales:
$config['list'][] = array(
        'title' => 'Disk Usage /partition',
        'lowerLimit' => 0,
        'altAutoscaleMax' => true,
        'content' => array(
                array(  
                        'type' => 'AREA',
                        'source' => 'diskinfo',
                        'ds' => 'freediskspace',
                        'cf' => 'AVERAGE',
                        'legend' => 'Free Disk',
                        'color' => 'FF0000'
                ),
                array(  
                        'type' => 'AREA',
                        'source' => 'diskinfo',
                        'ds' => 'availablediskspace',
                        'cf' => 'AVERAGE',
                        'legend' => 'Total Diskspace',
                        'color' => 'FFFF00'
                )
        )
);

graph.php simple.php

Codigo

diskinfo.php
<?php
/**
 *
 * Author: Jannis Leidel, jl@concetto.net
 * Modified by: dodger, dodger@ciberterminal.net
 * Project: Serverstats, http://serverstats.berlios.de/
 * License: GPL v2 or later (http://www.gnu.org/copyleft/gpl.html)
 *
 * Copyright (C) 2006 Jannis Leidel
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
class diskinfo extends source implements source_rrd
{
        private $disk;
        private $freespace;
        private $usedspace;
        private $percentage;
        private $availablespace;
 
        public function __construct($disk = '/dev/mapper/partition')
        {
                $this->disk = $disk;
        }
 
        public function refreshData()
        {
                $return = 0;
                $datarows = array();
                exec("df -m ".$this->disk." | grep -v Filesystem| tail -1 | awk '{printf int($1)\"::\"int($2)\"::\"int($3)\"::\"int($4)}'", $datarows, $return);
//              exec("df -m ".$this->disk." | grep -v Filesystem| tail -1 | awk '{printf int($2)::int($3)::int($4)::int($5)}'", $datarows, $return);
                if ($return !== 0)
                {
                        throw new Exception('Could not read from "' . $this->disk . '"');
                }
                $cmdoutput = implode(' ', $datarows);
                $parts = explode("::",$cmdoutput);
                foreach ($parts as $key => $part) {
                        //$parts[$key] = ereg_replace("[^0-9]", "", $part);
                        $parts[$key] = preg_replace('[^0-9]', '', $part);
//                      printf("$parts[$key]\n");
                }
                $this->availablespace = $parts[0]/1024;
                $this->usedspace = $parts[1]/1024;
                $this->freespace = $parts[2]/1024;
                $this->percentage = $parts[3];
        }
 
        public function initRRD(rrd $rrd)
        {
                $rrd->addDatasource('availablediskspace', 'GAUGE', null, 0);
                $rrd->addDatasource('freediskspace', 'GAUGE', null, 0);
                $rrd->addDatasource('useddiskspace', 'GAUGE', null, 0);
                $rrd->addDatasource('usedpercentage', 'GAUGE', null, 0);
        }
 
        public function fetchValues()
        {
                $values = array();
                $values['availablediskspace'] = $this->availablespace;
                $values['useddiskspace'] = $this->usedspace;
                $values['freediskspace'] = $this->freespace;
                $values['usedpercentage'] = $this->percentage;
                return $values;
        }
}
 
?>
linux/serverstats_howto.txt · Last modified: 2022/02/11 11:36 by 127.0.0.1