internal

package
v0.0.0-...-6a73ad5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Usage = `` /* 2393-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 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.Reader, 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 ParseTimestamp

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

ParseTimestamp with no location provided parses a timestamp value as UTC

func ParseTimestampWithLocation

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

ParseTimestamp parses a timestamp value as a unix epoch of various precision.

format = "unix": epoch is assumed to be in seconds and can come as number or string. Can have a decimal part. format = "unix_ms": epoch is assumed to be in milliseconds and can come as number or string. Cannot have a decimal part. format = "unix_us": epoch is assumed to be in microseconds and can come as number or string. Cannot have a decimal part. format = "unix_ns": epoch is assumed to be in nanoseconds and can come as number or string. Cannot have a decimal part.

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 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 Size

type Size struct {
	Size int64
}

Size just wraps an int64

func (*Size) UnmarshalTOML

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

Directories

Path Synopsis
aws

Jump to

Keyboard shortcuts

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