internal

package
v0.0.0-...-16a0e24 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const KillGrace = 5 * time.Second

KillGrace is the amount of time we allow a process to shutdown before sending a SIGKILL.

View Source
const Usage = `` /* 2834-byte string literal not displayed */

Variables

View Source
var (
	TimeoutErr = errors.New("Command timed out.")

	NotImplementedError = errors.New("not implemented yet")

	VersionAlreadySetError = errors.New("version has already been set")
)

Functions

func AlignDuration

func AlignDuration(tm time.Time, interval time.Duration) time.Duration

AlignDuration returns the duration until next aligned interval. If the current time is aligned a 0 duration is returned.

func AlignTime

func AlignTime(tm time.Time, interval time.Duration) time.Time

AlignTime returns the time of the next aligned interval. If the current time is aligned the current time is returned.

func AuthHandler

func AuthHandler(username, password, realm string, onError BasicAuthErrorFunc) func(h http.Handler) http.Handler

AuthHandler returns a http handler that requires HTTP basic auth credentials to match the given username and password.

func CombinedOutputTimeout

func CombinedOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error)

CombinedOutputTimeout runs the given command with the given timeout and returns the combined output of stdout and stderr. If the command times out, it attempts to kill the process.

func CompressWithGzip

func CompressWithGzip(data io.Reader) (io.ReadCloser, error)

CompressWithGzip takes an io.Reader as input and pipes it through a gzip.Writer returning an io.Reader containing the gzipped data. An error is returned if passing data to the gzip.Writer fails

func ExitStatus

func ExitStatus(err error) (int, bool)

Exit status takes the error from exec.Command and returns the exit status and true if error is not exit status, will return 0 and false

func IPRangeHandler

func IPRangeHandler(network []*net.IPNet, onError ErrorFunc) func(h http.Handler) http.Handler

IPRangeHandler returns a http handler that requires the remote address to be in the specified network.

func NewGzipReader

func NewGzipReader(r io.Reader) (io.Reader, error)

func NewStreamContentDecoder

func NewStreamContentDecoder(encoding string, r io.Reader) (io.Reader, error)

NewStreamContentDecoder returns a reader that will decode the stream according to the encoding type.

func OnClientError

func OnClientError(client *http.Client, err error)

func ParseTimestamp

func ParseTimestamp(format string, timestamp interface{}, location string) (time.Time, error)

ParseTimestamp parses a Time according to the standard Telegraf options. These are generally displayed in the toml similar to:

json_time_key= "timestamp"
json_time_format = "2006-01-02T15:04:05Z07:00"
json_timezone = "America/Los_Angeles"

The format can be one of "unix", "unix_ms", "unix_us", "unix_ns", or a Go time layout suitable for time.Parse.

When using the "unix" format, a optional fractional component is allowed. Specific unix time precisions cannot have a fractional component.

Unix times may be an int64, float64, or string. When using a Go format string the timestamp must be a string.

The location is a location string suitable for time.LoadLocation. Unix times do not use the location string, a unix time is always return in the UTC location.

func ProductToken

func ProductToken() string

ProductToken returns a tag for Telegraf that can be used in user agents.

func RandomDuration

func RandomDuration(max time.Duration) time.Duration

RandomDuration returns a random duration between 0 and max.

func RandomSleep

func RandomSleep(max time.Duration, shutdown chan struct{})

RandomSleep will sleep for a random amount of time up to max. If the shutdown channel is closed, it will return before it has finished sleeping.

func RandomString

func RandomString(n int) string

RandomString returns a random string of alpha-numeric characters

func ReadLines

func ReadLines(filename string) ([]string, error)

ReadLines reads contents from a file and splits them by new lines. A convenience wrapper to ReadLinesOffsetN(filename, 0, -1).

func ReadLinesOffsetN

func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error)

ReadLines reads contents from file and splits them by new line. The offset tells at which line number to start. The count determines the number of lines to read (starting from offset):

n >= 0: at most n lines
n < 0: whole file

func RunTimeout

