From d714a073e21d0de32c97c2149f07c1b612067dc8 Mon Sep 17 00:00:00 2001 From: CMGS Date: Wed, 1 Nov 2017 13:04:29 +0800 Subject: [PATCH] send memcap to statsd --- cluster/calcium/resource.go | 2 ++ stats/statsd.go | 15 +++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cluster/calcium/resource.go b/cluster/calcium/resource.go index 8ffac8bf5..abce3cb28 100644 --- a/cluster/calcium/resource.go +++ b/cluster/calcium/resource.go @@ -7,6 +7,7 @@ import ( log "github.com/Sirupsen/logrus" + "github.com/projecteru2/core/stats" "github.com/projecteru2/core/types" "github.com/projecteru2/core/utils" ) @@ -150,6 +151,7 @@ func (c *calcium) getCPUAndMem(podname, nodename string, labels map[string]strin } result = makeCPUAndMem(nodes) + go stats.Client.SendMemCap(result) return result, nodes, nil } diff --git a/stats/statsd.go b/stats/statsd.go index 997d6ef8e..2de949859 100644 --- a/stats/statsd.go +++ b/stats/statsd.go @@ -12,11 +12,8 @@ import ( ) const ( - memStats = "eru-core.%s.%s.%%s" + memStats = "eru-core.%s.mem" deployCount = "eru-core.deploy.count" - - beforeKey = "before" - afterKey = "after" ) type statsdClient struct { @@ -55,7 +52,7 @@ func (s *statsdClient) isNotSet() bool { return s.Addr == "" } -func (s *statsdClient) SendMemCap(cpumemmap map[string]types.CPUAndMem, before bool) { +func (s *statsdClient) SendMemCap(cpumemmap map[string]types.CPUAndMem) { if s.isNotSet() { return } @@ -64,11 +61,7 @@ func (s *statsdClient) SendMemCap(cpumemmap map[string]types.CPUAndMem, before b data[node] = float64(cpuandmem.MemCap) } - keyPattern := fmt.Sprintf(memStats, s.Hostname, beforeKey) - if !before { - keyPattern = fmt.Sprintf(memStats, s.Hostname, afterKey) - } - + keyPattern := fmt.Sprintf(memStats, s.Hostname) if err := s.gauge(keyPattern, data); err != nil { log.Errorf("[SendMemCap] Error occured while sending data to statsd: %v", err) } @@ -83,8 +76,10 @@ func (s *statsdClient) SendDeployCount(n int) { } } +//Client ref to statsd client var Client = statsdClient{} +//NewStatsdClient make a client func NewStatsdClient(addr string) { hostname, _ := os.Hostname() cleanHost := strings.Replace(hostname, ".", "-", -1)