Skip to content

Commit

Permalink
added Unix Domain Sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenruizdegauna committed Mar 8, 2022
1 parent 0b01b21 commit 79e6a71
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Usage of ./gen-statsd:
-run-time=0s: how long to run, 0=forever
-sample-rate=0: sampling rate
-spawn-drift=10: spread new agent generation by 0-n seconds
-statsd-hosts="localhost:8125:udp": comma separated list of ip:port:proto for statsD host(s)
-statsd-hosts="localhost:8125:udp": comma separated list of ip:port:proto or UDS socket path for statsD host(s).
-tag-format="": format of the tags to send. accepted values "datadog" or "influx"
-tags="": list of K:V comma separated tags. Example: key1:tag1,key2:tag2
-timer-samples=10: number of timer samples per iteration
Expand All @@ -32,25 +32,25 @@ Usage of ./gen-statsd:

### Environment Variables

| Variable | Description |
|:-------------:|:----------------------------------------------------------------|
|AGENTS |max number of agents to run concurrently (default 10) |
|CONFIG |path to config file |
|COUNTERS |number of counters for each agent to hold (default 50) |
|FLUSH_INTERVAL |how often to flush metrics (default 10s) |
|GAUGES |number of gauges for each agent to hold (default 30) |
|PREFIX |prefix for metrics (default "gen-statsd") |
|QUIET |run gen-statsd in quiet mode |
|RUN_TIME |how long to run, 0=forever |
|SAMPLE_RATE |sampling rate (default 0) |
|SPAWN_DRIFT |spread new agent generation by 0-n seconds (default 10) |
|STATSD_HOSTS |comma separated list of ip:port:proto for statsD host(s) |
|TAG_FORMAT |format of the tags to send. accepted values "datadog" or "influx |
|TAGS |list of K:V comma separated tags. Example: key1:tag1,key2:tag2 |
|TIMERS |number of timers for each agent to hold (default 20) |
|VALUE_MAX |maximum value to send (default 100) |
|VALUE_MIN |minimum value to send (default 0) |
|VERSION |show version information |
| Variable | Description |
|:-------------:|:--------------------------------------------------------------------------------------|
|AGENTS |max number of agents to run concurrently (default 10) |
|CONFIG |path to config file |
|COUNTERS |number of counters for each agent to hold (default 50) |
|FLUSH_INTERVAL |how often to flush metrics (default 10s) |
|GAUGES |number of gauges for each agent to hold (default 30) |
|PREFIX |prefix for metrics (default "gen-statsd") |
|QUIET |run gen-statsd in quiet mode |
|RUN_TIME |how long to run, 0=forever |
|SAMPLE_RATE |sampling rate (default 0) |
|SPAWN_DRIFT |spread new agent generation by 0-n seconds (default 10) |
|STATSD_HOSTS |comma separated list of ip:port:proto or UDS socket path for statsD for statsD host(s) |
|TAG_FORMAT |format of the tags to send. accepted values "datadog" or "influx |
|TAGS |list of K:V comma separated tags. Example: key1:tag1,key2:tag2 |
|TIMERS |number of timers for each agent to hold (default 20) |
|VALUE_MAX |maximum value to send (default 100) |
|VALUE_MIN |minimum value to send (default 0) |
|VERSION |show version information |

## Releases

Expand Down
24 changes: 16 additions & 8 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,26 @@ func (ac *AgentController) Start(c config) {
statsdClients := make([]*statsd.Client, 0)
for _, t := range targets {
t := t
ip := ""
port := "8125"
proto := "udp"
address := ":8125"
spec := strings.Split(t, ":")
switch len(spec) {
case 3:
ip = spec[0]
port = spec[1]
address = fmt.Sprintf("%s:%s", spec[0], spec[1])
proto = spec[2]
case 2:
ip = spec[0]
port = spec[1]
address = fmt.Sprintf("%s:%s", spec[0], spec[1])
case 1:
ip = spec[0]
address = spec[0]
if isSocket(address) {
proto = "unixgram"
}
default:
log.Printf("invalid target spec (%s)", t)
continue
}
client, err := statsd.New(
statsd.Address(ip+":"+port),
statsd.Address(address),
statsd.Network(proto),
statsd.FlushPeriod(c.flushInterval),
statsd.Prefix(c.prefix),
Expand Down Expand Up @@ -326,3 +326,11 @@ func done(ctx context.Context) bool {
return false
}
}

func isSocket(path string) bool {
fi, err := os.Stat(path)
if err != nil {
return false
}
return fi.Mode()&os.ModeSocket != 0
}

0 comments on commit 79e6a71

Please sign in to comment.