]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mgr/InfoAction.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mgr / InfoAction.cc
CommitLineData
8822ebee
AR
1/*
2 * $Id$
3 *
4 * DEBUG: section 16 Cache Manager API
5 *
6 */
7
f7f3304a 8#include "squid.h"
8822ebee 9#include "base/TextException.h"
c3e8e4e9 10#include "comm/Connection.h"
582c2af2 11#include "globals.h"
8822ebee
AR
12#include "HttpReply.h"
13#include "ipc/Messages.h"
51ea0904 14#include "ipc/UdsOp.h"
8822ebee
AR
15#include "ipc/TypedMsgHdr.h"
16#include "mgr/Filler.h"
17#include "mgr/InfoAction.h"
18#include "mgr/Request.h"
19#include "mgr/Response.h"
582c2af2 20#include "protos.h"
8822ebee
AR
21#include "SquidTime.h"
22#include "Store.h"
23
8822ebee
AR
24extern void GetInfo(Mgr::InfoActionData& stats);
25extern void DumpInfo(Mgr::InfoActionData& stats, StoreEntry* sentry);
26extern void DumpMallocStatistics(StoreEntry* sentry);
27
28Mgr::InfoActionData::InfoActionData()
29{
30 xmemset(this, 0, sizeof(*this));
31}
32
33Mgr::InfoActionData&
34Mgr::InfoActionData::operator += (const InfoActionData& stats)
35{
36 if (!timerisset(&squid_start) || timercmp(&squid_start, &stats.squid_start, >))
37 squid_start = stats.squid_start;
38 if (timercmp(&current_time, &stats.current_time, <))
39 current_time = stats.current_time;
40 client_http_clients += stats.client_http_clients;
41 client_http_requests += stats.client_http_requests;
42 icp_pkts_recv += stats.icp_pkts_recv;
43 icp_pkts_sent += stats.icp_pkts_sent;
44 icp_replies_queued += stats.icp_replies_queued;
45#if USE_HTCP
46 htcp_pkts_recv += stats.htcp_pkts_recv;
47 htcp_pkts_sent += stats.htcp_pkts_sent;
48#endif
49 request_failure_ratio += stats.request_failure_ratio;
50 avg_client_http_requests += stats.avg_client_http_requests;
51 avg_icp_messages += stats.avg_icp_messages;
52 select_loops += stats.select_loops;
53 avg_loop_time += stats.avg_loop_time;
54 request_hit_ratio5 += stats.request_hit_ratio5;
55 request_hit_ratio60 += stats.request_hit_ratio60;
56 byte_hit_ratio5 += stats.byte_hit_ratio5;
57 byte_hit_ratio60 += stats.byte_hit_ratio60;
58 request_hit_mem_ratio5 += stats.request_hit_mem_ratio5;
59 request_hit_mem_ratio60 += stats.request_hit_mem_ratio60;
60 request_hit_disk_ratio5 += stats.request_hit_disk_ratio5;
61 request_hit_disk_ratio60 += stats.request_hit_disk_ratio60;
93bc1434
AR
62
63 store += stats.store;
64
8822ebee
AR
65 unlink_requests += stats.unlink_requests;
66 http_requests5 += stats.http_requests5;
67 http_requests60 += stats.http_requests60;
68 cache_misses5 += stats.cache_misses5;
69 cache_misses60 += stats.cache_misses60;
70 cache_hits5 += stats.cache_hits5;
71 cache_hits60 += stats.cache_hits60;
72 near_hits5 += stats.near_hits5;
73 near_hits60 += stats.near_hits60;
74 not_modified_replies5 += stats.not_modified_replies5;
75 not_modified_replies60 += stats.not_modified_replies60;
76 dns_lookups5 += stats.dns_lookups5;
77 dns_lookups60 += stats.dns_lookups60;
78 icp_queries5 += stats.icp_queries5;
79 icp_queries60 += stats.icp_queries60;
80 if (stats.up_time > up_time)
81 up_time = stats.up_time;
82 cpu_time += stats.cpu_time;
83 cpu_usage += stats.cpu_usage;
84 cpu_usage5 += stats.cpu_usage5;
85 cpu_usage60 += stats.cpu_usage60;
86#if HAVE_SBRK
87 proc_data_seg += stats.proc_data_seg;
88#endif
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;
94#elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
95 mp_arena += stats.mp_arena;
96 mp_uordblks += stats.mp_uordblks;
97 mp_ordblks += stats.mp_ordblks;
98 mp_usmblks += stats.mp_usmblks;
99 mp_smblks += stats.mp_smblks;
100 mp_hblkhd += stats.mp_hblkhd;
101 mp_hblks += stats.mp_hblks;
102 mp_fsmblks += stats.mp_fsmblks;
103 mp_fordblks += stats.mp_fordblks;
104#if HAVE_STRUCT_MALLINFO_MXFAST
105 mp_mxfast += stats.mp_mxfast;
106 mp_nlblks += stats.mp_nlblks;
107 mp_grain += stats.mp_grain;
108 mp_uordbytes += stats.mp_uordbytes;
109 mp_allocated += stats.mp_allocated;
110 mp_treeoverhead += stats.mp_treeoverhead;
111#endif
112#endif
113 total_accounted += stats.total_accounted;
114#if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
115 mem_pool_allocated += stats.mem_pool_allocated;
116#endif
117 gb_saved_count += stats.gb_saved_count;
118 gb_freed_count += stats.gb_freed_count;
119 max_fd += stats.max_fd;
120 biggest_fd += stats.biggest_fd;
121 number_fd += stats.number_fd;
122 opening_fd += stats.opening_fd;
123 num_fd_free += stats.num_fd_free;
124 reserved_fd += stats.reserved_fd;
8822ebee
AR
125 ++count;
126
127 return *this;
128}
129
130Mgr::InfoAction::Pointer
131Mgr::InfoAction::Create(const CommandPointer &cmd)
132{
133 return new InfoAction(cmd);
134}
135
136Mgr::InfoAction::InfoAction(const CommandPointer &cmd):
d9fc6862 137 Action(cmd), data()
8822ebee
AR
138{
139 debugs(16, 5, HERE);
140}
141
142void
143Mgr::InfoAction::add(const Action& action)
144{
145 debugs(16, 5, HERE);
146 data += dynamic_cast<const InfoAction&>(action).data;
147}
148
149void
150Mgr::InfoAction::respond(const Request& request)
151{
152 debugs(16, 5, HERE);
1b76e6c1
AJ
153 Ipc::ImportFdIntoComm(request.conn, SOCK_STREAM, IPPROTO_TCP, Ipc::fdnHttpSocket);
154 Must(Comm::IsConnOpen(request.conn));
8822ebee 155 Must(request.requestId != 0);
1b76e6c1 156 AsyncJob::Start(new Mgr::Filler(this, request.conn, request.requestId));
8822ebee
AR
157}
158
159void
160Mgr::InfoAction::collect()
161{
162 GetInfo(data);
163}
164
165void
166Mgr::InfoAction::dump(StoreEntry* entry)
167{
168 debugs(16, 5, HERE);
169 Must(entry != NULL);
170
171#if XMALLOC_STATISTICS
39c1e1d9 172 if (UsingSmp())
8822ebee
AR
173 storeAppendPrintf(entry, "by kid%d {\n", KidIdentifier);
174 DumpMallocStatistics(entry);
39c1e1d9 175 if (UsingSmp())
8822ebee
AR
176 storeAppendPrintf(entry, "} by kid%d\n\n", KidIdentifier);
177#endif
178 if (IamPrimaryProcess())
179 DumpInfo(data, entry);
180}
181
182void
183Mgr::InfoAction::pack(Ipc::TypedMsgHdr& msg) const
184{
185 msg.setType(Ipc::mtCacheMgrResponse);
186 msg.putPod(data);
187}
188
189void
190Mgr::InfoAction::unpack(const Ipc::TypedMsgHdr& msg)
191{
192 msg.checkType(Ipc::mtCacheMgrResponse);
193 msg.getPod(data);
194}