Skip to content

Commit

Permalink
クラスターリレー統計に対応する
Browse files Browse the repository at this point in the history
  • Loading branch information
tnamao committed Mar 29, 2024
1 parent ee53d74 commit 390864d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
23 changes: 22 additions & 1 deletion collector/cluster_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
}
)

Expand All @@ -18,16 +23,25 @@ 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) {
ch <- m.clusterNode
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 {
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
9 changes: 9 additions & 0 deletions collector/sora_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit 390864d

Please sign in to comment.