Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wazazaby authored Oct 8, 2023
1 parent 5aa1db3 commit 2eba775
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# vimebu
Vimebu is a small library that provides a builder to create VictoriaMetrics compatible metrics.

### Usage
## Usage
### Builder pattern
```go
import (
"github.com/wazazaby/vimebu"
Expand Down Expand Up @@ -70,3 +71,67 @@ func getHTTPRequestCounter(path string) *vm.Counter {
return vm.GetOrCreateCounter(metric)
}
```

### Functional pattern
Vimebu also exposes another builder using a more functional pattern. Here are the same example as above using it.
```go
import (
"github.com/wazazaby/vimebu"
vm "github.com/VictoriaMetrics/metrics"
)

var (
requestsTotalCounter = vm.NewCounter(
vimebu.BuilderFunc("request_total", vimebu.WithLabel("path", "/foo/bar")), // request_total{path="/foo/bar"}
)

responseSizeHistogram = vm.NewHistogram(
vimebu.BuilderFunc("response_size"), // response_size{}
)
)
```

```go
import (
"net"
"github.com/wazazaby/vimebu"
vm "github.com/VictoriaMetrics/metrics"
)

func getCassandraQueryCounter(name string, host net.IP) *vm.Counter {
metric := vimebu.BuilderFunc("cassandra_query_total",
vimebu.WithLabel("name", name),
vimebu.WithLabel("host", host.String()),
) // cassandra_query_total{name="beep",host="1.2.3.4"}
return vm.GetOrCreateCounter(metric)
}
```

```go
import (
"github.com/wazazaby/vimebu"
vm "github.com/VictoriaMetrics/metrics"
)

func getHTTPRequestCounter(host string) *vm.Counter {
metric := vimebu.BuilderFunc("api_http_requests_total",
vimebu.WithLabelCond(func() bool { return host != "" }, "host", host),
) // api_http_requests_total{} or api_http_requests_total{host="api.app.com"}
return vm.GetOrCreateCounter(metric)
}
```

```go
import (
"github.com/wazazaby/vimebu"
vm "github.com/VictoriaMetrics/metrics"
)

func getHTTPRequestCounter(path string) *vm.Counter {
metric := vimebu.BuilderFunc(
"api_http_requests_total",
vimebu.WithLabelQuote("path", path"),
) // api_http_requests_total{path="some/bro\"ken/path"}
return vm.GetOrCreateCounter(metric)
}
```

0 comments on commit 2eba775

Please sign in to comment.