ephemeral metric aggregation server

hemera

hemera is a zero-dependency statsd implementation written in Go. The project takes advantage of modular packages and interfaces to make connecting to any backend simple. By default, the hemera binary connects to a Graphite server over TCP.

Documentation

Installing hemera

Install the binary by running the following:

go install github.com/andresoro/hemera

Install both the binary and the package by running:

go get github.com/andresoro/hemera

Basic usage

First make sure the package has been installed then simply run the following to run hemera with default configuration.

hemera

This will start the server with default configuration with the following flags but each one can be changed individually:

  • -p 8484 port where hemera server listens for metrics over UDP
  • -g 2003 port to connect to graphite instance to purge metrics over TCP
  • -s localhost server host
  • -t 10 interval in seconds for purging metrics to the server
# listen for metrics on port 8000 and purge to backend every 5 seconds
hemera -p 8000 -t 5

Supported metrics

hemera supports the four metrics that statsd supports. They are of the following form where bucket represents the name of the metric to update.

<bucket>:<value>|<metric-type>|@<sampling-rate>

Counters

Counters represent metrics that can only be incremented. During each purge cycle the counter is reset to 0.

# increment the 'button' bucket by 2
button:2|c

Sets

Sets hold a unique collection of values which represent events from the client. What is purge is the cardinality of the set at the purge interval.

# set named uniques will add the value '22' only if it does not already exist
uniques:22|s

Gauges

A gauge can fluctuate positively or negatively and will take on an arbitrary value assigned to it.

# set the 'gaugor' gauge to 100
gaugor:100|g

# set the 'gaugor' gauge to 1000
gaugor:1000|g

Timers

Timers generate an array of statistics that are purged to the backend:

  • Min/Max value
  • Count
  • Average
  • Median
  • 95th percentile
  • Standard Deviation

Timers currently only support the ms metric tag.

Hemera has two timer metrics. First is the raw input metrics under cache.Timers and the second is the computed metric statistics in this form <metric-name>.min.<value> which is returned by cache.TimerStats().

# load-time took 225ms to complete this time
load-time:225|ms

Creating new backend interfaces

Backends must simply satisfy the following interface:

type Backend interface {
    Purge(c *cache.Cache) error
}

It is up to the user to decide how to purge the actual values out. The cache.Cache struct exports all the values that are currently held since last purge cycle.

Warning: Do not clear the cache from the Purge() function as it is done by the server. Would cause issues when using multiple backends.

For example, a backend implementation where we only purge counters to the standard output would look like this.

type ConsoleBackend struct{}

// implement backend interface
func (cb *ConsoleBackend) Purge(c *cache.Cache) error {

    // only handling counters
    for name, value := range c.Counters {
        fmt.Printf("counter name: %s value: %f \n", name, value)
    }

    return nil
}

Remember while the cache.Timers map holds raw timer metrics, the statistics (min,max, std dev, etc) comes from calling cache.TimerStats() and getting values from the cache.TimerData map.

Take a look at the graphite implementation for a more robust example.

Using new backend interfaces

The server takes care of the cache and metric collection. If you want to use a new backend interface simply define it and add it to a new server instance. The server.New() function can take in a variadic amount of backends.

import github.com/andresoro/hemera/pkg/backend
import github.com/andresoro/hemera/pkg/server

// import a backend from the hemera backend package
graphite := &backend.Graphite{Addr: "localhost:2003"}

// and use a backend you implemented
console := &ConsoleBackend{}

// new server with given purge interval, host/port, and the backends that we would like to purge to. 
srv, err := server.New(purgeTime, host, port, graphite, console)

srv.Run()

To Do

  • Actually tackle to-dos
  • Add support for incrementing/decrementing gauges with '+' or '-' signs in metric value.
  • Benchmark tests
  • Better logging
  • Full testing
Owner
Andres Orozco
writing things that do stuff
Andres Orozco
Similar Resources

