/* * StatusRequestHandler.cpp * * Copyright (C) 2008 Matthias Schiffer * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation, either version 3 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this program. If not, see . */ #include "StatusRequestHandler.h" #include "../SystemManager.h" namespace Mad { namespace Common { namespace RequestHandlers { void StatusRequestHandler::handleRequest(boost::shared_ptr /*packet*/, Common::XmlPacket *ret) { if(!getConnection()->isAuthenticated()) throw(Core::Exception(Core::Exception::PERMISSION)); ret->setType("OK"); try { unsigned long uptime, idleTime; getApplication()->getSystemManager()->getUptimeInfo(&uptime, &idleTime); ret->set("uptime", uptime); ret->set("idleTime", idleTime); } catch(Core::Exception e) {} try { unsigned long totalMem, freeMem, totalSwap, freeSwap; getApplication()->getSystemManager()->getMemoryInfo(&totalMem, &freeMem, &totalSwap, &freeSwap); ret->set("totalMem", totalMem); ret->set("freeMem", freeMem); ret->set("totalSwap", totalSwap); ret->set("freeSwap", freeSwap); } catch(Core::Exception e) {} try { unsigned long currentLoad, nProcesses; float loadAvg1, loadAvg5, loadAvg15; getApplication()->getSystemManager()->getLoadInfo(¤tLoad, &nProcesses, &loadAvg1, &loadAvg5, &loadAvg15); ret->set("currentLoad", currentLoad); ret->set("nProcesses", nProcesses); ret->set("loadAvg1", loadAvg1); ret->set("loadAvg5", loadAvg5); ret->set("loadAvg15", loadAvg15); } catch(Core::Exception e) {} } } } }