change names for stats sub-collectors

This commit is contained in:
thonit
2015-12-21 20:46:02 +01:00
parent d5a4ca52d9
commit 76b63dc80d
4 changed files with 21 additions and 21 deletions

View File

@ -6,18 +6,18 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
type channelsCollector []struct { type channelStats []struct {
val func(*channel) float64 val func(*channel) float64
vec *prometheus.GaugeVec 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 // expose the channel metrics of a nsqd node to Prometheus. The
// channel metrics are reported per topic. // channel metrics are reported per topic.
func ChannelsCollector(namespace string) StatsCollector { func ChannelStats(namespace string) StatsCollector {
labels := []string{"type", "topic", "channel", "paused"} labels := []string{"type", "topic", "channel", "paused"}
return channelsCollector{ return channelStats{
{ {
val: func(c *channel) float64 { return float64(len(c.Clients)) }, val: func(c *channel) float64 { return float64(len(c.Clients)) },
vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ 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 _, topic := range s.Topics {
for _, channel := range topic.Channels { for _, channel := range topic.Channels {
labels := prometheus.Labels{ labels := prometheus.Labels{
@ -95,7 +95,7 @@ func (coll channelsCollector) collect(s *stats, out chan<- prometheus.Metric) {
"paused": strconv.FormatBool(channel.Paused), "paused": strconv.FormatBool(channel.Paused),
} }
for _, c := range coll { for _, c := range cs {
c.vec.With(labels).Set(c.val(channel)) c.vec.With(labels).Set(c.val(channel))
c.vec.Collect(out) c.vec.Collect(out)
} }

View File

@ -6,22 +6,22 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
type clientsCollector []struct { type clientStats []struct {
val func(*client) float64 val func(*client) float64
vec *prometheus.GaugeVec 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 // expose the client metrics of a nsqd node to Prometheus. The
// client metrics are reported per topic and per channel. // client metrics are reported per topic and per channel.
// //
// If there are too many clients, it could cause a timeout of the // If there are too many clients, it could cause a timeout of the
// Prometheus collection process. So be sure the number of clients // Prometheus collection process. So be sure the number of clients
// is small enough when using this collector. // 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"} 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. // TODO: Give state a descriptive name instead of a number.
val: func(c *client) float64 { return float64(c.State) }, 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 _, topic := range s.Topics {
for _, channel := range topic.Channels { for _, channel := range topic.Channels {
for _, client := range channel.Clients { for _, client := range channel.Clients {
@ -107,7 +107,7 @@ func (coll clientsCollector) collect(s *stats, out chan<- prometheus.Metric) {
"remote_address": client.RemoteAddress, "remote_address": client.RemoteAddress,
} }
for _, c := range coll { for _, c := range cs {
c.vec.With(labels).Set(c.val(client)) c.vec.With(labels).Set(c.val(client))
c.vec.Collect(out) c.vec.Collect(out)
} }

View File

@ -6,17 +6,17 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
type topicsCollector []struct { type topicStats []struct {
val func(*topic) float64 val func(*topic) float64
vec *prometheus.GaugeVec 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. // 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"} labels := []string{"type", "topic", "paused"}
return topicsCollector{ return topicStats{
{ {
val: func(t *topic) float64 { return float64(len(t.Channels)) }, val: func(t *topic) float64 { return float64(len(t.Channels)) },
vec: prometheus.NewGaugeVec(prometheus.GaugeOpts{ 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 { for _, topic := range s.Topics {
labels := prometheus.Labels{ labels := prometheus.Labels{
"type": "topic", "type": "topic",
@ -60,7 +60,7 @@ func (coll topicsCollector) collect(s *stats, out chan<- prometheus.Metric) {
"paused": strconv.FormatBool(topic.Paused), "paused": strconv.FormatBool(topic.Paused),
} }
for _, c := range coll { for _, c := range ts {
c.vec.With(labels).Set(c.val(topic)) c.vec.With(labels).Set(c.val(topic))
c.vec.Collect(out) c.vec.Collect(out)
} }

View File

@ -29,9 +29,9 @@ var (
// stats.* collectors // stats.* collectors
statsRegistry = map[string]func(namespace string) collector.StatsCollector{ statsRegistry = map[string]func(namespace string) collector.StatsCollector{
"topics": collector.TopicsCollector, "topics": collector.TopicStats,
"channels": collector.ChannelsCollector, "channels": collector.ChannelStats,
"clients": collector.ClientsCollector, "clients": collector.ClientStats,
} }
) )