timeaverage

package module
v0.0.0-...-ccf62fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

README

timeaverage

Call a function which returns a float every X duration and keep history of N values and return average value of that window.

Install

go get -u github.com/raspi/timeaverage

Example

Take measurement every 500 ms and keep history of 10 seconds.

package main

import (
	"github.com/raspi/timeaverage"
    "log"
	"time"
)

func exampleSampler() (float64, error) {
	return 1, nil
}

func main() {
	avg := timeaverage.New(time.Second*10, time.Millisecond*500, 0.0, exampleSampler)
	avg.Start()

	for {
		v := avg.Average()
		log.Printf(`%f`, v)
		time.Sleep(time.Second * 1)
	}

}

See _examples directory for more examples.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeAverage

type TimeAverage struct {
	SampleCount uint // how many measurements in .measurements

	Newest time.Time // what's the newest entry in .measurements
	Oldest time.Time // what's the oldest entry in .measurements (usually .measurements[0].T)
	// contains filtered or unexported fields
}

func New

func New(timeWindow, rate time.Duration, initialavg float64, samplerFunc measurementFunc) *TimeAverage

func (*TimeAverage) Average

func (s *TimeAverage) Average() float64

func (*TimeAverage) Start

func (s *TimeAverage) Start()

func (*TimeAverage) Stop

func (s *TimeAverage) Stop()

Directories

Path Synopsis
_examples
cpu command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL