User Tools

Site Tools


linux:serverstats_howto

This is an old revision of the document!


Descripción

Como poner a trabajar la herramienta serverstats

Plugins adicionales

diskinfo

<?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/huge_vg-rtorrent')
        {
                $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.1331123418.txt.gz · Last modified: 2012/03/07 12:30 by dodger