gometrics

package
v0.0.0-...-cb2e5be Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoMetrics

type GoMetrics struct {
	Dimensions []*cloudwatch.Dimension
	Namespace  string
	OnError    func(error)

	CollectTotalAlloc    bool
	CollectSys           bool
	CollectLookups       bool
	CollectMallocs       bool
	CollectFrees         bool
	CollectHeapAlloc     bool
	CollectHeapSys       bool
	CollectHeapIdle      bool
	CollectHeapInuse     bool
	CollectHeapReleased  bool
	CollectHeapObjects   bool
	CollectStackInuse    bool
	CollectStackSys      bool
	CollectMSpanInuse    bool
	CollectMSpanSys      bool
	CollectMCacheInuse   bool
	CollectMCacheSys     bool
	CollectBuckHashSys   bool
	CollectGCSys         bool
	CollectNextGC        bool
	CollectLastGC        bool
	CollectPauseTotalNs  bool
	CollectNumGC         bool
	CollectNumForcedGC   bool
	CollectGCCPUFraction bool
	CollectNumGoroutine  bool
	// contains filtered or unexported fields
}

func New

New creates collector of go metrics. Upon creation enable required metrics by toggling appropriate GoMetrics.Collect* fields.

Example
package main

import (
	"context"
	"time"

	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/molecule-man/cwatsch/gometrics"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	go func() {
		m := gometrics.New(session.Must(session.NewSession()))
		m.Namespace = "MyApp"
		m.CollectHeapAlloc = true
		m.CollectNextGC = true       // target heap size of the next GC cycle
		m.CollectStackInuse = true   // bytes in stack spans.
		m.CollectPauseTotalNs = true // cumulative nanoseconds in GC stop-the-world pauses since the program started.
		m.CollectNumGC = true        // number of completed GC cycles.
		m.CollectHeapObjects = true  // number of allocated heap objects.
		m.CollectNumGoroutine = true

		// the metrics will be collected every minute
		m.Launch(ctx, time.Minute)
	}()
}
Output:

func (*GoMetrics) Launch

func (m *GoMetrics) Launch(ctx context.Context, interval time.Duration)

Launch starts metric collection which is executed periodically in intervals specified by the the second argument.

Jump to

Keyboard shortcuts

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