Skip to content

Commit

Permalink
Add weavenet metrics to billing
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Cobden committed May 9, 2017
1 parent 10b276c commit 4210b30
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/multitenant/billing_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte)
hasher := sha256.New()
hasher.Write(buf)
hash := "sha256:" + base64.URLEncoding.EncodeToString(hasher.Sum(nil))
weaveNetCount := 0
if hasWeaveNet(rep) {
weaveNetCount = 1
}

amounts := billing.Amounts{
billing.ContainerSeconds: int64(interval/time.Second) * int64(len(rep.Container.Nodes)),
billing.NodeSeconds: int64(interval/time.Second) * int64(len(rep.Host.Nodes)),
billing.WeaveNetSeconds: int64(interval/time.Second) * int64(weaveNetCount),
}
metadata := map[string]string{
"row_key": rowKey,
Expand Down Expand Up @@ -112,6 +118,18 @@ func (e *BillingEmitter) reportInterval(r report.Report) time.Duration {
return d
}

// Tries to determine if this report came from a host running Weave Net
func hasWeaveNet(r report.Report) bool {
for _, n := range r.Overlay.Nodes {
overlayType, _ := report.ParseOverlayNodeID(n.ID)
if hasNet = (overlayType == report.WeaveOverlayPeerPrefix); hasNet {
return true
}
}

return false
}

// Close shuts down the billing emitter and billing client flushing events.
func (e *BillingEmitter) Close() error {
return e.billing.Close()
Expand Down

0 comments on commit 4210b30

Please sign in to comment.