diff --git a/collector/cluster_node.go b/collector/cluster_node.go index b1f9a3f..05c8a6f 100644 --- a/collector/cluster_node.go +++ b/collector/cluster_node.go @@ -10,6 +10,11 @@ var ( raftState: newDescWithLabel("cluster_raft_state", "The current Raft state. The state name is indicated by the label 'state'. The value of this metric is always set to 1.", []string{"state"}), raftTerm: newDesc("cluster_raft_term", "The current Raft term."), raftCommitIndex: newDesc("cluster_raft_commit_index", "The latest committed Raft log index."), + + clusterRelayReceivedBytes: newDescWithLabel("cluster_relay_received_bytes", "The total number of bytes received by the cluster relay.", []string{"node_name"}), + clusterRelaySentBytes: newDescWithLabel("cluster_relay_sent_bytes", "The total number of bytes sent by the cluster relay.", []string{"node_name"}), + clusterRelayReceivedPackets: newDescWithLabel("cluster_relay_received_packets", "The total number of packets received by the cluster relay.", []string{"node_name"}), + clusterRelaySentPackets: newDescWithLabel("cluster_relay_sent_packets", "The total number of packets sent by the cluster relay.", []string{"node_name"}), } ) @@ -18,6 +23,11 @@ type SoraClusterMetrics struct { raftState *prometheus.Desc raftTerm *prometheus.Desc raftCommitIndex *prometheus.Desc + + clusterRelayReceivedBytes *prometheus.Desc + clusterRelaySentBytes *prometheus.Desc + clusterRelayReceivedPackets *prometheus.Desc + clusterRelaySentPackets *prometheus.Desc } func (m *SoraClusterMetrics) Describe(ch chan<- *prometheus.Desc) { @@ -25,9 +35,13 @@ func (m *SoraClusterMetrics) Describe(ch chan<- *prometheus.Desc) { ch <- m.raftState ch <- m.raftTerm ch <- m.raftCommitIndex + ch <- m.clusterRelayReceivedBytes + ch <- m.clusterRelaySentBytes + ch <- m.clusterRelayReceivedPackets + ch <- m.clusterRelaySentPackets } -func (m *SoraClusterMetrics) Collect(ch chan<- prometheus.Metric, nodeList []soraClusterNode, report soraClusterReport) { +func (m *SoraClusterMetrics) Collect(ch chan<- prometheus.Metric, nodeList []soraClusterNode, report soraClusterReport, clusterRelaies []soraClusterRelay) { for _, node := range nodeList { value := 0.0 if node.Connected { @@ -42,4 +56,11 @@ func (m *SoraClusterMetrics) Collect(ch chan<- prometheus.Metric, nodeList []sor ch <- newGauge(m.raftState, 1.0, report.RaftState) ch <- newCounter(m.raftTerm, float64(report.RaftTerm)) ch <- newCounter(m.raftCommitIndex, float64(report.RaftCommitIndex)) + + for _, relayNode := range clusterRelaies { + ch <- newCounter(m.clusterRelayReceivedBytes, float64(relayNode.TotalReceivedByteSize), relayNode.NodeName) + ch <- newCounter(m.clusterRelaySentBytes, float64(relayNode.TotalSentByteSize), relayNode.NodeName) + ch <- newCounter(m.clusterRelayReceivedPackets, float64(relayNode.TotalReceived), relayNode.NodeName) + ch <- newCounter(m.clusterRelaySentPackets, float64(relayNode.TotalSent), relayNode.NodeName) + } } diff --git a/collector/collector.go b/collector/collector.go index ccdb70c..a92a227 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -212,7 +212,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { c.ErlangVMMetrics.Collect(ch, report.ErlangVMReport) } if c.EnableSoraClusterMetrics { - c.SoraClusterMetrics.Collect(ch, nodeList, report.ClusterReport) + c.SoraClusterMetrics.Collect(ch, nodeList, report.ClusterReport, report.ClusterRelay) } } diff --git a/collector/sora_api.go b/collector/sora_api.go index 74121dd..7283cbe 100644 --- a/collector/sora_api.go +++ b/collector/sora_api.go @@ -8,6 +8,7 @@ type soraGetStatsReport struct { SoraConnectionErrorReport soraConnectionErrorReport `json:"error,omitempty"` ErlangVMReport erlangVMReport `json:"erlang_vm,omitempty"` ClusterReport soraClusterReport `json:"cluster,omitempty"` + ClusterRelay []soraClusterRelay `json:"cluster_relay,omitempty"` } type soraConnectionReport struct { @@ -142,6 +143,14 @@ type soraClusterNode struct { Connected bool `json:"connected"` } +type soraClusterRelay struct { + NodeName string `json:"node_name"` + TotalReceivedByteSize int64 `json:"total_received_byte_size"` + TotalSentByteSize int64 `json:"total_sent_byte_size"` + TotalReceived int64 `json:"total_received"` + TotalSent int64 `json:"total_sent"` +} + type soraLicenseInfo struct { ExpiredAt string `json:"expired_at"` MaxConnections int64 `json:"max_connections"`