github.com/MetalBlockchain/subnet-evm@v0.4.9/metrics/README.md (about)

     1  go-metrics
     2  ==========
     3  
     4  ![travis build status](https://travis-ci.org/rcrowley/go-metrics.svg?branch=master)
     5  
     6  Go port of Coda Hale's Metrics library: <https://github.com/dropwizard/metrics>.
     7  
     8  Documentation: <https://godoc.org/github.com/rcrowley/go-metrics>.
     9  
    10  Usage
    11  -----
    12  
    13  Create and update metrics:
    14  
    15  ```go
    16  c := metrics.NewCounter()
    17  metrics.Register("foo", c)
    18  c.Inc(47)
    19  
    20  g := metrics.NewGauge()
    21  metrics.Register("bar", g)
    22  g.Update(47)
    23  
    24  r := NewRegistry()
    25  g := metrics.NewRegisteredFunctionalGauge("cache-evictions", r, func() int64 { return cache.getEvictionsCount() })
    26  
    27  s := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028)
    28  h := metrics.NewHistogram(s)
    29  metrics.Register("baz", h)
    30  h.Update(47)
    31  
    32  m := metrics.NewMeter()
    33  metrics.Register("quux", m)
    34  m.Mark(47)
    35  
    36  t := metrics.NewTimer()
    37  metrics.Register("bang", t)
    38  t.Time(func() {})
    39  t.Update(47)
    40  ```
    41  
    42  Register() is not threadsafe. For threadsafe metric registration use
    43  GetOrRegister:
    44  
    45  ```go
    46  t := metrics.GetOrRegisterTimer("account.create.latency", nil)
    47  t.Time(func() {})
    48  t.Update(47)
    49  ```
    50  
    51  **NOTE:** Be sure to unregister short-lived meters and timers otherwise they will
    52  leak memory:
    53  
    54  ```go
    55  // Will call Stop() on the Meter to allow for garbage collection
    56  metrics.Unregister("quux")
    57  // Or similarly for a Timer that embeds a Meter
    58  metrics.Unregister("bang")
    59  ```
    60  
    61  Periodically log every metric in human-readable form to standard error:
    62  
    63  ```go
    64  go metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
    65  ```
    66  
    67  Periodically log every metric in slightly-more-parseable form to syslog:
    68  
    69  ```go
    70  w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics")
    71  go metrics.Syslog(metrics.DefaultRegistry, 60e9, w)
    72  ```
    73  
    74  Periodically emit every metric to Graphite using the [Graphite client](https://github.com/cyberdelia/go-metrics-graphite):
    75  
    76  ```go
    77  
    78  import "github.com/cyberdelia/go-metrics-graphite"
    79  
    80  addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
    81  go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr)
    82  ```
    83  
    84  Installation
    85  ------------
    86  
    87  ```sh
    88  go get github.com/rcrowley/go-metrics
    89  ```
    90  
    91  StatHat support additionally requires their Go client:
    92  
    93  ```sh
    94  go get github.com/stathat/go
    95  ```
    96  
    97  Publishing Metrics
    98  ------------------
    99  
   100  Clients are available for the following destinations:
   101  
   102  * Prometheus - https://github.com/deathowl/go-metrics-prometheus