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