55 "time"
66)
77
8+ // Client is the main object the applications holds to do metrics.
9+ // It can be used directly for ad-hoc events, or be used to create persistent
10+ // gauge/conter/timer/... objects optimised for bulk metric generation.
811type Client struct {
912
1013 // Wait for all flushers to empty before exiting Stop()
@@ -32,7 +35,7 @@ func init() {
3235
3336// NewClient returns you a client handle directly if you do not want to use the
3437// global default client.
35- // Create a new metric client with a factory object for the sink.
38+ // Creates a new metric client with a factory object for the sink.
3639// If sink == nil, the client will not emit metrics until a Sink is set.
3740func NewClient (sinkf SinkFactory , opts ... MOption ) (client * Client ) {
3841
@@ -51,13 +54,13 @@ func NewClient(sinkf SinkFactory, opts ...MOption) (client *Client) {
5154 return
5255}
5356
54- // Set options on the default metric client
57+ // SetDefaultOptions sets options on the default metric client
5558func SetDefaultOptions (opts ... MOption ) {
5659 c := defaultClient
5760 c .SetOptions (opts ... )
5861}
5962
60- // Set options on a client - like the flush interval for metrics which
63+ // SetOptions sets options on a client - like the flush interval for metrics which
6164// haven't them selves a fixed flush interval
6265func (c * Client ) SetOptions (opts ... MOption ) {
6366 conf := make (map [string ]interface {})
@@ -74,12 +77,14 @@ func (c *Client) SetOptions(opts ...MOption) {
7477 c .fmu .Unlock ()
7578}
7679
80+ // SetDefaultSink sets the sink for the default metics client
7781func SetDefaultSink (sinkf SinkFactory ) {
7882 c := defaultClient
7983 c .SetSink (sinkf )
8084}
8185
82- // The the Sink factory of the client
86+ // SetSink sets the Sink factory of the client.
87+ // You'll need to set a sink before any metrics will be emitted.
8388func (c * Client ) SetSink (sinkf SinkFactory ) {
8489 c .fmu .Lock ()
8590
@@ -119,7 +124,7 @@ func (c *Client) Start() {
119124 c .running = true
120125}
121126
122- // Stops the global default metrics client
127+ // Stop the global default metrics client
123128func Stop () {
124129 defaultClient .Stop ()
125130}
@@ -182,19 +187,27 @@ func (c *Client) Flush() {
182187 c .defaultFlusher .FlushSink ()
183188}
184189
190+ // Counter creates an ad-hoc counter metric event.
191+ // If flush is true, the sink will be instructed to flush data immediately
185192func (c * Client ) Counter (name string , val int , flush bool ) {
186193 c .defaultFlusher .RecordNumeric64 (MeterCounter , name , Numeric64 {Type : Int64 , value : uint64 (val )}, flush )
187194}
188195
196+ // Gauge creates an ad-hoc gauge metric event.
197+ // If flush is true, the sink will be instructed to flush data immediately
189198func (c * Client ) Gauge (name string , val uint64 , flush bool ) {
190199 c .defaultFlusher .RecordNumeric64 (MeterGauge , name , Numeric64 {Type : Uint64 , value : uint64 (val )}, flush )
191200}
192201
202+ // Timer creates an ad-hoc timer metric event.
203+ // If flush is true, the sink will be instructed to flush data immediately
193204func (c * Client ) Timer (name string , d time.Duration , flush bool ) {
194205 val := d .Nanoseconds ()/ int64 (1000000 )
195206 c .defaultFlusher .RecordNumeric64 (MeterTimer , name , Numeric64 {Type : Uint64 , value : uint64 (val )}, flush )
196207}
197208
209+ // Sample creates an ad-hoc histogram metric event.
210+ // If flush is true, the sink will be instructed to flush data immediately
198211func (c * Client ) Sample (name string , val int64 , flush bool ) {
199212 c .defaultFlusher .RecordNumeric64 (MeterHistogram , name , Numeric64 {Type : Int64 , value : uint64 (val )}, flush )
200213}
0 commit comments