Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (list statOccurrence) Less(i, j int) bool {
}

// Write new stats to DataDog
func datadogUploadStats(hostname string, bucketSecs int64, addedStats map[string][]StatsStat) (err error) {
func datadogUploadStats(hostname string, bucketSecs int64, addedStats map[string][]StatsStat, additionalStats map[string]AdditionalStat) (err error) {

// Generate the list of aggregated stats
aggregatedStats := statsAggregate(addedStats, bucketSecs)
Expand Down Expand Up @@ -160,6 +160,18 @@ func datadogUploadStats(hostname string, bucketSecs int64, addedStats map[string
}
seriesArray = append(seriesArray, series)

for _, stat := range additionalStats {
series = datadog.Series{Metric: "notehub." + hostname + "." + stat.Name, Type: datadog.PtrString("gauge")}
for _, value := range stat.Values {
point := []*float64{
datadog.PtrFloat64(float64(value.Time)),
datadog.PtrFloat64(float64(value.Value)),
}
series.Points = append(series.Points, point)
}
seriesArray = append(seriesArray, series)
}

// Submit the metrics
ctx := context.Background()
ctx = context.WithValue(ctx, datadog.ContextServerVariables, map[string]string{"site": Config.DatadogSite})
Expand Down
2 changes: 2 additions & 0 deletions http-canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var device map[string]deviceContext
// Canary handler
func inboundWebCanaryHandler(httpRsp http.ResponseWriter, httpReq *http.Request) {

AddAdditionalStat("canary_called", 1)

// Exit
if Config.CanaryDisabled {
return
Expand Down
28 changes: 27 additions & 1 deletion stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ var statsLock sync.Mutex
var stats map[string]HostStats
var statsServiceVersions map[string]string

type AdditionalStat struct {
Name string
Values []StatValue
}

type StatValue struct {
Time int64
Value int64
}

var AdditionalStats map[string]AdditionalStat

func AddAdditionalStat(name string, value int64) {
stat, ok := AdditionalStats[name]
if !ok {
// If the stat does not exist, create it
stat = AdditionalStat{Name: name}
}
// Add the new value
stat.Values = append(stat.Values, StatValue{Time: todayTime(), Value: value})
// Put the stat back into the map
AdditionalStats[name] = stat
}

// Trace
const addStatsTrace = true

Expand Down Expand Up @@ -709,7 +733,9 @@ func statsUpdateHost(hostname string, hostaddr string, reload bool) (ss serviceS
// If this is just the initial set of stats that were being loaded from the file system, ignore it,
// else write the stats to datadog
if len(addedStats) > 0 && time.Now().UTC().Unix() > statsInitCompleted+60 {
datadogUploadStats(hostname, ss.BucketSecs, addedStats)
datadogUploadStats(hostname, ss.BucketSecs, addedStats, AdditionalStats)
// Clean up the additional stats so it doesn't keep growing.
AdditionalStats = map[string]AdditionalStat{}
}

// Done
Expand Down