From 9b74279f16f119159893e3b5855d58304b2df67a Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Thu, 10 Oct 2013 10:44:03 +0200 Subject: [PATCH] Added cachemgr reporting of SBuf and MemBlob statistics --- src/Makefile.am | 2 + src/SBufStatsAction.cc | 89 ++++++++++++++++++++++++++++++++++++++++++ src/SBufStatsAction.h | 60 ++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 src/SBufStatsAction.cc create mode 100644 src/SBufStatsAction.h diff --git a/src/Makefile.am b/src/Makefile.am index 9ef5ff4ef9..12f19f1352 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -465,6 +465,8 @@ squid_SOURCES = \ send-announce.h \ send-announce.cc \ $(SBUF_SOURCE) \ + SBufStatsAction.h \ + SBufStatsAction.cc \ $(SNMP_SOURCE) \ SquidMath.h \ SquidMath.cc \ diff --git a/src/SBufStatsAction.cc b/src/SBufStatsAction.cc new file mode 100644 index 0000000000..7fb34d47e5 --- /dev/null +++ b/src/SBufStatsAction.cc @@ -0,0 +1,89 @@ +/* + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + */ + +#include "squid.h" +#include "ipc/Messages.h" +#include "ipc/TypedMsgHdr.h" +#include "mgr/Registration.h" +#include "SBufStatsAction.h" +#include "StoreEntryStream.h" + +SBufStatsAction::SBufStatsAction(const Mgr::CommandPointer &cmd_): + Action(cmd_) +{ } //default constructor is OK for data member + +SBufStatsAction::Pointer +SBufStatsAction::Create(const Mgr::CommandPointer &cmd) +{ + return new SBufStatsAction(cmd); +} + +void +SBufStatsAction::add(const Mgr::Action& action) +{ + sbdata += dynamic_cast(action).sbdata; + mbdata += dynamic_cast(action).mbdata; +} + +void +SBufStatsAction::collect() +{ + sbdata = SBuf::GetStats(); + mbdata = MemBlob::GetStats(); +} + +void +SBufStatsAction::dump(StoreEntry* entry) +{ + StoreEntryStream ses(entry); + sbdata.dump(ses); + mbdata.dump(ses); + ses << "\n\n\nThese statistics are experimental; their format and contents " + "should not be relied upon, they are bound to change as " + "the SBuf feature is evolved"; +} + +void +SBufStatsAction::pack(Ipc::TypedMsgHdr& msg) const +{ + msg.setType(Ipc::mtCacheMgrResponse); + msg.putPod(sbdata); + msg.putPod(mbdata); +} + +void +SBufStatsAction::unpack(const Ipc::TypedMsgHdr& msg) +{ + msg.checkType(Ipc::mtCacheMgrResponse); + msg.getPod(sbdata); + msg.getPod(mbdata); +} + +static const bool Registered = (Mgr::RegisterAction("sbuf", + "String-Buffer statistics", &SBufStatsAction::Create, 0 , 1), + true); diff --git a/src/SBufStatsAction.h b/src/SBufStatsAction.h new file mode 100644 index 0000000000..629277305d --- /dev/null +++ b/src/SBufStatsAction.h @@ -0,0 +1,60 @@ +/* + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + */ + +#ifndef SQUID_SBUFEXTRAS_H +#define SQUID_SBUFEXTRAS_H + +#include "mgr/Action.h" +#include "SBuf.h" + +class StoreEntry; + +/// SBuf stats for cachemgr +class SBufStatsAction: public Mgr::Action +{ +public: + /// Mgr::ClassActionCreationHandler for Mgr::RegisterAction() + static Pointer Create(const Mgr::CommandPointer &cmd); + +protected: + explicit SBufStatsAction(const Mgr::CommandPointer &cmd); + /* Mgr::Action API */ + virtual void collect(); + virtual void dump(StoreEntry* entry); + +private: + /* Mgr::Action API */ + virtual void add(const Mgr::Action& action); + virtual void pack(Ipc::TypedMsgHdr& msg) const; + virtual void unpack(const Ipc::TypedMsgHdr& msg); + + SBufStats sbdata; + MemBlobStats mbdata; +}; + +#endif /* SQUID_SBUFSTATSACTION_H */ -- 2.47.3