From 76b63dc80d92958ccdf4fc529271903761dc5632 Mon Sep 17 00:00:00 2001 From: thonit Date: Mon, 21 Dec 2015 20:46:02 +0100 Subject: [PATCH] change names for stats sub-collectors --- collector/stats_channel.go | 12 ++++++------ collector/stats_client.go | 12 ++++++------ collector/stats_topic.go | 12 ++++++------ main.go | 6 +++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/collector/stats_channel.go b/collector/stats_channel.go index c1483be..56cc8ff 100644 --- a/collector/stats_channel.go +++ b/collector/stats_channel.go @@ -6,18 +6,18 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -type channelsCollector []struct { +type channelStats []struct { val func(*channel) float64 vec *prometheus.GaugeVec } -// ChannelsCollector creates a new stats collector which is able to +// ChannelStats creates a new stats collector which is able to // expose the channel metrics of a nsqd node to Prometheus. The // channel metrics are reported per topic. -func ChannelsCollector(namespace string) StatsCollector { +func ChannelStats(namespace string) StatsCollector { labels := []string{"type", "topic", "channel", "paused"} - return channelsCollector{ + return channelStats{ { val: func(c *channel) float64 { return float64(len(c.Clients)) }, vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ @@ -85,7 +85,7 @@ func ChannelsCollector(namespace string) StatsCollector { } } -func (coll channelsCollector) collect(s *stats, out chan<- prometheus.Metric) { +func (cs channelStats) collect(s *stats, out chan<- prometheus.Metric) { for _, topic := range s.Topics { for _, channel := range topic.Channels { labels := prometheus.Labels{ @@ -95,7 +95,7 @@ func (coll channelsCollector) collect(s *stats, out chan<- prometheus.Metric) { "paused": strconv.FormatBool(channel.Paused), } - for _, c := range coll { + for _, c := range cs { c.vec.With(labels).Set(c.val(channel)) c.vec.Collect(out) } diff --git a/collector/stats_client.go b/collector/stats_client.go index 22f8e08..f700464 100644 --- a/collector/stats_client.go +++ b/collector/stats_client.go @@ -6,22 +6,22 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -type clientsCollector []struct { +type clientStats []struct { val func(*client) float64 vec *prometheus.GaugeVec } -// ClientsCollector creates a new stats collector which is able to +// ClientStats creates a new stats collector which is able to // expose the client metrics of a nsqd node to Prometheus. The // client metrics are reported per topic and per channel. // // If there are too many clients, it could cause a timeout of the // Prometheus collection process. So be sure the number of clients // is small enough when using this collector. -func ClientsCollector(namespace string) StatsCollector { +func ClientStats(namespace string) StatsCollector { labels := []string{"type", "topic", "channel", "deflate", "snappy", "tls", "client_id", "hostname", "version", "remote_address"} - return clientsCollector{ + return clientStats{ { // TODO: Give state a descriptive name instead of a number. val: func(c *client) float64 { return float64(c.State) }, @@ -90,7 +90,7 @@ func ClientsCollector(namespace string) StatsCollector { } } -func (coll clientsCollector) collect(s *stats, out chan<- prometheus.Metric) { +func (cs clientStats) collect(s *stats, out chan<- prometheus.Metric) { for _, topic := range s.Topics { for _, channel := range topic.Channels { for _, client := range channel.Clients { @@ -107,7 +107,7 @@ func (coll clientsCollector) collect(s *stats, out chan<- prometheus.Metric) { "remote_address": client.RemoteAddress, } - for _, c := range coll { + for _, c := range cs { c.vec.With(labels).Set(c.val(client)) c.vec.Collect(out) } diff --git a/collector/stats_topic.go b/collector/stats_topic.go index 1e94ad4..faa5659 100644 --- a/collector/stats_topic.go +++ b/collector/stats_topic.go @@ -6,17 +6,17 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -type topicsCollector []struct { +type topicStats []struct { val func(*topic) float64 vec *prometheus.GaugeVec } -// TopicsCollector creates a new stats collector which is able to +// TopicStats creates a new stats collector which is able to // expose the topic metrics of a nsqd node to Prometheus. -func TopicsCollector(namespace string) StatsCollector { +func TopicStats(namespace string) StatsCollector { labels := []string{"type", "topic", "paused"} - return topicsCollector{ + return topicStats{ { val: func(t *topic) float64 { return float64(len(t.Channels)) }, vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ @@ -52,7 +52,7 @@ func TopicsCollector(namespace string) StatsCollector { } } -func (coll topicsCollector) collect(s *stats, out chan<- prometheus.Metric) { +func (ts topicStats) collect(s *stats, out chan<- prometheus.Metric) { for _, topic := range s.Topics { labels := prometheus.Labels{ "type": "topic", @@ -60,7 +60,7 @@ func (coll topicsCollector) collect(s *stats, out chan<- prometheus.Metric) { "paused": strconv.FormatBool(topic.Paused), } - for _, c := range coll { + for _, c := range ts { c.vec.With(labels).Set(c.val(topic)) c.vec.Collect(out) } diff --git a/main.go b/main.go index 80b1da3..78a77d0 100644 --- a/main.go +++ b/main.go @@ -29,9 +29,9 @@ var ( // stats.* collectors statsRegistry = map[string]func(namespace string) collector.StatsCollector{ - "topics": collector.TopicsCollector, - "channels": collector.ChannelsCollector, - "clients": collector.ClientsCollector, + "topics": collector.TopicStats, + "channels": collector.ChannelStats, + "clients": collector.ClientStats, } )