Skip to content

Commit 8c3aa40

Browse files
authored
Use ts::Metrics for socks metrics (#12568)
1 parent b55e505 commit 8c3aa40

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/traffic_server/SocksProxy.cc

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@
3131
#include "../iocore/eventsystem/P_VConnection.h"
3232
#include "iocore/utils/OneWayTunnel.h"
3333
#include "proxy/http/HttpSessionAccept.h"
34+
#include "tsutil/Metrics.h"
3435

3536
static DbgCtl dbg_ctl_SocksProxy("SocksProxy");
3637

37-
enum {
38-
socksproxy_http_connections_stat,
39-
socksproxy_tunneled_connections_stat,
40-
41-
socksproxy_stat_count
42-
};
43-
static RecRawStatBlock *socksproxy_stat_block;
44-
45-
#define SOCKSPROXY_INC_STAT(x) RecIncrRawStat(socksproxy_stat_block, mutex->thread_holding, x)
38+
namespace
39+
{
40+
struct {
41+
ts::Metrics::Counter::AtomicType *http_connections;
42+
ts::Metrics::Counter::AtomicType *tunneled_connections;
43+
} stats;
44+
} // namespace
4645

4746
struct SocksProxy;
4847
using SocksProxyHandler = int (SocksProxy::*)(int, void *);
@@ -508,7 +507,7 @@ SocksProxy::parse_socks_client_request(unsigned char *p)
508507
sendResp(true);
509508
state = HTTP_REQ;
510509
} else {
511-
SOCKSPROXY_INC_STAT(socksproxy_tunneled_connections_stat);
510+
ts::Metrics::Counter::increment(stats.tunneled_connections);
512511
Dbg(dbg_ctl_SocksProxy, "Tunnelling the connection for port %d", port);
513512

514513
if (clientVC->socks_addr.type != SOCKS_ATYPE_IPV4) {
@@ -555,7 +554,7 @@ SocksProxy::state_handing_over_http_request(int event, [[maybe_unused]] void *da
555554
case VC_EVENT_WRITE_COMPLETE: {
556555
HttpSessionAccept::Options ha_opt;
557556

558-
SOCKSPROXY_INC_STAT(socksproxy_http_connections_stat);
557+
ts::Metrics::Counter::increment(stats.http_connections);
559558
Dbg(dbg_ctl_SocksProxy, "Handing over the HTTP request");
560559

561560
ha_opt.transport_type = clientVC->attributes;
@@ -707,15 +706,8 @@ start_SocksProxy(int port)
707706
opt.local_port = port;
708707
netProcessor.main_accept(new SocksAccepter(), NO_FD, opt);
709708

710-
socksproxy_stat_block = RecAllocateRawStatBlock(socksproxy_stat_count);
711-
712-
if (socksproxy_stat_block) {
713-
RecRegisterRawStat(socksproxy_stat_block, RECT_PROCESS, "proxy.process.socks.proxy.http_connections", RECD_INT, RECP_PERSISTENT,
714-
socksproxy_http_connections_stat, RecRawStatSyncCount);
715-
716-
RecRegisterRawStat(socksproxy_stat_block, RECT_PROCESS, "proxy.process.socks.proxy.tunneled_connections", RECD_INT,
717-
RECP_PERSISTENT, socksproxy_tunneled_connections_stat, RecRawStatSyncCount);
718-
}
709+
stats.http_connections = ts::Metrics::Counter::createPtr("proxy.process.socks.proxy.http_connections");
710+
stats.tunneled_connections = ts::Metrics::Counter::createPtr("proxy.process.socks.proxy.tunneled_connections");
719711
}
720712

721713
int

0 commit comments

Comments
 (0)