Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added counterAsGauge flag for librato compatibility & other fixes #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Usage of statsd:
-debug=false: enable logging of inputs and submissions
-flush=60: interval at which data is sent to librato (in seconds)
-percentiles="": comma separated list of percentiles to calculate for timers (eg. "95,99.5")
-counterAsGauge=false: submit counters as gauge for Librato compatibility
-source="": librato api source (LIBRATO_SOURCE)
-token="": librato api token (LIBRATO_TOKEN)
-user="": librato api username (LIBRATO_USER)
Expand Down
10 changes: 9 additions & 1 deletion librato.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ func submitLibrato() (err error) {
defer resp.Body.Close()

if resp.StatusCode != 200 {
if resp.StatusCode == 400 {
resetAll()
}
raw, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf("%s: %s", resp.Status, string(raw))
}

if *debug {
raw, _ := ioutil.ReadAll(resp.Body)
log.Printf("%s: %s", resp.Status, string(raw))
}

log.Printf("%d measurements sent to librato\n", m.Count())

resetTimers()
resetAll()

return
}
Expand Down
19 changes: 10 additions & 9 deletions main.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (
const VERSION = "1.0.0"

var (
address = flag.String("address", "0.0.0.0:8125", "udp listen address")
libratoUser = flag.String("user", "", "librato api username (LIBRATO_USER)")
libratoToken = flag.String("token", "", "librato api token (LIBRATO_TOKEN)")
libratoSource = flag.String("source", "", "librato api source (LIBRATO_SOURCE)")
interval = flag.Int64("flush", 60, "interval at which data is sent to librato (in seconds)")
percentiles = flag.String("percentiles", "", "comma separated list of percentiles to calculate for timers (eg. \"95,99.5\")")
proxy = flag.String("proxy", "", "send metrics to a proxy rather than directly to librato")
debug = flag.Bool("debug", false, "enable logging of inputs and submissions")
version = flag.Bool("version", false, "print version and exit")
address = flag.String("address", "0.0.0.0:8125", "udp listen address")
libratoUser = flag.String("user", "", "librato api username (LIBRATO_USER)")
libratoToken = flag.String("token", "", "librato api token (LIBRATO_TOKEN)")
libratoSource = flag.String("source", "", "librato api source (LIBRATO_SOURCE)")
interval = flag.Int64("flush", 60, "interval at which data is sent to librato (in seconds)")
percentiles = flag.String("percentiles", "", "comma separated list of percentiles to calculate for timers (eg. \"95,99.5\")")
proxy = flag.String("proxy", "", "send metrics to a proxy rather than directly to librato")
debug = flag.Bool("debug", false, "enable logging of inputs and submissions")
version = flag.Bool("version", false, "print version and exit")
counterAsGauge = flag.Bool("counterAsGauge", false, "use counters as guage for Librato compatibility")
)

func monitor() {
Expand Down
18 changes: 15 additions & 3 deletions metric.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

import "log"

var (
counters = make(map[string]float64)
gauges = make(map[string]float64)
Expand All @@ -14,10 +16,20 @@ func init() {
func readPacket(p packet) {
switch p.bucket {
case "c":
if _, f := counters[p.name]; !f {
counters[p.name] = 0.0
if *counterAsGauge == true {
if _, f := gauges[p.name]; !f {
gauges[p.name] = 0.0
}
gauges[p.name] += p.value
if *debug {
log.Printf("counter as guage %.1f\n", gauges[p.name])
}
} else {
if _, f := counters[p.name]; !f {
counters[p.name] = 0.0
}
counters[p.name] += p.value
}
counters[p.name] += p.value

case "g":
gauges[p.name] = p.value
Expand Down