You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2017/07/20 09:21:14 UTC
[trafficserver] branch master updated: Adding a stat page for HTTP
connection count
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 6d89c1c Adding a stat page for HTTP connection count
6d89c1c is described below
commit 6d89c1cf010754b0555cb1b45bf8255d41700b3a
Author: Zizhong Zhang <zi...@linkedin.com>
AuthorDate: Mon Mar 27 10:32:56 2017 -0700
Adding a stat page for HTTP connection count
---
proxy/http/HttpConnectionCount.cc | 51 +++++++++++++++++++++++++++++++++++++++
proxy/http/HttpConnectionCount.h | 42 ++++++++++++++++++++++++++++++++
proxy/http/HttpProxyServerMain.cc | 4 +++
3 files changed, 97 insertions(+)
diff --git a/proxy/http/HttpConnectionCount.cc b/proxy/http/HttpConnectionCount.cc
index 3966ce0..faf1b9f 100644
--- a/proxy/http/HttpConnectionCount.cc
+++ b/proxy/http/HttpConnectionCount.cc
@@ -25,3 +25,54 @@
ConnectionCount ConnectionCount::_connectionCount;
ConnectionCountQueue ConnectionCountQueue::_connectionCount;
+
+std::string
+ConnectionCount::dumpToJSON()
+{
+ Vec<ConnAddr> keys;
+ ink_mutex_acquire(&_mutex);
+ _hostCount.get_keys(keys);
+ std::ostringstream oss;
+ oss << '{';
+ appendJSONPair(oss, "connectionCountSize", keys.n);
+ oss << ", \"connectionCountList\": [";
+ for (size_t i = 0; i < keys.n; i++) {
+ oss << '{';
+
+ appendJSONPair(oss, "ip", keys[i].getIpStr());
+ oss << ',';
+
+ appendJSONPair(oss, "port", keys[i]._addr.host_order_port());
+ oss << ',';
+
+ appendJSONPair(oss, "hostname_hash", keys[i].getHostnameHashStr());
+ oss << ',';
+
+ appendJSONPair(oss, "connection_count", _hostCount.get(keys[i]));
+ oss << "}";
+
+ if (i < keys.n - 1)
+ oss << ',';
+ }
+ ink_mutex_release(&_mutex);
+ oss << "]}";
+ return oss.str();
+}
+
+struct ShowConnectionCount : public ShowCont {
+ ShowConnectionCount(Continuation *c, HTTPHdr *h) : ShowCont(c, h) { SET_HANDLER(&ShowConnectionCount::showHandler); }
+ int
+ showHandler(int event, Event *e)
+ {
+ CHECK_SHOW(show(ConnectionCount::getInstance()->dumpToJSON().c_str()));
+ return completeJson(event, e);
+ }
+};
+
+Action *
+register_ShowConnectionCount(Continuation *c, HTTPHdr *h)
+{
+ ShowConnectionCount *s = new ShowConnectionCount(c, h);
+ this_ethread()->schedule_imm(s);
+ return &s->action;
+}
diff --git a/proxy/http/HttpConnectionCount.h b/proxy/http/HttpConnectionCount.h
index 7997941..6774caa 100644
--- a/proxy/http/HttpConnectionCount.h
+++ b/proxy/http/HttpConnectionCount.h
@@ -30,6 +30,8 @@
#include "ts/INK_MD5.h"
#include "ts/ink_config.h"
#include "HttpProxyAPIEnums.h"
+#include "Show.h"
+#include <sstream>
#ifndef _HTTP_CONNECTION_COUNT_H_
#define _HTTP_CONNECTION_COUNT_H_
@@ -87,6 +89,11 @@ public:
_hostCount.put(caddr, count + delta);
ink_mutex_release(&_mutex);
}
+ /**
+ * dump to JSON for stat page.
+ * @return JSON string for _hostCount
+ */
+ std::string dumpToJSON();
struct ConnAddr {
IpEndpoint _addr;
@@ -119,6 +126,26 @@ public:
}
operator bool() { return ats_is_ip(&_addr); }
+ std::string
+ getIpStr()
+ {
+ std::string str;
+ if (*this) {
+ ip_text_buffer buf;
+ const char *ret = ats_ip_ntop(&_addr.sa, buf, sizeof(buf));
+ if (ret) {
+ str.assign(ret);
+ }
+ }
+ return str;
+ }
+
+ std::string
+ getHostnameHashStr()
+ {
+ char hashBuffer[33];
+ return std::string(_hostname_hash.toHexStr(hashBuffer));
+ }
};
class ConnAddrHashFns
@@ -197,6 +224,19 @@ protected:
static ConnectionCount _connectionCount;
HashMap<ConnAddr, ConnAddrHashFns, int> _hostCount;
ink_mutex _mutex;
+
+private:
+ void
+ appendJSONPair(std::ostringstream &oss, const std::string &key, const int value)
+ {
+ oss << '\"' << key << "\": " << value;
+ }
+
+ void
+ appendJSONPair(std::ostringstream &oss, const std::string &key, const std::string &value)
+ {
+ oss << '\"' << key << "\": \"" << value << '"';
+ }
};
class ConnectionCountQueue : public ConnectionCount
@@ -216,4 +256,6 @@ private:
static ConnectionCountQueue _connectionCount;
};
+Action *register_ShowConnectionCount(Continuation *, HTTPHdr *);
+
#endif
diff --git a/proxy/http/HttpProxyServerMain.cc b/proxy/http/HttpProxyServerMain.cc
index 791549a..e88b604 100644
--- a/proxy/http/HttpProxyServerMain.cc
+++ b/proxy/http/HttpProxyServerMain.cc
@@ -38,6 +38,7 @@
#include "P_SSLNextProtocolAccept.h"
#include "ProtocolProbeSessionAccept.h"
#include "http2/Http2SessionAccept.h"
+#include "HttpConnectionCount.h"
HttpSessionAccept *plugin_http_accept = nullptr;
HttpSessionAccept *plugin_http_transparent_accept = nullptr;
@@ -304,6 +305,9 @@ start_HttpProxyServer()
}
#endif
+ // Set up stat page for http connection count
+ statPagesManager.register_http("connection_count", register_ShowConnectionCount);
+
// Alert plugins that connections will be accepted.
APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_PORTS_READY_HOOK);
while (hook) {
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].