Skip to content

Commit

Permalink
fix stats key prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
xjewer committed Sep 28, 2017
1 parent 06df008 commit 3f89492
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/reader_test_offset*
.idea/

config.yml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This tool allows to parse log files and send statistics to statsd endpoint

* {string} `config` - configuration file
* {string} `statsd` - statsd endpoint
* {string} `prefix` - statsd global key prefix
* {string} `prefix` - statsd global key prefix, e.g. `balancer.`
* {int} `buffer` - buffer interval for metrics, `0` default: one metric - one request

### Configuration file
Expand Down Expand Up @@ -39,7 +39,7 @@ where is:
* {boolean} `noFollow` - means no follow new lines that are written in the log file, if true
* {boolean} `mustExists` - log file have to be existed, if true
* {boolean} `reOpen` - re-open file, if true (e.g. log rotation)
* {string} `prefix` - statsd key prefix
* {string} `prefix` - statsd key prefix, `%HOST%` is used as substitution a hostname
* {string} `delimiter` - column delimiter in log files, it is reasonable to use `\t` delimiter in log files

* {[]key} `keys` - list of keys, which would be send to statsd
Expand Down
2 changes: 1 addition & 1 deletion cmd/snitch/snitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (

cfg = flag.String("config", config.DefaultConfigPath, "config file name")
statsdEndpoint = flag.String("statsd", "", "statsd endpoint")
statsdKeyPrefix = flag.String("prefix", "test", "statsd global key prefix")
statsdKeyPrefix = flag.String("prefix", "", "statsd global key prefix")
buffer = flag.Int("buffer", 0, "statsd buffer interval")
)

Expand Down
7 changes: 3 additions & 4 deletions lib/stats/stats.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package stats

import (
"fmt"
"time"

"github.com/quipo/statsd"
)

// NewStatsd return new statsd client
// NewStatsd return the new statsd client
func NewStatsd(s string, prefix string, buffer int) statsd.Statsd {
if s == "" {
return statsd.NewStdoutClient("", prefix)
Expand All @@ -23,10 +22,10 @@ func NewStatsd(s string, prefix string, buffer int) statsd.Statsd {

// SendTiming writes timings in milliseconds
func SendTiming(s statsd.Statsd, key string, t int64) {
s.Timing(fmt.Sprintf("timings.%s", key), t)
s.Timing(key, t)
}

// SendEvent writes event types
func SendEvent(s statsd.Statsd, key string) {
s.Incr(fmt.Sprintf("count.%s", key), 1)
s.Incr(key, 1)
}
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

var (
ErrProcessorStopped = errors.New("processor is stopped")
ErrEmptyVarName = errors.New("empty var name")
ErrProcessorIsFinished = errors.New("processor is finished")
ErrEmptyVarName = errors.New("empty var name")
)

// Parser parses log text from reader and sends statistics
Expand Down
2 changes: 1 addition & 1 deletion processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (p *Processor) Close() error {
if err != ErrReaderIsFinished {
p.l.Println(err)
}
p.Kill(ErrProcessorStopped)
p.Kill(ErrProcessorIsFinished)
return p.Wait()
}

Expand Down
4 changes: 2 additions & 2 deletions processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func Test_ProcessorRun(t *testing.T) {
}()

lines <- snitch.NewLine("test", nil)
a.Equal(snitch.ErrProcessorStopped, p.Close())
//a.Equal(0, len(lines))
a.Equal(snitch.ErrProcessorIsFinished, p.Close())
a.Equal(0, len(lines))
wg.Wait()
close(lines)
}
8 changes: 1 addition & 7 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ func (r *fileReader) Close() error {
}
r.tail.Cleanup()
r.tail.Kill(ErrReaderIsFinished)
err := r.tail.Wait()
if err != ErrReaderIsFinished {
return err
}

return nil
return r.tail.Wait()
}

// openFile opens simplelog file to read its lines
Expand Down Expand Up @@ -116,7 +111,6 @@ func (r *fileReader) GetLines(lines chan<- *Line) {
}
lines <- NewLine(l.Text, l.Err)
case <-r.tail.Dying():
r.l.Println("dying")
return
}
}
Expand Down

0 comments on commit 3f89492

Please sign in to comment.