Categorygithub.com/tommzn/go-metrics
modulepackage
1.0.1
Repository: https://github.com/tommzn/go-metrics.git
Documentation: pkg.go.dev

# README

Go Reference GitHub go.mod Go version GitHub release (latest by date) Go Report Card Actions Status

Timestream DB Client

Client to import measurements to timestream databases.

Supported Databases/Services

  • AWS Timestream

AWS Timestream

Run NewTimestreamPublisher to create a new client for AWS Timestream. You've to pass a config which defines region, database, table name and batch size. If you don't pass a logger a new stdout logger will be created. See https://github.com/tommzn/go-log for more details about used logger.

package main

import (
    "fmt"

    metrics "github.com/tommzn/go-metrics"
    config "github.com/tommzn/go-config"
)

func main() {

    // Assumes a config.yml file in current folter.
    conf, err := config.NewConfigSource().Load()
    if err != nil {
        panic(err)
    }
    publisher := metrics.NewTimestreamPublisher(conf. nil)
    measurement := Measurement{
		MetricName: "test-metric",
		Tags: []MeasurementTag{MeasurementTag{
			Name:  "host",
			Value: "ip-10.0.1.12",
		}},
		Values: []MeasurementValue{MeasurementValue{
			Name:  "load",
			Value: 0.53,
		}},
	}

    // If batch size is not set or 0 this will directly import passed measurement to AWS Timestream.
    publisher.Send(measurement)
    // To ensure import of a aavailable measurements you've to flush the publisher.
    publisher.Flush()

    // Any errors that occur when importing measurements are collected.
    if err := publisher.Error(); err != nil {
        fmt.Println(err)
    }
}

Config

Following examples show a config with all available values.

aws:
  timestream:
    awsregion: eu-west-1
    database: timestream-db
    table: data
    batch_size: 10

AWS Credentials

Credentials for AWS access have to be setup separately as described in AWS SDK Docs.

# Functions

NewTimestreamPublisher returns a new metrics publisher for AWS Timestream.

# Structs

Measurement a single metrics which should be imported to a timestream database.
MeasurementTag is a key/value apir for additional metric information.
MeasurementValue is a single, named value which can be imported to a timestream database.
TimestreamPublisher can be used to import metics to AWS Timestream.

# Interfaces

Publisher is used to import metrics to different timesteam databases.