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

Basic workers stats #148

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
14 changes: 12 additions & 2 deletions isolate/conn_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func (r *responseStream) close(ctx context.Context) {
}
}

func (r *responseStream) Write(ctx context.Context, num uint64, data []byte) error {
// Writes messagepacked payload `as is` as a packet of Cocaine
func (r *responseStream) WriteMessage(ctx context.Context, num uint64, packedPayload []byte) error {
r.Lock()
defer r.Unlock()

Expand All @@ -238,7 +239,7 @@ func (r *responseStream) Write(ctx context.Context, num uint64, data []byte) err
p = msgp.AppendUint64(p, num)

p = msgp.AppendArrayHeader(p, 1)
p = msgp.AppendStringFromBytes(p, data)
p = append(p, packedPayload...)

if _, err := r.wr.Write(p); err != nil {
log.G(r.ctx).WithError(err).Error("responseStream.Write")
Expand All @@ -247,6 +248,15 @@ func (r *responseStream) Write(ctx context.Context, num uint64, data []byte) err
return nil
}

// IMHO: should be named WriteString, really.
func (r *responseStream) Write(ctx context.Context, num uint64, str []byte) error {
p := msgpackBytePool.Get().([]byte)[:0]
defer msgpackBytePool.Put(p)

p = msgp.AppendStringFromBytes(p, str)
return r.WriteMessage(ctx, num, p)
}

func (r *responseStream) Error(ctx context.Context, num uint64, code [2]int, msg string) error {
r.Lock()
defer r.Unlock()
Expand Down
38 changes: 38 additions & 0 deletions isolate/container_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:generate msgp --tests=false
//msgp:ignore isolate.MarkedWorkerMetrics
package isolate

type (
NetStat struct {
RxBytes uint64 `msg:"rx_bytes"`
TxBytes uint64 `msg:"tx_bytes"`
}

WorkerMetrics struct {
UptimeSec uint64 `msg:"uptime"`
CpuUsageSec uint64 `msg:"cpu_usage"`

CpuLoad float32 `msg:"cpu_load"`

Mem uint64 `msg:"mem"`

// iface -> net stat
Net map[string]NetStat `msg:"net"`
}

MetricsResponse map[string]*WorkerMetrics

MarkedWorkerMetrics struct {
uuid string
m *WorkerMetrics
}
)

func NewWorkerMetrics() (c WorkerMetrics) {
c.Net = make(map[string]NetStat)
return
}

func NewMarkedMetrics(uuid string, cm *WorkerMetrics) MarkedWorkerMetrics {
return MarkedWorkerMetrics{uuid: uuid, m: cm}
}
Loading