Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
863cbe51
Commit
863cbe51
authored
8 years ago
by
Cameron Sparr
Browse files
Options
Downloads
Patches
Plain Diff
processes plugin: fix case where there are spaces in cmd name
fixes #968
parent
d871e9ae
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+7
-0
7 additions, 0 deletions
CHANGELOG.md
plugins/inputs/system/processes.go
+10
-3
10 additions, 3 deletions
plugins/inputs/system/processes.go
plugins/inputs/system/processes_test.go
+30
-0
30 additions, 0 deletions
plugins/inputs/system/processes_test.go
with
47 additions
and
3 deletions
CHANGELOG.md
+
7
−
0
View file @
863cbe51
## v0.12.1 [unreleased]
### Features
### Bugfixes
-
[
#968
](
https://github.com/influxdata/telegraf/issues/968
)
: Processes plugin gets unknown state when spaces are in (command name)
## v0.12.0 [2016-04-05]
### Features
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/processes.go
+
10
−
3
View file @
863cbe51
...
...
@@ -144,11 +144,18 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
continue
}
// Parse out data after (<cmd name>)
i
:=
bytes
.
LastIndex
(
data
,
[]
byte
(
")"
))
if
i
==
-
1
{
continue
}
data
=
data
[
i
+
2
:
]
stats
:=
bytes
.
Fields
(
data
)
if
len
(
stats
)
<
3
{
return
fmt
.
Errorf
(
"Something is terribly wrong with %s"
,
statFile
)
}
switch
stats
[
2
][
0
]
{
switch
stats
[
0
][
0
]
{
case
'R'
:
fields
[
"running"
]
=
fields
[
"running"
]
.
(
int64
)
+
int64
(
1
)
case
'S'
:
...
...
@@ -163,11 +170,11 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
fields
[
"paging"
]
=
fields
[
"paging"
]
.
(
int64
)
+
int64
(
1
)
default
:
log
.
Printf
(
"processes: Unknown state [ %s ] in file %s"
,
string
(
stats
[
2
][
0
]),
statFile
)
string
(
stats
[
0
][
0
]),
statFile
)
}
fields
[
"total"
]
=
fields
[
"total"
]
.
(
int64
)
+
int64
(
1
)
threads
,
err
:=
strconv
.
Atoi
(
string
(
stats
[
1
9
]))
threads
,
err
:=
strconv
.
Atoi
(
string
(
stats
[
1
7
]))
if
err
!=
nil
{
log
.
Printf
(
"processes: Error parsing thread count: %s"
,
err
)
continue
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/processes_test.go
+
30
−
0
View file @
863cbe51
...
...
@@ -82,6 +82,28 @@ func TestFromProcFiles(t *testing.T) {
acc
.
AssertContainsTaggedFields
(
t
,
"processes"
,
fields
,
map
[
string
]
string
{})
}
func
TestFromProcFilesWithSpaceInCmd
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
!=
"linux"
{
t
.
Skip
(
"This test only runs on linux"
)
}
tester
:=
tester
{}
processes
:=
&
Processes
{
readProcFile
:
tester
.
testProcFile2
,
forceProc
:
true
,
}
var
acc
testutil
.
Accumulator
err
:=
processes
.
Gather
(
&
acc
)
require
.
NoError
(
t
,
err
)
fields
:=
getEmptyFields
()
fields
[
"sleeping"
]
=
tester
.
calls
fields
[
"total_threads"
]
=
tester
.
calls
*
2
fields
[
"total"
]
=
tester
.
calls
acc
.
AssertContainsTaggedFields
(
t
,
"processes"
,
fields
,
map
[
string
]
string
{})
}
func
testExecPS
()
([]
byte
,
error
)
{
return
[]
byte
(
testPSOut
),
nil
}
...
...
@@ -96,6 +118,11 @@ func (t *tester) testProcFile(_ string) ([]byte, error) {
return
[]
byte
(
fmt
.
Sprintf
(
testProcStat
,
"S"
,
"2"
)),
nil
}
func
(
t
*
tester
)
testProcFile2
(
_
string
)
([]
byte
,
error
)
{
t
.
calls
++
return
[]
byte
(
fmt
.
Sprintf
(
testProcStat2
,
"S"
,
"2"
)),
nil
}
func
testExecPSError
()
([]
byte
,
error
)
{
return
[]
byte
(
testPSOut
),
fmt
.
Errorf
(
"ERROR!"
)
}
...
...
@@ -149,3 +176,6 @@ S+
const
testProcStat
=
`10 (rcuob/0) %s 2 0 0 0 -1 2129984 0 0 0 0 0 0 0 0 20 0 %s 0 11 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 18446744073709551615 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0
`
const
testProcStat2
=
`10 (rcuob 0) %s 2 0 0 0 -1 2129984 0 0 0 0 0 0 0 0 20 0 %s 0 11 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 18446744073709551615 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0
`
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment