expvar

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 6 Imported by: 1

README

component-expvar - Settings component for sending expvar metrics

GoDoc

Bugs Code Smells Coverage Lines of Code Maintainability Rating Quality Gate Status Reliability Rating Security Rating Technical Debt Vulnerabilities

Overview

This is a settings that enables sending metrics for the values usually provided through the Expvar HTTP endpoints. We have extended the set of metrics to also include the current goroutine count.

Quick Start

package main

import (
    "context"
    "net/http"

    stat "github.com/asecurityteam/component-stat"
    expvar "github.com/asecurityteam/component-expvar"
    "github.com/asecurityteam/settings/v2"
)

func main() {
    ctx := context.Background()
    envSource := settings.NewEnvSource(os.Environ())

    s, _ := stat.New(ctx, envSource)
    exp, _ := expvar.Load(ctx, envSource, expvar.NewComponent().WithStat(s))
    defer exp.Close()
    go exp.Report()
}

Status

This project is in incubation which means we are not yet operating this tool in production and the interfaces are subject to change.

Contributing

Building And Testing

We publish a docker image called SDCLI that bundles all of our build dependencies. It is used by the included Makefile to help make building and testing a bit easier. The following actions are available through the Makefile:

  • make dep

    Install the project dependencies into a vendor directory

  • make lint

    Run our static analysis suite

  • make test

    Run unit tests and generate a coverage artifact

  • make integration

    Run integration tests and generate a coverage artifact

  • make coverage

    Report the combined coverage for unit and integration tests

License

This project is licensed under Apache 2.0. See LICENSE.txt for details.

Contributing Agreement

Atlassian requires signing a contributor's agreement before we can accept a patch. If you are an individual you can fill out the individual CLA. If you are contributing on behalf of your company then please fill out the corporate CLA.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	Stat stat.Stat
}

Component implements the settings.Component interface for expvar metrics.

func NewComponent

func NewComponent() *Component

NewComponent generates a blank component instance.

func (*Component) New

func (c *Component) New(_ context.Context, conf *Config) (*Expvar, error)

New produces a ServerFn bound to the given configuration.

func (*Component) Settings

func (*Component) Settings() *Config

Settings returns a configuration with all defaults set.

func (*Component) WithStat

func (c *Component) WithStat(s stat.Stat) *Component

WithStat returns a copy of the component bound to the given Stat instance.

type Config

type Config struct {
	Alloc            string        `description:"Name of the metric tracking allocated bytes"`
	Frees            string        `description:"Name of the metric tracking number of frees"`
	HeapAlloc        string        `description:"Name of the metric tracking allocated bytes"`
	HeapIdle         string        `description:"Name of the metric tracking bytes in unused spans"`
	HeapInuse        string        `description:"Name of the metric tracking bytes in in-use spans"`
	HeapObjects      string        `description:"Name of the metric tracking total number of object allocated"`
	HeapReleased     string        `description:"Name of the metric tracking bytes realeased to the OS"`
	HeapSys          string        `description:"Name of the metric tracking bytes obtained from the system"`
	Lookups          string        `description:"Name of the metric tracking number of pointer lookups"`
	Mallocs          string        `description:"Name of the metric tracking number of mallocs"`
	NumGC            string        `description:"Name of the metric tracking number of garbage collections"`
	PauseNS          string        `description:"Name of the metric tracking duration of GC pauses"`
	PauseTotalNS     string        `description:"Name of the metric tracking total GC pause duration over lifetime process"`
	TotalAlloc       string        `description:"Name of the metric tracking allocated bytes (even if freed)"`
	GoroutinesExists string        `description:"Name of the metric tracking number of active go routines"`
	ReportInterval   time.Duration `description:"Interval on which metrics are reported."`
}

Config is a container for internal expvar metrics settings.

func (*Config) Description

func (*Config) Description() string

Description returns the help information for the configuration root.

func (*Config) Name

func (*Config) Name() string

Name of the configuration root.

type Expvar

type Expvar struct {
	Stat                     stat.Stat
	MemstatsAllocName        string
	MemstatsFreesName        string
	MemstatsHeapAllocName    string
	MemstatsHeapIdleName     string
	MemstatsHeapInuseName    string
	MemstatsHeapObjectsName  string
	MemstatsHeapReleasedName string
	MemstatsHeapSysName      string
	MemstatsLookupsName      string
	MemstatsMallocsName      string
	MemstatsNumGCName        string
	MemstatsPauseNSName      string
	MemstatsPauseTotalNSName string
	MemstatsTotalAllocName   string
	GoroutinesExistsName     string
	Interval                 time.Duration
	// contains filtered or unexported fields
}

Expvar tracks the memory usage of the Go runtime and collects metrics instrumented from Go’s expvar package

func Load

func Load(ctx context.Context, source settings.Source, c *Component) (*Expvar, error)

Load is a convenience method for binding the source to the component.

func (*Expvar) Close

func (e *Expvar) Close() error

Close the reporting loop.

func (*Expvar) Report

func (e *Expvar) Report()

Report loops on a time interval and pushes a set of gauge metrics.

Jump to

Keyboard shortcuts

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