Skip to content

Commit

Permalink
added stattype (counters/gauges/timers) to each metric
Browse files Browse the repository at this point in the history
switched counters from publishing count to rate with .rate suffix
  • Loading branch information
nnaoumov committed Jun 16, 2015
1 parent 5c4dd1c commit ea30b41
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions statsdaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,17 @@ func processCounters(buffer *bytes.Buffer, now int64) int64 {
var num int64
// continue sending zeros for counters for a short period of time even if we have no new data
for bucket, value := range counters {
fmt.Fprintf(buffer, "%s %d %d\n", bucket, value, now)
//fmt.Fprintf(buffer, "%s.count %d %d\n", bucket, value, now)
rate := float64(value)/float64(*flushInterval)
fmt.Fprintf(buffer, "%s.rate %f %d\n", bucket, rate, now)
delete(counters, bucket)
countInactivity[bucket] = 0
num++
}
for bucket, purgeCount := range countInactivity {
if purgeCount > 0 {
fmt.Fprintf(buffer, "%s %d %d\n", bucket, 0, now)
//fmt.Fprintf(buffer, "%s %d %d\n", bucket, 0, now)
fmt.Fprintf(buffer, "%s.rate %d %d\n", bucket, 0, now)
num++
}
countInactivity[bucket] += 1
Expand Down Expand Up @@ -501,6 +504,7 @@ func parseLine(line []byte) *Packet {
var (
err error
value interface{}
stattype string
)

switch typeCode {
Expand All @@ -510,6 +514,7 @@ func parseLine(line []byte) *Packet {
log.Printf("ERROR: failed to ParseInt %s - %s", string(val), err)
return nil
}
stattype = "counters."
case "g":
var rel, neg bool
var s string
Expand All @@ -536,21 +541,24 @@ func parseLine(line []byte) *Packet {
}

value = GaugeData{rel, neg, value.(uint64)}
stattype = "gauges."
case "s":
value = string(val)
stattype = "timers."
case "ms":
value, err = strconv.ParseUint(string(val), 10, 64)
if err != nil {
log.Printf("ERROR: failed to ParseUint %s - %s", string(val), err)
return nil
}
stattype = "timers."
default:
log.Printf("ERROR: unrecognized type code %q", typeCode)
return nil
}

return &Packet{
Bucket: sanitizeBucket(*prefix + string(name) + *postfix),
Bucket: sanitizeBucket(*prefix + stattype + string(name) + *postfix),
Value: value,
Modifier: typeCode,
Sampling: sampling,
Expand Down

0 comments on commit ea30b41

Please sign in to comment.