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