Skip to content

Commit

Permalink
send memcap to statsd
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Nov 1, 2017
1 parent 2ca8d1f commit d714a07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cluster/calcium/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 5 additions & 10 deletions stats/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down

0 comments on commit d714a07

Please sign in to comment.