Skip to content

Commit

Permalink
support variable components
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramraman committed Feb 8, 2019
1 parent 5e0e1d7 commit a656e9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 0 additions & 2 deletions application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func New(application, service string) Tags {
// Map with all values
func (a Tags) Map() map[string]string {
allTags := make(map[string]string)

allTags["application"] = a.Application
allTags["service"] = a.Service
allTags["cluster"] = a.Cluster
Expand All @@ -32,6 +31,5 @@ func (a Tags) Map() map[string]string {
for k, v := range a.CustomTags {
allTags[k] = v
}

return allTags
}
14 changes: 12 additions & 2 deletions application/heartbeater.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ type heartbeater struct {
sender senders.Sender
application Tags
source string
components []string

ticker *time.Ticker
stop chan bool
}

// StartHeartbeatService will create and start a new HeartbeatService
func StartHeartbeatService(sender senders.Sender, application Tags, source string) HeartbeatService {
func StartHeartbeatService(sender senders.Sender, application Tags, source string, components ...string) HeartbeatService {
hb := &heartbeater{
sender: sender,
application: application,
source: source,
components: components,
ticker: time.NewTicker(5 * time.Minute),
stop: make(chan bool, 1),
}
Expand All @@ -43,7 +45,6 @@ func StartHeartbeatService(sender senders.Sender, application Tags, source strin
}()

hb.beat()

return hb
}

Expand All @@ -54,6 +55,15 @@ func (hb *heartbeater) Close() {
func (hb *heartbeater) beat() {
tags := hb.application.Map()
tags["component"] = "wavefront-generated"
hb.send(tags)

for _, component := range hb.components {
tags["component"] = component
hb.send(tags)
}
}

func (hb *heartbeater) send(tags map[string]string) {
err := hb.sender.SendMetric("~component.heartbeat", 1, 0, hb.source, tags)
if err != nil {
log.Printf("heartbeater SendMetric error: %v\n", err)
Expand Down

0 comments on commit a656e9e

Please sign in to comment.