execd

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: MIT Imports: 14 Imported by: 0

README

Execd Input Plugin

The execd plugin runs an external program as a long-running daemon. The programs must output metrics in any one of the accepted Input Data Formats on the process's STDOUT, and is expected to stay running. If you'd instead like the process to collect metrics and then exit, check out the inputs.exec plugin.

The signal can be configured to send a signal the running daemon on each collection interval. This is used for when you want to have Telegraf notify the plugin when it's time to run collection. STDIN is recommended, which writes a new line to the process's STDIN.

STDERR from the process will be relayed to Telegraf as errors in the logs.

Configuration:
[[inputs.execd]]
  ## One program to run as daemon.
  ## NOTE: process and each argument should each be their own string
  command = ["telegraf-smartctl", "-d", "/dev/sda"]

  ## Define how the process is signaled on each collection interval.
  ## Valid values are:
  ##   "none"    : Do not signal anything. (Recommended for service inputs)
  ##               The process must output metrics by itself.
  ##   "STDIN"   : Send a newline on STDIN. (Recommended for gather inputs)
  ##   "SIGHUP"  : Send a HUP signal. Not available on Windows. (not recommended)
  ##   "SIGUSR1" : Send a USR1 signal. Not available on Windows.
  ##   "SIGUSR2" : Send a USR2 signal. Not available on Windows.
  signal = "none"

  ## Delay before the process is restarted after an unexpected termination
  restart_delay = "10s"

  ## Data format to consume.
  ## 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_INPUT.md
  data_format = "influx"
Example
Daemon written in bash using STDIN signaling
#!/bin/bash

counter=0

while IFS= read -r LINE; do
    echo "counter_bash count=${counter}"
    let counter=counter+1
done
[[inputs.execd]]
  command = ["plugins/inputs/execd/examples/count.sh"]
  signal = "STDIN"
Go daemon using SIGHUP
package main

import (
    "fmt"
    "os"
    "os/signal"
    "syscall"
)

func main() {
    c := make(chan os.Signal, 1)
    signal.Notify(c, syscall.SIGHUP)

    counter := 0

    for {
        <-c

        fmt.Printf("counter_go count=%d\n", counter)
        counter++
    }
}

[[inputs.execd]]
  command = ["plugins/inputs/execd/examples/count.go.exe"]
  signal = "SIGHUP"
Ruby daemon running standalone
#!/usr/bin/env ruby

counter = 0

loop do
  puts "counter_ruby count=#{counter}"
  STDOUT.flush

  counter += 1
  sleep 1
end
[[inputs.execd]]
  command = ["plugins/inputs/execd/examples/count.rb"]
  signal = "none"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Execd

type Execd struct {
	Command      []string        `toml:"command"`
	Signal       string          `toml:"signal"`
	RestartDelay config.Duration `toml:"restart_delay"`
	Log          telegraf.Logger `toml:"-"`
	// contains filtered or unexported fields
}

func (*Execd) Description

func (e *Execd) Description() string

func (*Execd) Gather

func (e *Execd) Gather(acc telegraf.Accumulator) error

func (*Execd) Init added in v1.15.0

func (e *Execd) Init() error

func (*Execd) SampleConfig

func (e *Execd) SampleConfig() string

func (*Execd) SetParser

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

func (*Execd) Start

func (e *Execd) Start(acc telegraf.Accumulator) error

func (*Execd) Stop

func (e *Execd) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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