fluxrus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: MIT Imports: 5 Imported by: 0

README

fluxrus

logrus hook for InfluxDB

usage

Installation
go get github.com/HeavyHorst/fluxrus
Example
import (
    "github.com/HeavyHorst/fluxrus"
	"github.com/Sirupsen/logrus"
)

func main() {
    log := logrus.New()
	hook, err := fluxrus.New("http://influxdbhost:8086", "mydb", "my_measurement", fluxrus.WithBatchSize(2000), fluxrus.WithTags([]string{"mytag"}))
	if err == nil {
		log.Hooks.Add(hook)
	}
	defer hook.Close()
}

Details

Buffer

All log messages are buffered by default to increase the performance. You need to run hook.Close() on program exit to get sure that all messages are written to the database.

Configuration

The constructor takes some optional configuration options:

  1. WithBatchInterval(int): flush the buffer at the given interval in seconds. (default is 5s)
  2. WithBatchSize(int): Max size of the buffer. The buffer gets flushed to the db if this threshold is reached. (default is 200)
  3. WithPrecision(string): Sets the timestamp precision. (default is ns)
  4. WithTags([]string): Use some logrus fields as influxdb tags instead of influxdb fields.
  5. WithClient(influx.Client): A custom influxdb client.
Message Field

We will insert your message into InfluxDB with the field message.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InfluxHook

type InfluxHook struct {
	// contains filtered or unexported fields
}

func New

func New(url, db, measurement string, opts ...Option) (*InfluxHook, error)

func (*InfluxHook) Close

func (h *InfluxHook) Close()

func (*InfluxHook) Fire

func (h *InfluxHook) Fire(entry *logrus.Entry) error

func (*InfluxHook) Levels

func (h *InfluxHook) Levels() []logrus.Level

Levels implementation allows for level logging.

type Option

type Option func(*InfluxHook)

Option configures the Hook

func CreateDBIfNotExist

func CreateDBIfNotExist() Option

func WithBatchInterval

func WithBatchInterval(interval int) Option

WithBatchInterval sets the batchInterval

func WithBatchSize

func WithBatchSize(count int) Option

WithBatchSize sets the batchSize

func WithClient

func WithClient(c influx.Client) Option

WithClient overwrites the default influx.Client

func WithPrecision

func WithPrecision(p string) Option

WithPrecision sets the precision

func WithTags

func WithTags(t []string) Option

WithTags sets the tags that we will extract from the log fields

Jump to

Keyboard shortcuts

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