]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added cachemgr reporting of SBuf and MemBlob statistics
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 10 Oct 2013 08:44:03 +0000 (10:44 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 10 Oct 2013 08:44:03 +0000 (10:44 +0200)
src/Makefile.am
src/SBufStatsAction.cc [new file with mode: 0644]
src/SBufStatsAction.h [new file with mode: 0644]

index 9ef5ff4ef975e9229be22ed40c41fda0073869ae..12f19f1352ea4879578cabbf3e4585ce5041569b 100644 (file)
@@ -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 (file)
index 0000000..7fb34d4
--- /dev/null
@@ -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<const SBufStatsAction&>(action).sbdata;
+    mbdata += dynamic_cast<const SBufStatsAction&>(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 (file)
index 0000000..6292773
--- /dev/null
@@ -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 */