Skip to content

Commit

Permalink
chore: add more examples (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma authored Mar 13, 2022
1 parent 24d77b9 commit 38dd166
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
6 changes: 3 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
)

func ExampleCounter_Inc() {
stat := statter.New(nil, time.Second)
stat := statter.New(statter.DiscardReporter, time.Second)

stat.Counter("my_counter", tags.Str("tag", "value")).Inc(1)
}

func ExampleGauge_Set() {
stat := statter.New(nil, time.Second)
stat := statter.New(statter.DiscardReporter, time.Second)

stat.Gauge("my_gauge", tags.Int("int", 1)).Set(1.23)
}

func ExampleHistogram_Observe() {
stat := statter.New(nil, time.Second)
stat := statter.New(statter.DiscardReporter, time.Second)

stat.Histogram("my_histo", tags.Str("label", "blah")).Observe(2.34)
}
18 changes: 18 additions & 0 deletions reporter/l2met/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package l2met_test

import (
"os"
"time"

"github.com/hamba/logger/v2"
"github.com/hamba/statter/v2"
"github.com/hamba/statter/v2/reporter/l2met"
)

func ExampleNew() {
log := logger.New(os.Stdout, logger.LogfmtFormat(), logger.Info)

reporter := l2met.New(log, "my-prefix")

statter.New(reporter, 10*time.Second)
}
37 changes: 37 additions & 0 deletions reporter/prometheus/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package prometheus_test

import (
"time"

"github.com/hamba/statter/v2"
"github.com/hamba/statter/v2/reporter/prometheus"
)

func ExampleNew() {
buckets := []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
reporter := prometheus.New("my-namespace", prometheus.WithBuckets(buckets))

statter.New(reporter, 10*time.Second)
}

func ExampleRegisterCounter() {
reporter := prometheus.New("my-namespace")
stats := statter.New(reporter, 10*time.Second).With("my-prefix")

prometheus.RegisterCounter(stats, "my-counter", []string{"tag"}, "my awesome counter")
}

func ExampleRegisterGauge() {
reporter := prometheus.New("my-namespace")
stats := statter.New(reporter, 10*time.Second).With("my-prefix")

prometheus.RegisterGauge(stats, "my-gauge", []string{"tag"}, "my awesome gauge")
}

func ExampleRegisterHistogram() {
reporter := prometheus.New("my-namespace")
stats := statter.New(reporter, 10*time.Second).With("my-prefix")

buckets := []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
prometheus.RegisterHistogram(stats, "my-gauge", []string{"tag"}, buckets, "my awesome histogram")
}
20 changes: 20 additions & 0 deletions reporter/statsd/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package statsd_test

import (
"time"

"github.com/hamba/statter/v2"
"github.com/hamba/statter/v2/reporter/statsd"
)

func ExampleNew() {
reporter, err := statsd.New("127.0.0.1:8125", "my-prefix",
statsd.WithFlushBytes(1432),
statsd.WithFlushInterval(300*time.Millisecond),
)
if err != nil {
panic(err)
}

statter.New(reporter, 10*time.Second)
}

0 comments on commit 38dd166

Please sign in to comment.