• Stars
    star
    3,421
  • Rank 12,490 (Top 0.3 %)
  • Language
    Go
  • License
    Other
  • Created over 12 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go port of Coda Hale's Metrics library

go-metrics

travis build status

Go port of Coda Hale's Metrics library: https://github.com/dropwizard/metrics.

Documentation: http://godoc.org/github.com/rcrowley/go-metrics.

Usage

Create and update metrics:

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:

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:

// 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 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:

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:

import "github.com/cyberdelia/go-metrics-graphite"

addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr)

Periodically emit every metric into InfluxDB:

NOTE: this has been pulled out of the library due to constant fluctuations in the InfluxDB API. In fact, all client libraries are on their way out. see issues #121 and #124 for progress and details.

import "github.com/vrischmann/go-metrics-influxdb"

go influxdb.InfluxDB(metrics.DefaultRegistry,
  10e9, 
  "127.0.0.1:8086", 
  "database-name", 
  "username", 
  "password"
)

Periodically upload every metric to Librato using the Librato client:

Note: the client included with this repository under the librato package has been deprecated and moved to the repository linked above.

import "github.com/mihasya/go-metrics-librato"

go librato.Librato(metrics.DefaultRegistry,
    10e9,                  // interval
    "[email protected]", // account owner email address
    "token",               // Librato API token
    "hostname",            // source
    []float64{0.95},       // percentiles to send
    time.Millisecond,      // time unit
)

Periodically emit every metric to StatHat:

import "github.com/rcrowley/go-metrics/stathat"

go stathat.Stathat(metrics.DefaultRegistry, 10e9, "[email protected]")

Maintain all metrics along with expvars at /debug/metrics:

This uses the same mechanism as the official expvar but exposed under /debug/metrics, which shows a json representation of all your usual expvars as well as all your go-metrics.

import "github.com/rcrowley/go-metrics/exp"

exp.Exp(metrics.DefaultRegistry)

Installation

go get github.com/rcrowley/go-metrics

StatHat support additionally requires their Go client:

go get github.com/stathat/go

Publishing Metrics

Clients are available for the following destinations:

More Repositories

1

goagain

Zero-downtime restarts in Go
Go
2,080
star
2

go-tigertonic

A Go framework for building JSON web services inspired by Dropwizard
Go
995
star
3

certified

Generate and manage an internal CA for your company
HTML
416
star
4

freight

A modern take on the Debian archive.
Shell
401
star
5

slack

Run a command; post it and its standard input, output, and error to Slack
Shell
109
star
6

json.sh

Pure-shell JSON parser
Shell
94
star
7

mustache.sh

Mustache in POSIX shell
Shell
81
star
8

gitpaid

The programmer's time tracker
Shell
64
star
9

django-twitterauth

Use Twitter for authentication in Django
Python
56
star
10

go-librato

Go client for Librato Metrics
Go
52
star
11

puppet-pip

DON'T USE THIS, USE PUPPET 2.7
Ruby
33
star
12

debra

build Debian packages
Shell
30
star
13

bashpress

Command-line blog engine
PHP
26
star
14

clint

Ruby command line argument parser
Ruby
19
star
15

opendns-fetchstats

Automatically fetch your OpenDNS Top Domains data
Visual Basic
18
star
16

rcrowley

My home directory and
JavaScript
18
star
17

puppet-related_nodes

An alternative to Puppet's exported resources
Ruby
16
star
18

pagerunit

A simple Nagios alternative made to look like unit tests.
Python
9
star
19

curvr

Automatic approximation of typical Photoshop actions
C++
8
star
20

archiso

Branch of https://projects.archlinux.org/archiso.git that supports unattended installation
Shell
6
star
21

manskeleton

build skeleton man paths
6
star
22

gas

Gas is a tiny prefork WSGI server and app for streaming static files through grep-, awk- and sed-like generators.
Python
6
star
23

dopploadr

A Flickr Uploadr extension for geotagging photos with Dopplr trips.
JavaScript
6
star
24

extending-puppet

Example code from my Extending Puppet talk
Ruby
6
star
25

puppet-python

5
star
26

fpf

Effing package format!
Shell
5
star
27

upstartable-nginx

Shell
5
star
28

go-shellac

Very experimental experiment into a declarative, strongly-typed API for executing shell commands from Go
Go
5
star
29

wheresmycar

Scrapes SF GIS to send alerts when I need to move my car for street cleaning
PHP
5
star
30

thrudb

Modifications to the Thrudb storage engine built on Thrift.
C++
4
star
31

sometimes

a PHP templating system
PHP
4
star
32

powncefs

A Fuse filesystem for your friends' files on Pownce
Python
4
star
33

hapimoney

Django implementation of HapiMoney
Python
3
star
34

puppet-crunkd

3
star
35

puppet-ruby

3
star
36

spoon

Spoon feeds HTML5 into Atom.
Python
3
star
37

go-bson

Not just a mirror of http://labix.org/gobson
Go
3
star
38

talk-django-puppet

Deploying Django with Puppet
JavaScript
3
star
39

puppet-sourceinstall

3
star
40

ssh-freeagent

Shell
3
star
41

nomblr

Python
3
star
42

puppet-virtualbox

Shell
3
star
43

httperf_modified

httperf with percentiles
Shell
3
star
44

talk-developing-operability

JavaScript
2
star
45

mixinstall

Manage read-only "mixed projects" within your own
2
star
46

countd

DON'T USE THIS. It's an old experiment and I wanted to free up some space in my GitHub account.
Python
2
star
47

lazy_redis

Maybe this is not a terrible idea?
Ruby
2
star
48

puppet-interfaces

Legacy repository for reclaiming some lost bug fixes
Ruby
2
star
49

talk-blueprint

JavaScript
2
star
50

slack-gmail-screener

Get mentioned in Slack when you receive email from noteworthy senders; don't be bothered with the rest
Python
2
star
51

talk-extending-puppet

JavaScript
2
star
52

krecipec

Ruby
2
star
53

python-givvy

Python bindings to the Givvy API
2
star
54

errforce

Utilities for working effectively with Go errors and UNIX errnos
Go
1
star
55

fsevents

Mirror of Yossef Mendelssohn's probably defunct fsevents gem
Ruby
1
star
56

puppet-iptables

Puppet
1
star
57

talk-securing-and-extending-puppet

Securing and Extending Puppet talk
JavaScript
1
star
58

talk-why-is-config-mgmt-ruby

JavaScript
1
star
59

rcrowley.github.com

1
star
60

puppet-php

1
star
61

talk-dep-mgmt-with-puppet

Dependency Management with Puppet lightning talk
JavaScript
1
star
62

gimmeservers

Python
1
star