Documentation ¶
Index ¶
- Constants
- Variables
- func Disable()
- func Send(metrics M, path ...string)
- func SendAndWait(metrics M, path ...string) error
- func SendWithTags(metrics M, tags T, path ...string)
- func SendWithTagsAndWait(metrics M, tags T, path ...string) error
- func SetErrorHandler(fn ErrorHandler)
- func Setup(url string, application, hostname string, options ...nats.Option) error
- func Watch(interval time.Duration) error
- type Conn
- type ErrorHandler
- type M
- type T
Constants ¶
const DefaultQueue = "telegraf"
DefaultQueue is queue where we puts event into NATS
Variables ¶
var ( // ErrAppNameNotSet not set ErrAppNameNotSet = errors.New("application name not set") // ErrHostNameNotSet not set ErrHostNameNotSet = errors.New("hostname not set") )
var DefaultErrorHandler = func(err error) { fmt.Fprintf(os.Stderr, "Error while sending metrics: %v", err) }
DefaultErrorHandler just printing all errors comes from async writes to Stderr
Functions ¶
func SendAndWait ¶
SendAndWait metrics to NATS queue waiting for response
Example:
err = SendAndWait(metrics.M{ "counter": i, }, "metricname")
func SendWithTags ¶
SendWithTags metrics to NATS queue waiting for response
Example:
err = SendWithTags(metrics.M{ "counter": i, }, metrics.T{
"tag": "sometag", }, "metricname")
func SendWithTagsAndWait ¶
SendWithTagsAndWait metrics to NATS queue waiting for response
Example:
err = SendWithTags(metrics.M{ "counter": i, }, metrics.T{
"tag": "sometag", }, "metricname")
func SetErrorHandler ¶
func SetErrorHandler(fn ErrorHandler)
SetErrorHandler changes error handler to provided one
func Setup ¶
Setup rewrites default metrics configuration
Params: - url (in e.g. "nats://localhost:4222") - options nats.Option array
Example: import (
"log" "github.com/cryptopay.dev/go-metrics"
)
func main() { err := metrics.Setup("nats://localhost:4222") if err != nil { log.Fatal(err) } for i:=0; i<10; i++ { err = metrics.SendAndWait(metrics.M{ "counter": i, }) if err != nil { log.Fatal(err) } } }
Types ¶
type Conn ¶
type Conn interface { SetErrorHandler(fn ErrorHandler) Send(metrics M, path ...string) SendWithTags(metrics M, tags T, path ...string) SendWithTagsAndWait(metrics M, tags T, path ...string) error SendAndWait(metrics M, path ...string) error Disable() Watch(interval time.Duration) error }
Conn - connection interface
var DefaultConn Conn
DefaultConn shared default metric connection
func New ¶
New creates new metrics connection
Params: - url (in e.g. "nats://localhost:4222") - options nats.Option array
Example: import (
"log" "github.com/cryptopay.dev/go-metrics"
)
func main() { m, err := metrics.New("nats://localhost:4222") if err != nil { log.Fatal(err) } for i:=0; i<10; i++ { err = m.SendAndWait(metrics.M{ "counter": i, }) if err != nil { log.Fatal(err) } } }