-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from ava-labs/metrics-pkg
add metrics pkg
- Loading branch information
Showing
77 changed files
with
6,500 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This repo has been forked from https://github.com/rcrowley/go-metrics at commit e181e09 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Copyright 2012 Richard Crowley. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY RICHARD CROWLEY ``AS IS'' AND ANY EXPRESS | ||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL RICHARD CROWLEY OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
The views and conclusions contained in the software and documentation | ||
are those of the authors and should not be interpreted as representing | ||
official policies, either expressed or implied, of Richard Crowley. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
go-metrics | ||
========== | ||
|
||
![travis build status](https://travis-ci.org/rcrowley/go-metrics.svg?branch=master) | ||
|
||
Go port of Coda Hale's Metrics library: <https://github.com/dropwizard/metrics>. | ||
|
||
Documentation: <https://godoc.org/github.com/rcrowley/go-metrics>. | ||
|
||
Usage | ||
----- | ||
|
||
Create and update metrics: | ||
|
||
```go | ||
c := metrics.NewCounter() | ||
metrics.Register("foo", c) | ||
c.Inc(47) | ||
|
||
g := metrics.NewGauge() | ||
metrics.Register("bar", g) | ||
g.Update(47) | ||
|
||
r := NewRegistry() | ||
g := metrics.NewRegisteredFunctionalGauge("cache-evictions", r, func() int64 { return cache.getEvictionsCount() }) | ||
|
||
s := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028) | ||
h := metrics.NewHistogram(s) | ||
metrics.Register("baz", h) | ||
h.Update(47) | ||
|
||
m := metrics.NewMeter() | ||
metrics.Register("quux", m) | ||
m.Mark(47) | ||
|
||
t := metrics.NewTimer() | ||
metrics.Register("bang", t) | ||
t.Time(func() {}) | ||
t.Update(47) | ||
``` | ||
|
||
Register() is not threadsafe. For threadsafe metric registration use | ||
GetOrRegister: | ||
|
||
```go | ||
t := metrics.GetOrRegisterTimer("account.create.latency", nil) | ||
t.Time(func() {}) | ||
t.Update(47) | ||
``` | ||
|
||
**NOTE:** Be sure to unregister short-lived meters and timers otherwise they will | ||
leak memory: | ||
|
||
```go | ||
// Will call Stop() on the Meter to allow for garbage collection | ||
metrics.Unregister("quux") | ||
// Or similarly for a Timer that embeds a Meter | ||
metrics.Unregister("bang") | ||
``` | ||
|
||
Periodically log every metric in human-readable form to standard error: | ||
|
||
```go | ||
go metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds)) | ||
``` | ||
|
||
Periodically log every metric in slightly-more-parseable form to syslog: | ||
|
||
```go | ||
w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics") | ||
go metrics.Syslog(metrics.DefaultRegistry, 60e9, w) | ||
``` | ||
|
||
Periodically emit every metric to Graphite using the [Graphite client](https://github.com/cyberdelia/go-metrics-graphite): | ||
|
||
```go | ||
|
||
import "github.com/cyberdelia/go-metrics-graphite" | ||
|
||
addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003") | ||
go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr) | ||
``` | ||
|
||
Installation | ||
------------ | ||
|
||
```sh | ||
go get github.com/rcrowley/go-metrics | ||
``` | ||
|
||
StatHat support additionally requires their Go client: | ||
|
||
```sh | ||
go get github.com/stathat/go | ||
``` | ||
|
||
Publishing Metrics | ||
------------------ | ||
|
||
Clients are available for the following destinations: | ||
|
||
* Prometheus - https://github.com/deathowl/go-metrics-prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// (c) 2022, Ava Labs, Inc. | ||
// | ||
// This file is a derived work, based on the go-ethereum library whose original | ||
// notices appear below. | ||
// | ||
// It is distributed under a license compatible with the licensing terms of the | ||
// original code from which it is derived. | ||
// | ||
// Much love to the original authors for their work. | ||
// ********** | ||
// Copyright 2021 The go-ethereum Authors | ||
// This file is part of go-ethereum. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package metrics | ||
|
||
// Config contains the configuration for the metric collection. | ||
type Config struct { | ||
Enabled bool `toml:",omitempty"` | ||
EnabledExpensive bool `toml:",omitempty"` | ||
HTTP string `toml:",omitempty"` | ||
Port int `toml:",omitempty"` | ||
} | ||
|
||
// DefaultConfig is the default config for metrics used in go-ethereum. | ||
var DefaultConfig = Config{ | ||
Enabled: false, | ||
EnabledExpensive: false, | ||
HTTP: "127.0.0.1", | ||
Port: 6060, | ||
} |
Oops, something went wrong.