Skip to content

Commit

Permalink
Merge pull request #84 from caarlos0/active
Browse files Browse the repository at this point in the history
feat: nss_server_active
  • Loading branch information
wallyqs authored Jun 19, 2019
2 parents 625409e + 7aed76b commit 84dac22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func TestStreamingMetrics(t *testing.T) {
"nss_server_subscriptions": 0,
"nss_server_clients": 0,
"nss_server_info": 1,
"nss_server_active": 0,
}

verifyCollector(url, "serverz", cases, t)
Expand Down
16 changes: 16 additions & 0 deletions collector/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type serverzCollector struct {
channels *prometheus.Desc
subs *prometheus.Desc
clients *prometheus.Desc
active *prometheus.Desc
info *prometheus.Desc
}

Expand Down Expand Up @@ -73,6 +74,12 @@ func newServerzCollector(servers []*CollectedServer) prometheus.Collector {
[]string{"server_id"},
nil,
),
active: prometheus.NewDesc(
prometheus.BuildFQName("nss", "server", "active"),
"Active server",
[]string{"server_id"},
nil,
),
info: prometheus.NewDesc(
prometheus.BuildFQName("nss", "server", "info"),
"Info",
Expand All @@ -98,6 +105,7 @@ func (nc *serverzCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- nc.channels
ch <- nc.subs
ch <- nc.clients
ch <- nc.active
ch <- nc.info
}

Expand Down Expand Up @@ -131,10 +139,18 @@ func (nc *serverzCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(nc.channels, prometheus.CounterValue, float64(resp.Channels), server.ID)
ch <- prometheus.MustNewConstMetric(nc.subs, prometheus.CounterValue, float64(resp.Subscriptions), server.ID)
ch <- prometheus.MustNewConstMetric(nc.clients, prometheus.CounterValue, float64(resp.Clients), server.ID)
ch <- prometheus.MustNewConstMetric(nc.active, prometheus.GaugeValue, boolToFloat(resp.State == "FT_ACTIVE"), server.ID)
ch <- prometheus.MustNewConstMetric(nc.info, prometheus.GaugeValue, 1, server.ID, resp.ClusterID, resp.Version, resp.GoVersion, resp.State, resp.Role, resp.StartTime)
}
}

func boolToFloat(b bool) float64 {
if b {
return 1.0
}
return 0.0
}

type channelsCollector struct {
sync.Mutex

Expand Down

0 comments on commit 84dac22

Please sign in to comment.