]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mgr/InfoAction.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mgr / InfoAction.cc
CommitLineData
8822ebee 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
8822ebee 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
8822ebee
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 16 Cache Manager API */
10
f7f3304a 11#include "squid.h"
8822ebee 12#include "base/TextException.h"
c3e8e4e9 13#include "comm/Connection.h"
582c2af2 14#include "globals.h"
8822ebee
AR
15#include "HttpReply.h"
16#include "ipc/Messages.h"
17#include "ipc/TypedMsgHdr.h"
602d9612 18#include "ipc/UdsOp.h"
8822ebee
AR
19#include "mgr/Filler.h"
20#include "mgr/InfoAction.h"
21#include "mgr/Request.h"
22#include "mgr/Response.h"
23#include "SquidTime.h"
24#include "Store.h"
5bed43d6 25#include "tools.h"
8822ebee 26
82afb125
FC
27void GetInfo(Mgr::InfoActionData& stats);
28void DumpInfo(Mgr::InfoActionData& stats, StoreEntry* sentry);
29void DumpMallocStatistics(StoreEntry* sentry);
8822ebee
AR
30
31Mgr::InfoActionData::InfoActionData()
32{
e297be13 33 memset(this, 0, sizeof(*this));
8822ebee
AR
34}
35
36Mgr::InfoActionData&
37Mgr::InfoActionData::operator += (const InfoActionData& stats)
38{
39 if (!timerisset(&squid_start) || timercmp(&squid_start, &stats.squid_start, >))
40 squid_start = stats.squid_start;
41 if (timercmp(&current_time, &stats.current_time, <))
42 current_time = stats.current_time;
43 client_http_clients += stats.client_http_clients;
44 client_http_requests += stats.client_http_requests;
45 icp_pkts_recv += stats.icp_pkts_recv;
46 icp_pkts_sent += stats.icp_pkts_sent;
47 icp_replies_queued += stats.icp_replies_queued;
48#if USE_HTCP
49 htcp_pkts_recv += stats.htcp_pkts_recv;
50 htcp_pkts_sent += stats.htcp_pkts_sent;
51#endif
52 request_failure_ratio += stats.request_failure_ratio;
53 avg_client_http_requests += stats.avg_client_http_requests;
54 avg_icp_messages += stats.avg_icp_messages;
55 select_loops += stats.select_loops;
56 avg_loop_time += stats.avg_loop_time;
57 request_hit_ratio5 += stats.request_hit_ratio5;
58 request_hit_ratio60 += stats.request_hit_ratio60;
59 byte_hit_ratio5 += stats.byte_hit_ratio5;
60 byte_hit_ratio60 += stats.byte_hit_ratio60;
61 request_hit_mem_ratio5 += stats.request_hit_mem_ratio5;
62 request_hit_mem_ratio60 += stats.request_hit_mem_ratio60;
63 request_hit_disk_ratio5 += stats.request_hit_disk_ratio5;
64 request_hit_disk_ratio60 += stats.request_hit_disk_ratio60;
93bc1434
AR
65
66 store += stats.store;
67
8822ebee
AR
68 unlink_requests += stats.unlink_requests;
69 http_requests5 += stats.http_requests5;
70 http_requests60 += stats.http_requests60;
71 cache_misses5 += stats.cache_misses5;
72 cache_misses60 += stats.cache_misses60;
73 cache_hits5 += stats.cache_hits5;
74 cache_hits60 += stats.cache_hits60;
75 near_hits5 += stats.near_hits5;
76 near_hits60 += stats.near_hits60;
77 not_modified_replies5 += stats.not_modified_replies5;
78 not_modified_replies60 += stats.not_modified_replies60;
79 dns_lookups5 += stats.dns_lookups5;
80 dns_lookups60 += stats.dns_lookups60;
81 icp_queries5 += stats.icp_queries5;
82 icp_queries60 += stats.icp_queries60;
83 if (stats.up_time > up_time)
84 up_time = stats.up_time;
85 cpu_time += stats.cpu_time;
86 cpu_usage += stats.cpu_usage;
87 cpu_usage5 += stats.cpu_usage5;
88 cpu_usage60 += stats.cpu_usage60;
8822ebee
AR
89 maxrss += stats.maxrss;
90 page_faults += stats.page_faults;
91#if HAVE_MSTATS && HAVE_GNUMALLOC_H
92 ms_bytes_total += stats.ms_bytes_total;
93 ms_bytes_free += stats.ms_bytes_free;
8822ebee 94#endif
4572073a 95 total_accounted += stats.total_accounted;
8822ebee
AR
96 gb_saved_count += stats.gb_saved_count;
97 gb_freed_count += stats.gb_freed_count;
98 max_fd += stats.max_fd;
4b04bce6 99 biggest_fd = max(biggest_fd, stats.biggest_fd);
8822ebee
AR
100 number_fd += stats.number_fd;
101 opening_fd += stats.opening_fd;
102 num_fd_free += stats.num_fd_free;
103 reserved_fd += stats.reserved_fd;
8822ebee
AR
104 ++count;
105
106 return *this;
107}
108
109Mgr::InfoAction::Pointer
110Mgr::InfoAction::Create(const CommandPointer &cmd)
111{
112 return new InfoAction(cmd);
113}
114
9dca980d 115Mgr::InfoAction::InfoAction(const CommandPointer &aCmd):
f53969cc 116 Action(aCmd), data()
8822ebee
AR
117{
118 debugs(16, 5, HERE);
119}
120
121void
122Mgr::InfoAction::add(const Action& action)
123{
124 debugs(16, 5, HERE);
125 data += dynamic_cast<const InfoAction&>(action).data;
126}
127
128void
129Mgr::InfoAction::respond(const Request& request)
130{
131 debugs(16, 5, HERE);
1b76e6c1
AJ
132 Ipc::ImportFdIntoComm(request.conn, SOCK_STREAM, IPPROTO_TCP, Ipc::fdnHttpSocket);
133 Must(Comm::IsConnOpen(request.conn));
8822ebee 134 Must(request.requestId != 0);
1b76e6c1 135 AsyncJob::Start(new Mgr::Filler(this, request.conn, request.requestId));
8822ebee
AR
136}
137
138void
139Mgr::InfoAction::collect()
140{
141 GetInfo(data);
142}
143
144void
145Mgr::InfoAction::dump(StoreEntry* entry)
146{
147 debugs(16, 5, HERE);
148 Must(entry != NULL);
149
150#if XMALLOC_STATISTICS
39c1e1d9 151 if (UsingSmp())
8822ebee
AR
152 storeAppendPrintf(entry, "by kid%d {\n", KidIdentifier);
153 DumpMallocStatistics(entry);
39c1e1d9 154 if (UsingSmp())
8822ebee
AR
155 storeAppendPrintf(entry, "} by kid%d\n\n", KidIdentifier);
156#endif
157 if (IamPrimaryProcess())
158 DumpInfo(data, entry);
159}
160
161void
162Mgr::InfoAction::pack(Ipc::TypedMsgHdr& msg) const
163{
164 msg.setType(Ipc::mtCacheMgrResponse);
165 msg.putPod(data);
166}
167
168void
169Mgr::InfoAction::unpack(const Ipc::TypedMsgHdr& msg)
170{
171 msg.checkType(Ipc::mtCacheMgrResponse);
172 msg.getPod(data);
173}
f53969cc 174