]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mgr/InfoAction.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / mgr / InfoAction.cc
CommitLineData
8822ebee 1/*
77b1029d 2 * Copyright (C) 1996-2020 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 30
8822ebee
AR
31Mgr::InfoActionData&
32Mgr::InfoActionData::operator += (const InfoActionData& stats)
33{
34 if (!timerisset(&squid_start) || timercmp(&squid_start, &stats.squid_start, >))
35 squid_start = stats.squid_start;
36 if (timercmp(&current_time, &stats.current_time, <))
37 current_time = stats.current_time;
38 client_http_clients += stats.client_http_clients;
39 client_http_requests += stats.client_http_requests;
40 icp_pkts_recv += stats.icp_pkts_recv;
41 icp_pkts_sent += stats.icp_pkts_sent;
42 icp_replies_queued += stats.icp_replies_queued;
43#if USE_HTCP
44 htcp_pkts_recv += stats.htcp_pkts_recv;
45 htcp_pkts_sent += stats.htcp_pkts_sent;
46#endif
47 request_failure_ratio += stats.request_failure_ratio;
48 avg_client_http_requests += stats.avg_client_http_requests;
49 avg_icp_messages += stats.avg_icp_messages;
50 select_loops += stats.select_loops;
51 avg_loop_time += stats.avg_loop_time;
52 request_hit_ratio5 += stats.request_hit_ratio5;
53 request_hit_ratio60 += stats.request_hit_ratio60;
54 byte_hit_ratio5 += stats.byte_hit_ratio5;
55 byte_hit_ratio60 += stats.byte_hit_ratio60;
56 request_hit_mem_ratio5 += stats.request_hit_mem_ratio5;
57 request_hit_mem_ratio60 += stats.request_hit_mem_ratio60;
58 request_hit_disk_ratio5 += stats.request_hit_disk_ratio5;
59 request_hit_disk_ratio60 += stats.request_hit_disk_ratio60;
93bc1434
AR
60
61 store += stats.store;
62
8822ebee
AR
63 unlink_requests += stats.unlink_requests;
64 http_requests5 += stats.http_requests5;
65 http_requests60 += stats.http_requests60;
66 cache_misses5 += stats.cache_misses5;
67 cache_misses60 += stats.cache_misses60;
68 cache_hits5 += stats.cache_hits5;
69 cache_hits60 += stats.cache_hits60;
70 near_hits5 += stats.near_hits5;
71 near_hits60 += stats.near_hits60;
72 not_modified_replies5 += stats.not_modified_replies5;
73 not_modified_replies60 += stats.not_modified_replies60;
74 dns_lookups5 += stats.dns_lookups5;
75 dns_lookups60 += stats.dns_lookups60;
76 icp_queries5 += stats.icp_queries5;
77 icp_queries60 += stats.icp_queries60;
78 if (stats.up_time > up_time)
79 up_time = stats.up_time;
80 cpu_time += stats.cpu_time;
81 cpu_usage += stats.cpu_usage;
82 cpu_usage5 += stats.cpu_usage5;
83 cpu_usage60 += stats.cpu_usage60;
8822ebee
AR
84 maxrss += stats.maxrss;
85 page_faults += stats.page_faults;
86#if HAVE_MSTATS && HAVE_GNUMALLOC_H
87 ms_bytes_total += stats.ms_bytes_total;
88 ms_bytes_free += stats.ms_bytes_free;
8822ebee 89#endif
4572073a 90 total_accounted += stats.total_accounted;
8822ebee
AR
91 gb_saved_count += stats.gb_saved_count;
92 gb_freed_count += stats.gb_freed_count;
93 max_fd += stats.max_fd;
4b04bce6 94 biggest_fd = max(biggest_fd, stats.biggest_fd);
8822ebee
AR
95 number_fd += stats.number_fd;
96 opening_fd += stats.opening_fd;
97 num_fd_free += stats.num_fd_free;
98 reserved_fd += stats.reserved_fd;
8822ebee
AR
99 ++count;
100
101 return *this;
102}
103
104Mgr::InfoAction::Pointer
105Mgr::InfoAction::Create(const CommandPointer &cmd)
106{
107 return new InfoAction(cmd);
108}
109
9dca980d 110Mgr::InfoAction::InfoAction(const CommandPointer &aCmd):
f53969cc 111 Action(aCmd), data()
8822ebee
AR
112{
113 debugs(16, 5, HERE);
114}
115
116void
117Mgr::InfoAction::add(const Action& action)
118{
119 debugs(16, 5, HERE);
120 data += dynamic_cast<const InfoAction&>(action).data;
121}
122
123void
124Mgr::InfoAction::respond(const Request& request)
125{
126 debugs(16, 5, HERE);
1b76e6c1
AJ
127 Ipc::ImportFdIntoComm(request.conn, SOCK_STREAM, IPPROTO_TCP, Ipc::fdnHttpSocket);
128 Must(Comm::IsConnOpen(request.conn));
8822ebee 129 Must(request.requestId != 0);
1b76e6c1 130 AsyncJob::Start(new Mgr::Filler(this, request.conn, request.requestId));
8822ebee
AR
131}
132
133void
134Mgr::InfoAction::collect()
135{
136 GetInfo(data);
137}
138
139void
140Mgr::InfoAction::dump(StoreEntry* entry)
141{
142 debugs(16, 5, HERE);
143 Must(entry != NULL);
144
145#if XMALLOC_STATISTICS
39c1e1d9 146 if (UsingSmp())
8822ebee
AR
147 storeAppendPrintf(entry, "by kid%d {\n", KidIdentifier);
148 DumpMallocStatistics(entry);
39c1e1d9 149 if (UsingSmp())
8822ebee
AR
150 storeAppendPrintf(entry, "} by kid%d\n\n", KidIdentifier);
151#endif
152 if (IamPrimaryProcess())
153 DumpInfo(data, entry);
154}
155
156void
157Mgr::InfoAction::pack(Ipc::TypedMsgHdr& msg) const
158{
159 msg.setType(Ipc::mtCacheMgrResponse);
160 msg.putPod(data);
161}
162
163void
164Mgr::InfoAction::unpack(const Ipc::TypedMsgHdr& msg)
165{
166 msg.checkType(Ipc::mtCacheMgrResponse);
167 msg.getPod(data);
168}
f53969cc 169