A server for TurboRepo Remote Cache to store cache artefacts in Google Cloud Storage or Amazon S3

Tapico Turborepo Remote Cache This is an implementation of Vercel's Turborepo Remote Cache API endpoints used by the turborepo CLI command. This solut

Dec 13, 2022

Temporal Server docker-compose files

Temporal Server docker-compose files This repository provides docker-compose fil

Dec 24, 2021

Transcoder - This package implements a transcoding server

muxable/transcoder This package implements a transcoding server. It accepts WebR

Dec 30, 2022

Embedded javascript server-side renderer for Golang

v8ssr Embedded javascript server-side renderer for Golang. Useful for static server-side rendering. This does not attempt to polyfill node or browser

Aug 27, 2022

Forklift: an API application developed with go that enables virtual server migration from vcenter virtualization environment to openstack environment

Forklift: an API application developed with go that enables virtual server migration from vcenter virtualization environment to openstack environment

What is the Forklift? Forklift is an API application developed with go that enables virtual server migration from vcenter virtualization environment t

Jan 14, 2022

Plant environment data sensor aggregation / UI server.

Plant environment data sensor aggregation / UI server.

What? A pet project to design a simple garden sensor and custom server for aggregating data and providing a simple user interface. Nginx gateway for s

Dec 10, 2022

A Discord bot for managing ephemeral roles based upon voice channel member presence.

A Discord bot for managing ephemeral roles based upon voice channel member presence.

ephemeral-roles A Discord bot for managing ephemeral roles based upon voice channel member presence. Quickstart Click on the Ephemeral Roles logo head

Dec 19, 2022

Test your code without writing mocks with ephemeral Docker containers 📦 Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code 💻

Gnomock – tests without mocks 🏗️ Spin up entire dependency stack 🎁 Setup initial dependency state – easily! 🏭 Test against actual, close to product

Dec 29, 2022

An operator for managing ephemeral clusters in GKE

Test Cluster Operator for GKE This operator provides an API-driven cluster provisioning for integration and performance testing of software that integ

Oct 22, 2022

Fast, realtime regex-extraction, and aggregation into common formats such as histograms, numerical summaries, tables, and more!

Fast, realtime regex-extraction, and aggregation into common formats such as histograms, numerical summaries, tables, and more!

rare A file scanner/regex extractor and realtime summarizor. Supports various CLI-based graphing and metric formats (histogram, table, etc). Features

Dec 29, 2022

Ephemeral One Time/Build-Time gRPC TLS PKI system.

PkiSauce Ephemeral Build Time TLS PKI saucing for your intra services GRPC (or not) communications. Description A simple attempt to avoid deploying co

Jul 4, 2022

A Kubernetes CSI plugin to automatically mount SPIFFE certificates to Pods using ephemeral volumes

A Kubernetes CSI plugin to automatically mount SPIFFE certificates to Pods using ephemeral volumes

csi-driver-spiffe csi-driver-spiffe is a Container Storage Interface (CSI) driver plugin for Kubernetes to work along cert-manager. This CSI driver tr

Dec 1, 2022

Multi-cluster api gateway based on apiserver-aggregation.

Cluster Gateway "Cluster-Gateway" is a gateway apiserver for routing kubernetes api traffic to multiple kubernetes clusters. Additionally, the gateway

Jan 6, 2023

Assignment aggregation system

Assignment aggregation system . Assignment Build aggregation system. You need create an endpoint to receive the events, and an endpoint to get each

Nov 4, 2021

Kubernetes APIServer Aggregation Sample

apiserver-aggregation-sample Kubernetes APIServer Aggregation Sample Create an apiserver sample Initialize the Project apiserver-boot init repo --doma

Nov 23, 2021

Run your workloads on ephemeral Virtual Machines

vm-spinner Run your workloads on ephemeral Virtual Machines. Descriprion A simple tool that spawns an arbitrary number of VMs in parallel, runs the sa

Jan 21, 2022

