Giter Site home page Giter Site logo

telegraf.serializers.template's Introduction

Telegraf 模板输出数据格式

最新文档请移步: 中文文档

让 Telegraf 的输出格式支持GO模板(text/template):

安装

  1. 安装Telegraf
go get -d github.com/influxdata/telegraf
  1. 下载插件源码
go get github.com/liuhengloveyou/telegraf.serializers.template
  1. 注册插件到Telegraf

这里要吐槽一下Telegraf,插件注册做得不方便,需要改Telegraf源码:$GOPATH/src/github.com/influxdata/telegraf/plugins/serializers/registry.go

// import插件源码
import (
	... ...
	"github.com/influxdata/telegraf/plugins/serializers/json"
	template "github.com/liuhengloveyou/telegraf.serializers.template"
)

// 注册插件
func NewSerializer(config *Config) (Serializer, error) {
	var err error
	var serializer Serializer
	switch config.DataFormat {
	case "influx":
		serializer, err = NewInfluxSerializer()
	case "graphite":
		serializer, err = NewGraphiteSerializer(config.Prefix, config.Template)
	case "json":
		serializer, err = NewJsonSerializer(config.TimestampUnits)
	case "template":
		serializer, err = template.NewTemplateSerializer(config.Template)
	default:
		err = fmt.Errorf("Invalid data format: %s", config.DataFormat)
	}
	return serializer, err
}

配置

[[outputs.file]]
  ## Files to write to, "stdout" is a specially handled file.
  files = ["stdout"]

  ## Data format to output.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
  data_format = "template"
  ## template (text/template)
  ## 例如nginx:
  ##log_format main '$time_iso8601 $server_name $remote_addr "$request" '
  ##  '$status $body_bytes_sent $request_time "$http_referer" '
  ##  '"$http_user_agent" "$http_x_forwarded_for"';
  template = "{{.time}} {{.server_name}} {{.client_ip}} \"{{.request}}\" {{.resp_code}} {{.resp_bytes}} {{printf \"%.3f\" .request_time}} \"{{.referer}}\" {{.user_agent}} \"{{.x_forwarded_for}}\"\n"
  

telegraf.serializers.template's People

Contributors

liuhengloveyou avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

john1688

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.