exec

package
v0.0.0-...-bdb06d8 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2018 License: MIT Imports: 15 Imported by: 0

README

Exec Input Plugin

The exec plugin executes the commands on every interval and parses metrics from their output in any one of the accepted Input Data Formats.

This plugin can be used to poll for custom metrics from any source.

Configuration:
[[inputs.exec]]
  ## Commands array
  commands = [
    "/tmp/test.sh",
    "/usr/bin/mycollector --foo=bar",
    "/tmp/collect_*.sh"
  ]

  ## Timeout for each command to complete.
  timeout = "5s"

  ## measurement name suffix (for separating different commands)
  name_suffix = "_mycollector"

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/digbrand1977/tinymonitor/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "influx"

Glob patterns in the command option are matched on every run, so adding new scripts that match the pattern will cause them to be picked up immediately.

Example:

This script produces static values, since no timestamp is specified the values are at the current time.

#!/bin/sh
echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i'

It can be paired with the following configuration and will be ran at the interval of the agent.

[[inputs.exec]]
  commands = ["sh /tmp/test.sh"]
  timeout = "5s"
  data_format = "influx"
Common Issues:
Q: My script works when I run it by hand, but not when Telegraf is running as a service.

This may be related to the Telegraf service running as a different user. The official packages run Telegraf as the telegraf user and group on Linux systems.

Documentation

Index

Constants

View Source
const MaxStderrBytes = 512

Variables

This section is empty.

Functions

func AddNagiosState

func AddNagiosState(exitCode error, acc tinymonitor.Accumulator) error

Types

type CommandRunner

type CommandRunner struct{}

func (CommandRunner) Run

func (c CommandRunner) Run(
	e *Exec,
	command string,
	acc tinymonitor.Accumulator,
) ([]byte, error)

type Exec

type Exec struct {
	Commands []string
	Command  string
	Timeout  itscripts.Duration
	// contains filtered or unexported fields
}

func NewExec

func NewExec() *Exec

func (*Exec) Description

func (e *Exec) Description() string

func (*Exec) Gather

func (e *Exec) Gather(acc tinymonitor.Accumulator) error

func (*Exec) ProcessCommand

func (e *Exec) ProcessCommand(command string, acc tinymonitor.Accumulator, wg *sync.WaitGroup)

func (*Exec) SampleConfig

func (e *Exec) SampleConfig() string

func (*Exec) SetParser

func (e *Exec) SetParser(parser parsers.Parser)

type Runner

type Runner interface {
	Run(*Exec, string, tinymonitor.Accumulator) ([]byte, error)
}

Jump to

Keyboard shortcuts

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