A plugin for Hashicorp Vault to create ephemeral users and API tokens for Jenkins CI

A plugin for Hashicorp Vault to create ephemeral users and API tokens for Jenkins CI

vault-plugin-secrets-jenkins This is a backend plugin to be used with Hashicorp Vault. This plugin generates ephemeral Jenkins Users and API tokens. v

Dec 15, 2022

RSS master is a RSS subscription function aggregation tool, You can use it easily!

🇨🇳 中文 rsm ✨ RSS master[rsm] is a RSS subscription function aggregation tool, You can use it easily! How to start? 🚁 Start rsm with rsm run -c,--cfg

Oct 18, 2022

Butler - Aggregation and Alerting Platform

Butler - Aggregation and Alerting Platform

Welcome to Butler Table of Contents Welcome About The Project Contributing Developer Workflow Getting Started Configuration About The Project Contribu

Mar 1, 2022
Comments
  • Beautify code

    Beautify code

    While watching Youtube, reading reddit and watching the rain from the comfort of my sofa, I skimmed through your code and beautified it according to my taste, common (and Uber's) best practice and whatever linters complained about. There is one linter complaint that I was too lazy about, I tagged it with a FIXME.

    Most of the changes have some reason behind them; please ask if something is not obvious. Sorry for being lazy and not writing a proper commit message explaining "the why" as a commit message should do.

    Consider using golangci-lint from the start.

    See also:

    • https://github.com/golang/go/wiki/CodeReviewComments
    • https://github.com/uber-go/guide/blob/master/style.md
  • Please test with --race detector

    Please test with --race detector

    Hello, I was a bit bored and looked over your code after your post on /r/golang. I did (edit: not) read the code thoroughly, but I suspect you use a bunch of maps concurrently which is not safe. You should be able to confirm this error with the --race detector and firing a couple of requests against your server.

    Either protect the maps with a mutex, or, since it is a cache and it might fit the use case, use sync.Map.

Related tags
mackerel metric plugin for count lines in log

mackerel metric plugin for count lines in log

Nov 13, 2021
RTS: request to struct. Generates Go structs from JSON server responses.

RTS: Request to Struct Generate Go structs definitions from JSON server responses. RTS defines type names using the specified lines in the route file

Dec 7, 2022
A minimalistic message queue server, in Go

lineup, a tiny queue server lineup is a very simple queue server. all it does is serve a binary-safe priority queue with a simple protocol insp

Aug 17, 2022
OTS: Open Terraforming Server
 OTS: Open Terraforming Server

OTS: Open Terraforming Server A prototype open source alternative to terraform enterprise

Jan 2, 2023
server for dozenplans
server for dozenplans

DozenPlans Server 学习养成计划主要是针对考研学生用户的任务管理系统, 用户可以添加 学习 任务, 每个任务都有自己的主题、 完成时间和优先级, 根据设定的完成时间和优先级对 用户进行不同频率的提醒, 直到其完成该任务, 任务可以设定提醒频率和时间期限, 避免导致任务越堆积越多, 除

Sep 17, 2021
thermal print server for esc pos printers

thprint thprint is an extremely simple printing server for thermal printers connected to raspberry pis. This printing server exposes a print endpoint

Nov 4, 2021
Count Dracula is a fast metrics server that counts entries while automatically expiring old ones

In-Memory Expirable Key Counter This is a fast metrics server, ideal for tracking throttling. Put values to the server, and then count them. Values ex

Jun 17, 2022
Module to ease interaction with Pact's development server & ScalableBFT

go-pact Module to ease interaction with Pact's development server & ScalableBFT Install go install github.com/jfamousket/go-pact@latest Functions H

Dec 9, 2021
Example ReSTFul Server in Golang - SBU-Snapp-School

students.go Introduction ReSTful API to create, update, retrieve and delete students from a datastore. Requests needs validation, package needs tests,

Sep 14, 2022
Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and traditional RESTful API.

Phalanx Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and tr

Dec 25, 2022