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
9a062498
Commit
9a062498
authored
7 years ago
by
Daniel Nelson
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use golang.org/x/sys/unix instead of syscall in diskio (#3384)
parent
f64cf89d
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
plugins/inputs/system/disk.go
+11
-12
11 additions, 12 deletions
plugins/inputs/system/disk.go
plugins/inputs/system/disk_linux.go
+19
-17
19 additions, 17 deletions
plugins/inputs/system/disk_linux.go
with
30 additions
and
29 deletions
plugins/inputs/system/disk.go
+
11
−
12
View file @
9a062498
...
@@ -2,6 +2,7 @@ package system
...
@@ -2,6 +2,7 @@ package system
import
(
import
(
"fmt"
"fmt"
"log"
"regexp"
"regexp"
"strings"
"strings"
...
@@ -166,14 +167,13 @@ func (s *DiskIOStats) Gather(acc telegraf.Accumulator) error {
...
@@ -166,14 +167,13 @@ func (s *DiskIOStats) Gather(acc telegraf.Accumulator) error {
var
varRegex
=
regexp
.
MustCompile
(
`\$(?:\w+|\{\w+\})`
)
var
varRegex
=
regexp
.
MustCompile
(
`\$(?:\w+|\{\w+\})`
)
func
(
s
*
DiskIOStats
)
diskName
(
devName
string
)
string
{
func
(
s
*
DiskIOStats
)
diskName
(
devName
string
)
string
{
di
,
err
:=
s
.
diskInfo
(
devName
)
if
len
(
s
.
NameTemplates
)
==
0
{
if
err
!=
nil
{
// discard error :-(
// We can't return error because it's non-fatal to the Gather().
// And we have no logger, so we can't log it.
return
devName
return
devName
}
}
if
di
==
nil
{
di
,
err
:=
s
.
diskInfo
(
devName
)
if
err
!=
nil
{
log
.
Printf
(
"W! Error gathering disk info: %s"
,
err
)
return
devName
return
devName
}
}
...
@@ -200,14 +200,13 @@ func (s *DiskIOStats) diskName(devName string) string {
...
@@ -200,14 +200,13 @@ func (s *DiskIOStats) diskName(devName string) string {
}
}
func
(
s
*
DiskIOStats
)
diskTags
(
devName
string
)
map
[
string
]
string
{
func
(
s
*
DiskIOStats
)
diskTags
(
devName
string
)
map
[
string
]
string
{
di
,
err
:=
s
.
diskInfo
(
devName
)
if
len
(
s
.
DeviceTags
)
==
0
{
if
err
!=
nil
{
// discard error :-(
// We can't return error because it's non-fatal to the Gather().
// And we have no logger, so we can't log it.
return
nil
return
nil
}
}
if
di
==
nil
{
di
,
err
:=
s
.
diskInfo
(
devName
)
if
err
!=
nil
{
log
.
Printf
(
"W! Error gathering disk info: %s"
,
err
)
return
nil
return
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/system/disk_linux.go
+
19
−
17
View file @
9a062498
...
@@ -5,25 +5,26 @@ import (
...
@@ -5,25 +5,26 @@ import (
"fmt"
"fmt"
"os"
"os"
"strings"
"strings"
"syscall"
"golang.org/x/sys/unix"
)
)
type
diskInfoCache
struct
{
type
diskInfoCache
struct
{
stat
syscall
.
Stat_t
udevDataPath
string
values
map
[
string
]
string
values
map
[
string
]
string
}
}
var
udevPath
=
"/run/udev/data"
var
udevPath
=
"/run/udev/data"
func
(
s
*
DiskIOStats
)
diskInfo
(
devName
string
)
(
map
[
string
]
string
,
error
)
{
func
(
s
*
DiskIOStats
)
diskInfo
(
devName
string
)
(
map
[
string
]
string
,
error
)
{
fi
,
err
:=
os
.
Stat
(
"/dev/"
+
devName
)
var
err
error
var
stat
unix
.
Stat_t
path
:=
"/dev/"
+
devName
err
=
unix
.
Stat
(
path
,
&
stat
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
stat
,
ok
:=
fi
.
Sys
()
.
(
*
syscall
.
Stat_t
)
if
!
ok
{
return
nil
,
nil
}
if
s
.
infoCache
==
nil
{
if
s
.
infoCache
==
nil
{
s
.
infoCache
=
map
[
string
]
diskInfoCache
{}
s
.
infoCache
=
map
[
string
]
diskInfoCache
{}
...
@@ -31,25 +32,26 @@ func (s *DiskIOStats) diskInfo(devName string) (map[string]string, error) {
...
@@ -31,25 +32,26 @@ func (s *DiskIOStats) diskInfo(devName string) (map[string]string, error) {
ic
,
ok
:=
s
.
infoCache
[
devName
]
ic
,
ok
:=
s
.
infoCache
[
devName
]
if
ok
{
if
ok
{
return
ic
.
values
,
nil
return
ic
.
values
,
nil
}
else
{
ic
=
diskInfoCache
{
stat
:
*
stat
,
values
:
map
[
string
]
string
{},
}
s
.
infoCache
[
devName
]
=
ic
}
}
di
:=
ic
.
values
major
:=
stat
.
Rdev
>>
8
&
0xff
major
:=
stat
.
Rdev
>>
8
&
0xff
minor
:=
stat
.
Rdev
&
0xff
minor
:=
stat
.
Rdev
&
0xff
udevDataPath
:=
fmt
.
Sprintf
(
"%s/b%d:%d"
,
udevPath
,
major
,
minor
)
di
:=
map
[
string
]
string
{}
f
,
err
:=
os
.
Open
(
fmt
.
Sprintf
(
"%s/b%d:%d"
,
udevPath
,
major
,
minor
))
s
.
infoCache
[
devName
]
=
diskInfoCache
{
udevDataPath
:
udevDataPath
,
values
:
di
,
}
f
,
err
:=
os
.
Open
(
udevDataPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
defer
f
.
Close
()
defer
f
.
Close
()
scnr
:=
bufio
.
NewScanner
(
f
)
scnr
:=
bufio
.
NewScanner
(
f
)
for
scnr
.
Scan
()
{
for
scnr
.
Scan
()
{
l
:=
scnr
.
Text
()
l
:=
scnr
.
Text
()
if
len
(
l
)
<
4
||
l
[
:
2
]
!=
"E:"
{
if
len
(
l
)
<
4
||
l
[
:
2
]
!=
"E:"
{
...
...
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