Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gpuhw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
gpuhw
Commits
5ab194dd
Commit
5ab194dd
authored
May 24, 2024
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
filter filesystem and network
parent
41574d3a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
4 deletions
+74
-4
block.go
block.go
+49
-0
main-dcgm.go
main-dcgm.go
+2
-2
main.go
main.go
+2
-2
network.go
network.go
+21
-0
No files found.
block.go
View file @
5ab194dd
...
...
@@ -12,6 +12,7 @@ import (
"context"
"fmt"
"sort"
"strings"
"time"
"github.com/jaypipes/ghw"
...
...
@@ -34,6 +35,54 @@ type FileSystem struct {
SizeBytes
int64
`json:"size_bytes"`
}
var
filter
map
[
string
]
bool
func
init
()
{
filter
=
make
(
map
[
string
]
bool
)
filter
[
"none"
]
=
true
filter
[
"rootfs"
]
=
true
filter
[
"snapfuse"
]
=
true
}
func
filterDevice
(
str
string
)
bool
{
return
strings
.
Contains
(
str
,
"none"
)
||
strings
.
Contains
(
str
,
"rootfs"
)
||
strings
.
Contains
(
str
,
"snapfuse"
)
||
strings
.
Contains
(
str
,
"tmpfs"
)
}
func
(
c
*
ProApi
)
DisksWithFilter
()
([]
FileSystem
,
error
)
{
disks
,
err
:=
c
.
Disks
()
if
err
!=
nil
{
return
nil
,
err
}
res
:=
make
([]
FileSystem
,
0
,
len
(
disks
))
for
_
,
v
:=
range
disks
{
if
!
filterDevice
(
v
.
Device
)
{
newMountPoint
:=
make
([]
string
,
0
,
len
(
v
.
MountPoints
))
for
_
,
mp
:=
range
v
.
MountPoints
{
if
!
(
strings
.
HasPrefix
(
mp
,
"/var"
)
||
strings
.
HasPrefix
(
mp
,
"/snap"
))
{
newMountPoint
=
append
(
newMountPoint
,
mp
)
}
}
v
.
MountPoints
=
newMountPoint
res
=
append
(
res
,
v
)
}
}
return
res
,
nil
}
func
(
c
*
ProApi
)
Disks
()
([]
FileSystem
,
error
)
{
size
,
err
:=
c
.
FileSystemSizeBytes
()
...
...
main-dcgm.go
View file @
5ab194dd
...
...
@@ -73,7 +73,7 @@ func DCGM() {
res
.
Data
.
Cpus
=
cpus
networks
,
err
:=
cli
.
Networks
()
networks
,
err
:=
cli
.
Networks
WithFilter
()
if
err
!=
nil
{
fmt
.
Println
(
"network error"
,
err
.
Error
())
...
...
@@ -83,7 +83,7 @@ func DCGM() {
res
.
Data
.
Networks
=
networks
filesystems
,
err
:=
cli
.
Disks
()
filesystems
,
err
:=
cli
.
Disks
WithFilter
()
if
err
!=
nil
{
fmt
.
Println
(
"disks error"
,
err
.
Error
())
...
...
main.go
View file @
5ab194dd
package
main
func
main
()
{
//
DCGM()
Smi
()
DCGM
()
//
Smi()
}
network.go
View file @
5ab194dd
...
...
@@ -24,6 +24,27 @@ type Network struct {
Mac
string
`json:"mac"`
}
func
(
c
*
ProApi
)
NetworksWithFilter
()
([]
Network
,
error
)
{
nets
,
err
:=
c
.
Networks
()
if
err
!=
nil
{
return
nil
,
err
}
res
:=
make
([]
Network
,
0
,
len
(
nets
))
//veth
//Br
for
_
,
v
:=
range
nets
{
if
!
(
strings
.
HasPrefix
(
v
.
Device
,
"veth"
)
||
strings
.
HasPrefix
(
v
.
Device
,
"br"
))
{
res
=
append
(
res
,
v
)
}
}
return
res
,
nil
}
func
(
c
*
ProApi
)
Networks
()
([]
Network
,
error
)
{
speed
,
err
:=
c
.
NetworkSpeed
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment