Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional bytes field to traces #283

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
MetricNet
MetricsMem
MetricsCPU
MetricsRPC

// MetricsAll must be last.
// Enables all metrics.
Expand Down Expand Up @@ -156,6 +157,7 @@ type Metrics struct {
Net *NetMetrics `json:"net,omitempty"`
Mem *MemMetrics `json:"mem,omitempty"`
CPU *CPUMetrics `json:"cpu,omitempty"`
RPC *RPCMetrics `json:"rpc,omitempty"`
}

// Merge other into r.
Expand Down Expand Up @@ -191,6 +193,10 @@ func (r *Metrics) Merge(other *Metrics) {
r.Net = &NetMetrics{}
}
r.Net.Merge(other.Net)
if r.RPC == nil && other.RPC != nil {
r.RPC = &RPCMetrics{}
}
r.RPC.Merge(other.RPC)
}

// Merge will merge other into r.
Expand Down Expand Up @@ -664,3 +670,51 @@ func (m *CPUMetrics) Merge(other *CPUMetrics) {
m.LoadStat.Load5 += other.LoadStat.Load5
m.LoadStat.Load15 += other.LoadStat.Load15
}

// RPCMetrics contains metrics for RPC operations.
type RPCMetrics struct {
CollectedAt time.Time `json:"collectedAt"`
Connected int `json:"connected"`
Disconnected int `json:"disconnected"`
OutgoingStreams int `json:"outgoingStreams"`
IncomingStreams int `json:"incomingStreams"`
OutgoingBytes int64 `json:"outgoingBytes"`
IncomingBytes int64 `json:"incomingBytes"`
OutgoingMessages int64 `json:"outgoingMessages"`
IncomingMessages int64 `json:"incomingMessages"`
OutQueue int `json:"outQueue"`
LastPongTime time.Time `json:"lastPongTime"`

ByDestination map[string]RPCMetrics `json:"byDestination,omitempty"`
}

// Merge other into 'm'.
func (m *RPCMetrics) Merge(other *RPCMetrics) {
if m == nil {
return
}
if m.CollectedAt.Before(other.CollectedAt) {
// Use latest timestamp
m.CollectedAt = other.CollectedAt
}
m.Connected += other.Connected
m.Disconnected += other.Disconnected
m.OutgoingStreams += other.OutgoingStreams
m.IncomingStreams += other.IncomingStreams
m.OutgoingBytes += other.OutgoingBytes
m.IncomingBytes += other.IncomingBytes
m.OutgoingMessages += other.OutgoingMessages
m.IncomingMessages += other.IncomingMessages
m.OutQueue += other.OutQueue
if m.LastPongTime.Before(other.LastPongTime) {
m.LastPongTime = other.LastPongTime
}
for k, v := range other.ByDestination {
if m.ByDestination == nil {
m.ByDestination = make(map[string]RPCMetrics, len(other.ByDestination))
}
existing := m.ByDestination[k]
existing.Merge(&v)
m.ByDestination[k] = existing
}
}
1 change: 1 addition & 0 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type TraceInfo struct {
Time time.Time `json:"time"`
Path string `json:"path"`
Duration time.Duration `json:"dur"`
Bytes int64 `json:"bytes,omitempty"`

Message string `json:"msg,omitempty"`
Error string `json:"error,omitempty"`
Expand Down
Loading