Document and add support to input plugins for logging alias (#6357)

This commit is contained in:
Greg
2019-09-23 16:39:50 -06:00
committed by Daniel Nelson
parent e42d2e39c6
commit 817c9a69a9
111 changed files with 961 additions and 659 deletions

View File

@@ -6,7 +6,6 @@ import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
@@ -23,6 +22,8 @@ type Processes struct {
execPS func() ([]byte, error)
readProcFile func(filename string) ([]byte, error)
Log telegraf.Logger
forcePS bool
forceProc bool
}
@@ -124,8 +125,7 @@ func (p *Processes) gatherFromPS(fields map[string]interface{}) error {
case '?':
fields["unknown"] = fields["unknown"].(int64) + int64(1)
default:
log.Printf("I! processes: Unknown state [ %s ] from ps",
string(status[0]))
p.Log.Infof("Unknown state %q from ps", string(status[0]))
}
fields["total"] = fields["total"].(int64) + int64(1)
}
@@ -184,14 +184,13 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
}
fields["parked"] = int64(1)
default:
log.Printf("I! processes: Unknown state [ %s ] in file %s",
string(stats[0][0]), filename)
p.Log.Infof("Unknown state %q in file %q", string(stats[0][0]), filename)
}
fields["total"] = fields["total"].(int64) + int64(1)
threads, err := strconv.Atoi(string(stats[17]))
if err != nil {
log.Printf("I! processes: Error parsing thread count: %s", err)
p.Log.Infof("Error parsing thread count: %s", err.Error())
continue
}
fields["total_threads"] = fields["total_threads"].(int64) + int64(threads)

View File

@@ -16,6 +16,7 @@ import (
func TestProcesses(t *testing.T) {
processes := &Processes{
Log: testutil.Logger{},
execPS: execPS,
readProcFile: readProcFile,
}
@@ -35,6 +36,7 @@ func TestProcesses(t *testing.T) {
func TestFromPS(t *testing.T) {
processes := &Processes{
Log: testutil.Logger{},
execPS: testExecPS,
forcePS: true,
}
@@ -56,6 +58,7 @@ func TestFromPS(t *testing.T) {
func TestFromPSError(t *testing.T) {
processes := &Processes{
Log: testutil.Logger{},
execPS: testExecPSError,
forcePS: true,
}
@@ -71,6 +74,7 @@ func TestFromProcFiles(t *testing.T) {
}
tester := tester{}
processes := &Processes{
Log: testutil.Logger{},
readProcFile: tester.testProcFile,
forceProc: true,
}
@@ -93,6 +97,7 @@ func TestFromProcFilesWithSpaceInCmd(t *testing.T) {
}
tester := tester{}
processes := &Processes{
Log: testutil.Logger{},
readProcFile: tester.testProcFile2,
forceProc: true,
}
@@ -120,6 +125,7 @@ func TestParkedProcess(t *testing.T) {
procstat := `88 (watchdog/13) P 2 0 0 0 -1 69238848 0 0 0 0 0 0 0 0 20 0 1 0 20 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 1 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0
`
plugin := &Processes{
Log: testutil.Logger{},
readProcFile: func(string) ([]byte, error) {
return []byte(procstat), nil
},