From 55a3540b1ca6307c64a214a8cdc08602ac1426a5 Mon Sep 17 00:00:00 2001 From: elubow Date: Sat, 25 Jan 2014 14:46:30 -0500 Subject: [PATCH 1/2] nsqd: export more client metadata in /stats --- nsqd/client_v2.go | 18 ++++++++++++++++-- nsqd/stats.go | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/nsqd/client_v2.go b/nsqd/client_v2.go index 9526616ec..094593397 100644 --- a/nsqd/client_v2.go +++ b/nsqd/client_v2.go @@ -73,6 +73,11 @@ type ClientV2 struct { SampleRate int32 SampleRateUpdateChan chan int32 + // states for exposing to nsqadmin + TLS int32 + Snappy int32 + Deflate int32 + // re-usable buffer for reading the 4-byte lengths off the wire lenBuf [4]byte lenSlice []byte @@ -157,7 +162,10 @@ func (c *ClientV2) Stats() ClientStats { FinishCount: atomic.LoadUint64(&c.FinishCount), RequeueCount: atomic.LoadUint64(&c.RequeueCount), ConnectTime: c.ConnectTime.Unix(), - SampleRate: c.SampleRate, + SampleRate: atomic.LoadInt32(&c.SampleRate), + TLS: atomic.LoadInt32(&c.TLS) == 1, + Deflate: atomic.LoadInt32(&c.Deflate) == 1, + Snappy: atomic.LoadInt32(&c.Snappy) == 1, } } @@ -330,7 +338,7 @@ func (c *ClientV2) SetSampleRate(sampleRate int32) error { } if sampleRate != 0 { - c.SampleRate = sampleRate + atomic.StoreInt32(&c.SampleRate, sampleRate) select { case c.SampleRateUpdateChan <- sampleRate: default: @@ -354,6 +362,8 @@ func (c *ClientV2) UpgradeTLS() error { c.Reader = bufio.NewReaderSize(c.tlsConn, DefaultBufferSize) c.Writer = bufio.NewWriterSize(c.tlsConn, c.OutputBufferSize) + atomic.StoreInt32(&c.TLS, 1) + return nil } @@ -372,6 +382,8 @@ func (c *ClientV2) UpgradeDeflate(level int) error { c.flateWriter = fw c.Writer = bufio.NewWriterSize(fw, c.OutputBufferSize) + atomic.StoreInt32(&c.Deflate, 1) + return nil } @@ -387,6 +399,8 @@ func (c *ClientV2) UpgradeSnappy() error { c.Reader = bufio.NewReaderSize(snappystream.NewReader(conn, snappystream.SkipVerifyChecksum), DefaultBufferSize) c.Writer = bufio.NewWriterSize(snappystream.NewWriter(conn), c.OutputBufferSize) + atomic.StoreInt32(&c.Snappy, 1) + return nil } diff --git a/nsqd/stats.go b/nsqd/stats.go index 126199b58..ab8b8c82a 100644 --- a/nsqd/stats.go +++ b/nsqd/stats.go @@ -73,6 +73,9 @@ type ClientStats struct { RequeueCount uint64 `json:"requeue_count"` ConnectTime int64 `json:"connect_ts"` SampleRate int32 `json:"sample_rate"` + TLS bool `json:"tls"` + Deflate bool `json:"deflate"` + Snappy bool `json:"snappy"` } type Topics []*Topic From 1514a6a26ce700b2bd4b17a1bd8f47c349009099 Mon Sep 17 00:00:00 2001 From: elubow Date: Sat, 25 Jan 2014 14:46:43 -0500 Subject: [PATCH 2/2] nsqadmin: expose client attributes --- nsqadmin/templates/channel.html.go | 15 +++++++++++++++ util/lookupd/lookupd.go | 4 ++++ util/lookupd/statsinfo.go | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/nsqadmin/templates/channel.html.go b/nsqadmin/templates/channel.html.go index 85bbc523b..a604d31e0 100644 --- a/nsqadmin/templates/channel.html.go +++ b/nsqadmin/templates/channel.html.go @@ -188,6 +188,7 @@ func init() { Client Host Protocol + Attributes NSQd Host In-Flight Ready Count @@ -201,6 +202,20 @@ func init() { {{.ClientIdentifier}} {{.ClientVersion}} + + {{if gt .SampleRate 0}} + Sampled {{.SampleRate}}% + {{end}} + {{if .TLS}} + TLS + {{end}} + {{if .Deflate}} + Delfate + {{end}} + {{if .Snappy}} + Snappy + {{end}} + {{.HostAddress}} {{.InFlightCount | commafy}} {{.ReadyCount | commafy}} diff --git a/util/lookupd/lookupd.go b/util/lookupd/lookupd.go index f5faf1b3c..535490b6b 100644 --- a/util/lookupd/lookupd.go +++ b/util/lookupd/lookupd.go @@ -421,6 +421,10 @@ func GetNSQDStats(nsqdHTTPAddrs []string, selectedTopic string) ([]*TopicStats, FinishCount: client.Get("finish_count").MustInt64(), RequeueCount: client.Get("requeue_count").MustInt64(), MessageCount: client.Get("message_count").MustInt64(), + SampleRate: int32(client.Get("sample_rate").MustInt()), + TLS: client.Get("tls").MustBool(), + Deflate: client.Get("deflate").MustBool(), + Snappy: client.Get("snappy").MustBool(), } hostChannelStats.Clients = append(hostChannelStats.Clients, clientInfo) channelStats.Clients = append(channelStats.Clients, clientInfo) diff --git a/util/lookupd/statsinfo.go b/util/lookupd/statsinfo.go index f9663ec62..5f93b281c 100644 --- a/util/lookupd/statsinfo.go +++ b/util/lookupd/statsinfo.go @@ -162,6 +162,10 @@ type ClientInfo struct { FinishCount int64 RequeueCount int64 MessageCount int64 + SampleRate int32 + TLS bool + Deflate bool + Snappy bool } type ChannelStatsList []*ChannelStats