Giter VIP home page Giter VIP logo

influxus's Introduction

Influxus GoDoc

Golang Hook for the Logrus logging library, in order to output logs to InfluxDB.

Usage

Installation

go get github.com/vlad-doru/influxus

Example

import (
	"github.com/Sirupsen/logrus"
	"github.com/influxdata/influxdb/client/v2"
	"github.com/vlad-doru/influxus"
)

func init() {
	// Create the InfluxDB client.
	influxClient, err := client.NewHTTPClient(client.HTTPConfig{
		Addr: "http://localhost:8086",
	})
	if err != nil {
		logrus.Fatalf("Error while creating the client: %v", err)
	}
	// Create and add the hook.
	hook, err := influxus.NewHook(
		&influxus.Config{
			Client:             influxClient,
			Database:           "logrus", // DATABASE MUST BE CREATED
			DefaultMeasurement: "logrus",
			BatchSize:          1, // default is 100
			BatchInterval:      1, // default is 5 seconds
		})
	if err != nil {
		logrus.Fatalf("Error while creating the hook: %v", err)
	}
	// Add the hook to the standard logger.
	logrus.StandardLogger().Hooks.Add(hook)
}

Concepts

Concurrency

We use a non-blocking model for the hook. Each time an entry is fired, we create an InfluxDB point and put that through a buffered channel. It is then picked up by a worker goroutine that will handle the current batch and write everything once the batch hit the size or time limit.

Configuration

We chose to take in as a parameter the InfluxDB client so that we have greater flexibility over the way we connect to the Influx Server. All the defaults and configuration options can be found in the GoDoc.

Database Handling

The database should have been previously created. This is by design, as we want to avoid people generating lots of databases. When passing an empty string for the InfluxDB database name, we default to "logrus" as the database name.

Message Field

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

TODO

  • Concurrent, non-blocking design.
  • Add unit tests
  • Set up continous integration.

influxus's People

Contributors

vlad-doru avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.