Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Releases: ContainerSSH/metrics

1.0.0: First stable release

01 Apr 14:05
Compare
Choose a tag to compare

This is the first tagged stable release for ContainerSSH 0.4.0.

0.9.8: Startup message

09 Mar 09:00
Compare
Choose a tag to compare
Pre-release

This release adds a log message at startup.

0.9.7: Better validation

08 Mar 22:20
Compare
Choose a tag to compare
Pre-release

This release adds better validation for the metrics server.

0.9.6: Fixed listen default

31 Dec 08:25
Compare
Choose a tag to compare
Pre-release

This release fixes a regression where the default listen value would be 0.0.0.0:8080 instead of 0.0.0.0:9100.

0.9.5: Added extended metrics

29 Dec 00:01
e923fd7
Compare
Choose a tag to compare
Pre-release

This release adds a WithLabel method to create metrics primed with certain labels. This can be used when passing labels between modules.

0.9.4: Add `Must*` methods

28 Dec 22:57
befe233
Compare
Choose a tag to compare
Pre-release

This release adds methods starting with Must that panic instead of throwing an error.

0.9.3: Custom label support

14 Dec 23:07
d4ccdf4
Compare
Choose a tag to compare
Pre-release

Each of the metric methods now allow adding extra labels:

testCounter.Increment(
    net.ParseIP("127.0.0.1"),
    metrics.Label("foo", "bar"),
    metrics.Label("somelabel","somevalue")
)

The following rules apply and will cause a panic if violated:

  • Label names and values cannot be empty.
  • The country label name is reserved for GeoIP usage.

0.9.2: Fixed JSON and YAML marshalling

10 Dec 23:49
0b7d33e
Compare
Choose a tag to compare
Pre-release

In the previous version the JSON and YAML configuration marshalling / unmarshalling created an unnecessary sub-map, which was incompatible to ContainerSSH 0.3. This release fixes that and restores compatibility.

0.9.1: Updating GeoIP to 0.9.3

05 Dec 11:45
e0eb998
Compare
Choose a tag to compare
Pre-release

This release updates the GeoIP dependency to version 0.9.3 for a cleaner API.

0.9.0: Initial Release

23 Nov 20:34
Compare
Choose a tag to compare
Pre-release

This is the initial release.

Collecting metrics

The core component of the metrics is the metrics.Collector interface. You can create a new instance of this interface by calling metrics.New() with a GeoIP lookup provider from the geoip library as a parameter. You can then dynamically create metrics:

m := metrics.New(geoip)
testCounter, err := m.CreateCounter(
    "test", // Name of the metric
    "MB", // Unit of the metric
    "This is a test", // Help text of the metric
)

You can then increment the counter:

testCounter.Increment()
testCounter.IncrementBy(5)

Alternatively, you can also create a CounterGeo to make a label automatically based on GeoIP lookup:

testCounter, err := m.CreateCounterGeo(
    "test", // Name of the metric
    "MB", // Unit of the metric
    "This is a test", // Help text of the metric
)
testCounter.Increment(net.ParseIP("127.0.0.1"))

If you need a metric that can be decremented or set directly you can use the Gauge type instead.

Using the metrics server

The metrics server exposes the collected metrics on an HTTP webserver in the Prometheus / OpenMetrics format. It requires the service library and a logger from the log library to work properly:

server := metrics.NewServer(
    metrics.Config{
        ServerConfiguration: http.ServerConfiguration{
            Listen:       "127.0.0.1:8080",
        },
        Enable:              true,
        Path:                "/metrics",
    },
    metricsCollector,
    logger,
)

lifecycle := service.NewLifecycle(server)
go func() {
    if err := lifecycle.Run(); err != nil {
        // Handle crash
    } 	
}()

//Later:
lifecycle.Stop(context.Background())

Alternatively, you can skip the full HTTP server and request a handler that you can embed in any Go HTTP server:

handler := metrics.NewHandler(
    "/metrics",
    metricsCollector
)
http.ListenAndServe("0.0.0.0:8080", handler)