diff --git a/collector/cluster_node.go b/collector/cluster_node.go index 116eb3b..b1f9a3f 100644 --- a/collector/cluster_node.go +++ b/collector/cluster_node.go @@ -1,6 +1,8 @@ package collector -import "github.com/prometheus/client_golang/prometheus" +import ( + "github.com/prometheus/client_golang/prometheus" +) var ( soraClusterMetrics = SoraClusterMetrics{ @@ -27,10 +29,14 @@ func (m *SoraClusterMetrics) Describe(ch chan<- *prometheus.Desc) { func (m *SoraClusterMetrics) Collect(ch chan<- prometheus.Metric, nodeList []soraClusterNode, report soraClusterReport) { for _, node := range nodeList { - if node.ClusterNodeName != nil { - ch <- newGauge(m.clusterNode, 1, *node.ClusterNodeName, *node.Mode) + value := 0.0 + if node.Connected { + value = 1.0 + } + if node.ClusterNodeName != "" { + ch <- newGauge(m.clusterNode, value, node.ClusterNodeName, node.Mode) } else { - ch <- newGauge(m.clusterNode, 1, *node.NodeName, *node.Mode) + ch <- newGauge(m.clusterNode, value, node.NodeName, node.Mode) } } ch <- newGauge(m.raftState, 1.0, report.RaftState) diff --git a/collector/collector.go b/collector/collector.go index 2b65e09..1a99b56 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -1,6 +1,7 @@ package collector import ( + "bytes" "context" "crypto/tls" "encoding/json" @@ -50,6 +51,10 @@ type HTTPClient interface { Do(*http.Request) (*http.Response, error) } +type SoraListClusterNodesRequest struct { + IncludeAllKnownNodes bool `json:"include_all_known_nodes"` +} + func NewCollector(options *CollectorOptions) *Collector { return &Collector{ URI: options.URI, @@ -112,7 +117,17 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { var nodeList []soraClusterNode if c.EnableSoraClusterMetrics { - req, err = http.NewRequestWithContext(ctx, http.MethodPost, c.URI, nil) + requestParams := SoraListClusterNodesRequest{ + IncludeAllKnownNodes: true, + } + encodedParams, err := json.Marshal(requestParams) + if err != nil { + level.Error(c.logger).Log("msg", "failed to encode Sora ListClusterNodes API request parameters", "err", err) + ch <- newGauge(c.soraUp, 0) + return + } + + req, err = http.NewRequestWithContext(ctx, http.MethodPost, c.URI, bytes.NewBuffer(encodedParams)) if err != nil { level.Error(c.logger).Log("msg", "failed to create request to sora", "err", err) ch <- newGauge(c.soraUp, 0) diff --git a/collector/sora_api.go b/collector/sora_api.go index 8011fe4..74121dd 100644 --- a/collector/sora_api.go +++ b/collector/sora_api.go @@ -136,9 +136,10 @@ type soraClusterReport struct { } type soraClusterNode struct { - ClusterNodeName *string `json:"cluster_node_name"` - NodeName *string `json:"node_name"` - Mode *string `json:"mode"` + ClusterNodeName string `json:"cluster_node_name"` + NodeName string `json:"node_name"` + Mode string `json:"mode"` + Connected bool `json:"connected"` } type soraLicenseInfo struct {