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
a3623525
Commit
a3623525
authored
8 years ago
by
Cameron Sparr
Browse files
Options
Downloads
Patches
Plain Diff
Use glob match for finding /proc/<pid>/stat files
closes #1323
parent
94f95278
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+2
-1
2 additions, 1 deletion
CHANGELOG.md
plugins/inputs/system/processes.go
+13
-22
13 additions, 22 deletions
plugins/inputs/system/processes.go
with
15 additions
and
23 deletions
CHANGELOG.md
+
2
−
1
View file @
a3623525
...
...
@@ -22,7 +22,7 @@ in conjunction with wildcard dimension values as it will control the amount of
time before a new metric is included by the plugin.
### Features
-
[
#1262
](
https://github.com/influxdata/telegraf/pull/1261
)
: Add graylog input pluging.
-
[
#1262
](
https://github.com/influxdata/telegraf/pull/1261
)
: Add graylog input pluging.
-
[
#1294
](
https://github.com/influxdata/telegraf/pull/1294
)
: consul input plugin. Thanks @harnash
-
[
#1164
](
https://github.com/influxdata/telegraf/pull/1164
)
: conntrack input plugin. Thanks @robinpercy!
-
[
#1165
](
https://github.com/influxdata/telegraf/pull/1165
)
: vmstat input plugin. Thanks @jshim-xm!
...
...
@@ -48,6 +48,7 @@ time before a new metric is included by the plugin.
-
[
#1283
](
https://github.com/influxdata/telegraf/pull/1283
)
: Still send processes metrics if a process exited during metric collection.
-
[
#1297
](
https://github.com/influxdata/telegraf/issues/1297
)
: disk plugin panic when usage grab fails.
-
[
#1316
](
https://github.com/influxdata/telegraf/pull/1316
)
: Removed leaked "database" tag on redis metrics. Thanks @PierreF!
-
[
#1323
](
https://github.com/influxdata/telegraf/issues/1323
)
: Processes plugin: fix potential error with /proc/net/stat directory.
## v0.13.1 [2016-05-24]
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/processes.go
+
13
−
22
View file @
a3623525
...
...
@@ -9,7 +9,7 @@ import (
"log"
"os"
"os/exec"
"path"
"path
/filepath
"
"runtime"
"strconv"
...
...
@@ -19,7 +19,7 @@ import (
type
Processes
struct
{
execPS
func
()
([]
byte
,
error
)
readProcFile
func
(
statFil
e
string
)
([]
byte
,
error
)
readProcFile
func
(
filenam
e
string
)
([]
byte
,
error
)
forcePS
bool
forceProc
bool
...
...
@@ -128,22 +128,16 @@ func (p *Processes) gatherFromPS(fields map[string]interface{}) error {
// get process states from /proc/(pid)/stat files
func
(
p
*
Processes
)
gatherFromProc
(
fields
map
[
string
]
interface
{})
error
{
files
,
err
:=
ioutil
.
ReadDir
(
"/proc
"
)
file
name
s
,
err
:=
filepath
.
Glob
(
"/proc/[0-9]*/stat
"
)
if
err
!=
nil
{
return
err
}
for
_
,
file
:=
range
files
{
if
!
file
.
IsDir
()
{
continue
}
for
_
,
filename
:=
range
filenames
{
_
,
err
:=
os
.
Stat
(
filename
)
statFile
:=
path
.
Join
(
"/proc"
,
file
.
Name
(),
"stat"
)
data
,
err
:=
p
.
readProcFile
(
statFile
)
data
,
err
:=
p
.
readProcFile
(
filename
)
if
err
!=
nil
{
if
!
file
.
IsDir
()
{
continue
}
return
err
}
if
data
==
nil
{
...
...
@@ -159,7 +153,7 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
stats
:=
bytes
.
Fields
(
data
)
if
len
(
stats
)
<
3
{
return
fmt
.
Errorf
(
"Something is terribly wrong with %s"
,
statFil
e
)
return
fmt
.
Errorf
(
"Something is terribly wrong with %s"
,
filenam
e
)
}
switch
stats
[
0
][
0
]
{
case
'R'
:
...
...
@@ -176,7 +170,7 @@ 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
[
0
][
0
]),
statFil
e
)
string
(
stats
[
0
][
0
]),
filenam
e
)
}
fields
[
"total"
]
=
fields
[
"total"
]
.
(
int64
)
+
int64
(
1
)
...
...
@@ -190,15 +184,12 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
return
nil
}
func
readProcFile
(
statFile
string
)
([]
byte
,
error
)
{
if
_
,
err
:=
os
.
Stat
(
statFile
);
os
.
IsNotExist
(
err
)
{
return
nil
,
nil
}
else
if
err
!=
nil
{
return
nil
,
err
}
data
,
err
:=
ioutil
.
ReadFile
(
statFile
)
func
readProcFile
(
filename
string
)
([]
byte
,
error
)
{
data
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
nil
,
nil
}
return
nil
,
err
}
...
...
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