Giter VIP home page Giter VIP logo

metrics-go's Introduction

metrics-go

This package provides an interface for reporting metrics to statsd, along with Echo middleware for use with HTTP APIs.

Usage

Include the metrics-go package in your project:

import (
    "github.com/lob/metrics-go"
)

Create a new Metrics client:

cfg := metrics.Config{
    Namespace: "myapp",
}
m := metrics.New(cfg)

The metric Namespace must be provided.

All metrics reported from the instance will have the environment, container, and release added as tags.

You may also pass additional tags to all metrics methods as variadic string arguments.

You may wish to embed the metrics.Config struct in your applications configuration struct for convenience.

Count

m.Count("event-counter", 1)

Gauge

m.Gauge("num-workers", 5)

Histogram

m.Histogram("queue-depth", 10)

Close

m.Close()

Timers

t := metrics.NewTimer("api-call")

err := apiCall()
if err != nil {
    // End also takes tags that are added to the timer metric
    t.End("state:failed")
} else {
    t.End("state:success")
}

Middleware

This package includes middleware suitable for use with Echo servers.

m := metrics.New(cfg)
e := echo.New()
e.Use(metrics.Middleware(m))

Lambda

The server-less AWS Lambda Service allows us to do expensive computations without having to manage extra infrastructure. However, without control of the actual server the code is running on, it's impossible to run a Datadog agent on or alongside the host. This makes using a normal StatsD client unfeasible. Instead, we can write metrics to logs that Datadog reads through an AWS account integration as detailed here.

Configuration

The only differences in configuring this library for a lambda function instead of a standard Go library are:

  1. You must set Lambda: true in the metrics.Config.
  2. You must set LambdaLogger to a struct that implements the io.WriteCloser interface in the metrics.Config.

Development

# Install necessary dependencies for development
make setup

# Ensure dependencies are safe, complete, and reproducible
make deps

# Run tests and generate test coverage report
make test

# Run linter
make lint

# Remove temporary files generated by the build command and the build directory
make clean

Cutting a New Release

After new commits have been added, a new git tag should also be created so that tools like go mod and dep can utilize it for more semantic versioning.

If there is a breaking change introduced in this new version, then it should be a major version bump. If there are no breaking changes and only new features, then it should be a minor version bump. And if there are no breaking changes, no new features, and only bug fixes, then it should be a patch version.

After determining what the next version should be, make sure you're on an up-to-date master branch and run make release. The v in the version tag is important for tools to recognize it.

$ git checkout master
$ git fetch
$ git rebase
$ make release tag=v1.0.0 # replace 1.0.0 with the next version

metrics-go's People

Contributors

nyergler avatar virtualdom avatar dmlittle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.