Skip to content

Commit

Permalink
Reporting is now handled by an unique goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
pariviere committed Jun 10, 2015
1 parent c10ba88 commit c1650e3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion diskstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (n *DiskStats) Collect(queue chan *Metric, listener *broadcast.Listener) {
// first run or
// no interface
if len(n.last) == 0 {
return
continue
}

interval := float64(n.actualTime.Sub(n.lastTime).Seconds())
Expand Down
86 changes: 44 additions & 42 deletions goshin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)



var logger, _ = syslog.New(syslog.LOG_DAEMON, "goshin")

type Metric struct {
Expand Down Expand Up @@ -97,13 +98,10 @@ func (g *Goshin) Start() {
go diskstats.Collect(collectQueue, b.Listen())
}

go g.Report(collectQueue)

for t := range ticker.C {
//logger.Debug("send collection event")
b.Send(t)

// TODO: move reporting outside
// of this loop
go g.Report(collectQueue)
}
}

Expand Down Expand Up @@ -132,41 +130,45 @@ func (g *Goshin) EnforceState(metric *Metric) {
}

func (g *Goshin) Report(reportQueue chan *Metric) {

c := goryman.NewGorymanClient(g.Address)
err := c.Connect()

connected := true

if err != nil {
logger.Err(fmt.Sprintf("error : can not connect to host %s", g.Address))
connected = false
}

more := true

for more {
select {
case metric := <-reportQueue:
if connected {
g.EnforceState(metric)
err := c.SendEvent(&goryman.Event{
Metric: metric.Value,
Ttl: g.Ttl,
Service: metric.Service,
Description: metric.Description,
Tags: g.Tag,
Host: g.EventHost,
State: metric.State})

if err != nil {
logger.Err(fmt.Sprintf("error : %s", err))
}
}
default:
more = false
}
}

defer c.Close()
c := goryman.NewGorymanClient(g.Address)
defer c.Close()

connected := false
var connError error

for {
if connected == false {
connError = c.Connect()
}

if (connError != nil) {
logger.Err(fmt.Sprintf("error : can not connect to host %s", g.Address))
c.Close()
connected = false
} else {
connected = true
}

metric := <-reportQueue

if connected {
g.EnforceState(metric)
connError = c.SendEvent(&goryman.Event{
Metric: metric.Value,
Ttl: g.Ttl,
Service: metric.Service,
Description: metric.Description,
Tags: g.Tag,
Host: g.EventHost,
State: metric.State})

if connError != nil {
logger.Err(fmt.Sprintf("error : %s", connError))
c.Close()
connected = false
}
}

metric = nil
}
}
2 changes: 1 addition & 1 deletion net.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (n *NetStats) Collect(queue chan *Metric, listener *broadcast.Listener) {
// first run or
// no interface
if len(n.last) == 0 {
return
continue
}

interval := float64(n.actualTime.Sub(n.lastTime).Seconds())
Expand Down

0 comments on commit c1650e3

Please sign in to comment.