A Go package providing a generic data type to track maximum and minimum peak values.

Go Reference MIT License

go-peak

Overview

go-peak is a Go package providing a generic data type that tracks the maximum and minimum peak values within a specific period of time.

Background

go-peak was originally designed for Prometheus monitoring to catch the peaks between scraping. For example, suppose the scraping interval is configured to one minute, and a Gauge metric spikes immediately after a scraping. If this Gauge value had dropped by the next scraping, that spike value would not be detected. If there are secondary metrics that report the maximum and/or minimum values for the last 1 minute, these peaks will be able to be detected.

Usage

import (
	"fmt"
	"time"

	"github.com/tunabay/go-peak"
)

func main() {
	// uint32 Value that tracks the maximum/minimum in last 1 sec, with the
	// initial value 1000.
	v := peak.New[uint32](time.Second, 1000)

	// Add, Sub, and Set change the value.
	time.Sleep(time.Second / 4) // [0.25s]
	v.Add(500)                  // [0.25s] 1500
	time.Sleep(time.Second / 4) // [0.50s]
	v.Sub(700)                  // [0.50s] 800
	time.Sleep(time.Second / 4) // [0.75s]
	v.Set(300)                  // [0.75s] 300
	time.Sleep(time.Second / 4) // [1.00s]

	// Get the current value and maximum/minimum values in last 1 sec.
	cur, min, max := v.Get()
	fmt.Printf("cur: %3v\n", cur)
	fmt.Printf("min: %3v\n", min)
	fmt.Printf("max: %3v\n", max)
}

Run in Go Playground

Limitation

  • It uses the new Go generics syntaxes and requires Go v1.18 or higher.
  • The detection period is not accurate. For example, a report for the last one second may contain a maximum value at 1.001 seconds ago. This is because not all individual changes are recorded, but at a resolution of about 1/128 to 1/256 of the reporting period.
Similar Resources

Vehicle Purchase on Exercism's Go Track

Vehicle Purchase Welcome to Vehicle Purchase on Exercism's Go Track. If you need help running the tests or submitting your code, check out HELP.md. If

Nov 30, 2021

Apachedist-resource - A concourse resource to track updates of an apache distribution, e.g. tomcat

Apache Distribution Resource A concourse resource that can track information abo

Feb 2, 2022

An exporter for bsport.io to track workouts sessions 💪

bsport-exporter An exporter for bsport. It is currently very basic and is supposed to be use to track how many bookings have been made in total: ➜ ~

Feb 22, 2022

A handy utility to generate configmap and values.yaml of your application for helmifying them

Helmfig Are you tired of writing values.yaml for configmap of your project when you are helmifying them? Helmfig is a handy tool that can generate the

Dec 14, 2022

A helm v3 plugin to get values from a previous release

helm-val helm-val is a helm plugin to fetch values from a previous release. Getting started Installation To install the plugin: $ helm plugin install

Dec 11, 2022

Render helm values-files from others

helm-plugin-render-values The Helm downloader plugin with rendering templated values files Install Use helm CLI to install this plugin: $ helm plugin

Aug 1, 2022

Drone conversion for platform values

drocopla A drone.io conversion extension to set host platform as drone pipeline platform. Default drone.io behaviour: If os/arch is not set in .drone.

Dec 1, 2021

Print specified values from desktop files to stdout.

Print specified values from desktop files to stdout.

dprint Print specified values from desktop files to stdout. Look, it’s hard to describe okay? Here’s a picture of me using it with dmenu. My launcher

Dec 22, 2021

MongoDB generic REST server in Go

MongoDB generic REST server in Go

Mora - Mongo Rest API REST server for accessing MongoDB documents and meta data Documents When querying on collections those parameters are available:

Dec 17, 2022
Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd data, and intelligent diagnosis.
Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd data, and intelligent diagnosis.

Kstone 中文 Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd

Dec 27, 2022
Provider-generic-workflows - A generic provider which uses argo workflows to define the backend actions.

provider-generic-workflows provider-generic-workflows is a generic provider which uses argo workflows for managing the external resource. This will re

Jan 1, 2022
An Oracle Cloud (OCI) Pulumi resource package, providing multi-language access to OCI

Oracle Cloud Infrastructure Resource Provider The Oracle Cloud Infrastructure (OCI) Resource Provider lets you manage OCI resources. Installing This p

Dec 2, 2022
🚢 Go package providing lifecycle management for PostgreSQL Docker instances.
🚢  Go package providing lifecycle management for PostgreSQL Docker instances.

?? psqldocker powered by ory/dockertest. Go package providing lifecycle management for PostgreSQL Docker instances. Leverage Docker to run unit and in

Sep 2, 2022
Kubei is a flexible Kubernetes runtime scanner, scanning images of worker and Kubernetes nodes providing accurate vulnerabilities assessment, for more information checkout:
Kubei is a flexible Kubernetes runtime scanner, scanning images of worker and Kubernetes nodes providing accurate vulnerabilities assessment, for more information checkout:

Kubei is a vulnerabilities scanning and CIS Docker benchmark tool that allows users to get an accurate and immediate risk assessment of their kubernet

Dec 30, 2022
Goal: Learn a Go plotting library and track my Electricity costs
Goal: Learn a Go plotting library and track my Electricity costs

Goal: Learn a Go plotting library and track my Electricity costs Findings https:

Jan 2, 2022
Package trn introduces a Range type with useful methods to perform complex operations over time ranges

Time Ranges Package trn introduces a Range type with useful methods to perform c

Aug 18, 2022
Testcontainers is a Golang library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.

When I was working on a Zipkin PR I discovered a nice Java library called Testcontainers. It provides an easy and clean API over the go docker sdk to

Jan 7, 2023
Go library providing algorithms optimized to leverage the characteristics of modern CPUs

asm Go library providing algorithms optimized to leverage the characteristics of modern CPUs. Motivation With the development of Cloud technologies, a

Dec 29, 2022
Kubernetes operator providing CRDs to interact with NETCONF servers.

NETCONF operator This operator is meant to provide support for: RFC6241 Network Configuration Protocol (NETCONF) RFC6242 Using the NETCONF Protocol ov

Nov 17, 2021