func RunTimeout(c *exec.Cmd, timeout time.Duration) error

RunTimeout runs the given command with the given timeout. If the command times out, it attempts to kill the process.

func SetVersion

func SetVersion(v string) error

SetVersion sets the telegraf agent version

func SleepContext

func SleepContext(ctx context.Context, duration time.Duration) error

SleepContext sleeps until the context is closed or the duration is reached.

func SnakeCase

func SnakeCase(in string) string

SnakeCase converts the given string to snake case following the Golang format: acronyms are converted to lower-case and preceded by an underscore.

func Version

func Version() string

Version returns the telegraf agent version

func WaitTimeout

func WaitTimeout(c *exec.Cmd, timeout time.Duration) error

WaitTimeout waits for the given command to finish with a timeout. It assumes the command has already been started. If the command times out, it attempts to kill the process.

Types

type BasicAuthErrorFunc

type BasicAuthErrorFunc func(rw http.ResponseWriter)

type ContentDecoder

type ContentDecoder interface {
	Decode([]byte) ([]byte, error)
}

ContentDecoder removes a wrapper encoding from byte buffers.

func NewContentDecoder

func NewContentDecoder(encoding string) (ContentDecoder, error)

NewContentDecoder returns a ContentDecoder for the encoding type.

type ContentEncoder

type ContentEncoder interface {
	Encode([]byte) ([]byte, error)
}

ContentEncoder applies a wrapper encoding to byte buffers.

func NewContentEncoder

func NewContentEncoder(encoding string) (ContentEncoder, error)

NewContentEncoder returns a ContentEncoder for the encoding type.

type Duration

type Duration struct {
	Duration time.Duration
}

Duration just wraps time.Duration

func (*Duration) UnmarshalTOML

func (d *Duration) UnmarshalTOML(b []byte) error

UnmarshalTOML parses the duration from the TOML config file

type ErrorFunc

type ErrorFunc func(rw http.ResponseWriter, code int)

ErrorFunc is a callback for writing an error response.

type GzipDecoder

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

GzipDecoder decompresses buffers with gzip compression.

func NewGzipDecoder

func NewGzipDecoder() (*GzipDecoder, error)

func (*GzipDecoder) Decode

func (d *GzipDecoder) Decode(data []byte) ([]byte, error)

type GzipEncoder

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

GzipEncoder compresses the buffer using gzip at the default level.

func NewGzipEncoder

func NewGzipEncoder() (*GzipEncoder, error)

func (*GzipEncoder) Encode

func (e *GzipEncoder) Encode(data []byte) ([]byte, error)

type GzipReader

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

GzipReader is similar to gzip.Reader but reads only a single gzip stream per read.

func (*GzipReader) Read

func (r *GzipReader) Read(b []byte) (int, error)

type IdentityDecoder

type IdentityDecoder struct{}

IdentityDecoder is a null decoder that returns the input.

func NewIdentityDecoder

func NewIdentityDecoder() *IdentityDecoder

func (*IdentityDecoder) Decode

func (*IdentityDecoder) Decode(data []byte) ([]byte, error)

type IdentityEncoder

type IdentityEncoder struct{}

IdentityEncoder is a null encoder that applies no transformation.

func NewIdentityEncoder

func NewIdentityEncoder() *IdentityEncoder

func (*IdentityEncoder) Encode

func (*IdentityEncoder) Encode(data []byte) ([]byte, error)

type Number

type Number struct {
	Value float64
}

func (*Number) UnmarshalTOML

func (n *Number) UnmarshalTOML(b []byte) error

type ReadWaitCloser

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

func (*ReadWaitCloser) Close

func (r *ReadWaitCloser) Close() error

type Size

type Size struct {
	Size int64
}

Size just wraps an int64

func (*Size) UnmarshalTOML

func (s *Size) UnmarshalTOML(b []byte) error

Directories

Path Synopsis
Package choice provides basic functions for working with plugin options that must be one of several values.
Package choice provides basic functions for working with plugin options that must be one of several values.

Jump to

Keyboard shortcuts

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