Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
liming6
dcu-process-montor
Commits
d40a98f3
Commit
d40a98f3
authored
Dec 26, 2025
by
liming6
Browse files
fix 添加判断docker api版本功能,提高docker版本兼容性
parent
f83b1bc9
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1834 additions
and
18 deletions
+1834
-18
cmd/hytop/backend/docker.go
cmd/hytop/backend/docker.go
+2
-1
cmd/hytop/lib/kfd_ioctl.h
cmd/hytop/lib/kfd_ioctl.h
+1788
-0
cmd/hytop/lib/rocm_smi.h
cmd/hytop/lib/rocm_smi.h
+1
-1
docker/find.go
docker/find.go
+29
-1
docker/find_test.go
docker/find_test.go
+13
-1
go.mod
go.mod
+1
-14
No files found.
cmd/hytop/backend/docker.go
View file @
d40a98f3
...
...
@@ -2,6 +2,7 @@ package backend
import
(
"context"
"get-container/docker"
"strconv"
"strings"
"sync"
...
...
@@ -20,7 +21,7 @@ type DockerProcessMap struct {
}
func
(
m
*
DockerProcessMap
)
Update
()
error
{
cli
,
err
:=
client
.
NewClientWithOpts
(
client
.
FromEnv
,
client
.
WithAPIVersionNegotiation
()
)
cli
,
err
:=
docker
.
GetDockerClient
()
if
err
!=
nil
{
return
err
}
...
...
cmd/hytop/lib/kfd_ioctl.h
0 → 100644
View file @
d40a98f3
This diff is collapsed.
Click to expand it.
cmd/hytop/lib/rocm_smi.h
View file @
d40a98f3
...
...
@@ -53,7 +53,7 @@ extern "C" {
#include <stddef.h>
#include <stdbool.h>
#include "
rocm_smi/
kfd_ioctl.h"
#include "kfd_ioctl.h"
/** \file rocm_smi.h
* Main header file for the ROCm SMI library.
...
...
docker/find.go
View file @
d40a98f3
package
docker
import
(
"os/exec"
"strconv"
"context"
...
...
@@ -158,7 +159,7 @@ func (info *ContainersInfo) GetProcessIdInDocker(update bool) (map[string][]Cont
// getRunningContainerInfo 获取所有正在运行的docker容器的详细信息
func
getRunningContainerInfo
()
(
map
[
string
]
container
.
InspectResponse
,
map
[
string
]
container
.
Summary
,
map
[
string
]
container
.
TopResponse
,
error
)
{
cli
,
err
:=
client
.
NewClientWithOpts
(
client
.
FromEnv
,
client
.
WithAPIVersionNegotiation
()
)
cli
,
err
:=
GetDockerClient
()
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
err
}
...
...
@@ -187,3 +188,30 @@ func getRunningContainerInfo() (map[string]container.InspectResponse, map[string
}
return
inspects
,
lists
,
tops
,
nil
}
var
(
reDockerApi
=
regexp
.
MustCompile
(
`(?i)^\s+api\s+version:\s+([0-9.]+).*$`
)
)
func
GetDockerAPIVersion
()
(
string
,
error
)
{
output
,
err
:=
exec
.
Command
(
"docker"
,
"version"
)
.
Output
()
if
err
!=
nil
{
return
""
,
err
}
lines
:=
strings
.
Split
(
strings
.
Trim
(
string
(
output
),
"
\n
"
),
"
\n
"
)
for
_
,
v
:=
range
lines
{
if
reDockerApi
.
MatchString
(
v
)
{
m
:=
reDockerApi
.
FindStringSubmatch
(
v
)
return
m
[
1
],
nil
}
}
return
""
,
nil
}
func
GetDockerClient
()
(
*
client
.
Client
,
error
)
{
ver
,
err
:=
GetDockerAPIVersion
()
if
err
!=
nil
{
return
client
.
NewClientWithOpts
(
client
.
FromEnv
,
client
.
WithAPIVersionNegotiation
())
}
return
client
.
NewClientWithOpts
(
client
.
FromEnv
,
client
.
WithVersion
(
ver
))
}
docker/find_test.go
View file @
d40a98f3
...
...
@@ -68,7 +68,11 @@ func TestRegexp(t *testing.T) {
}
func
TestDocker
(
t
*
testing
.
T
)
{
cli
,
err
:=
client
.
NewClientWithOpts
(
client
.
FromEnv
,
client
.
WithAPIVersionNegotiation
())
v
,
err
:=
GetDockerAPIVersion
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
cli
,
err
:=
client
.
NewClientWithOpts
(
client
.
FromEnv
,
client
.
WithVersion
(
v
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -108,3 +112,11 @@ func TestGetProcessIdInDocker(t *testing.T) {
}
}
}
func
TestGetDockerAPIVersion
(
t
*
testing
.
T
)
{
v
,
err
:=
GetDockerAPIVersion
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
t
.
Log
(
v
)
}
go.mod
View file @
d40a98f3
...
...
@@ -12,23 +12,20 @@ require (
github.com/shirou/gopsutil/v3
v3.24.5
github.com/shirou/gopsutil/v4
v4.25.9
github.com/spf13/viper
v1.21.0
github.com/swaggo/swag
v1.16.6
)
require (
github.com/KyleBanks/depth
v1.2.1 // indirect
github.com/PuerkitoBio/purell
v1.2.1 // indirect
github.com/PuerkitoBio/urlesc
v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic
v1.14.0 // indirect
github.com/bytedance/sonic/loader
v0.3.0 // indirect
github.com/cloudwego/base64x
v0.1.6 // indirect
github.com/cpuguy83/go-md2man/v2
v2.0.7 // indirect
github.com/fsnotify/fsnotify
v1.9.0 // indirect
github.com/gabriel-vasile/mimetype
v1.4.8 // indirect
github.com/gin-contrib/sse
v1.1.0 // indirect
github.com/go-openapi/jsonpointer
v0.22.4 // indirect
github.com/go-openapi/jsonreference
v0.21.4 // indirect
github.com/go-openapi/spec
v0.22.2 // indirect
github.com/go-openapi/swag
v0.25.4 // indirect
github.com/go-openapi/swag/conv
v0.25.4 // indirect
github.com/go-openapi/swag/jsonname
v0.25.4 // indirect
github.com/go-openapi/swag/jsonutils
v0.25.4 // indirect
...
...
@@ -42,11 +39,9 @@ require (
github.com/go-viper/mapstructure/v2
v2.4.0 // indirect
github.com/goccy/go-json
v0.10.2 // indirect
github.com/goccy/go-yaml
v1.18.0 // indirect
github.com/josharian/intern
v1.0.0 // indirect
github.com/json-iterator/go
v1.1.12 // indirect
github.com/klauspost/cpuid/v2
v2.3.0 // indirect
github.com/leodido/go-urn
v1.4.0 // indirect
github.com/mailru/easyjson
v0.9.1 // indirect
github.com/modern-go/concurrent
v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2
v1.0.2 // indirect
github.com/muesli/clusters
v0.0.0-20200529215643-2700303c1762 // indirect
...
...
@@ -54,22 +49,16 @@ require (
github.com/pelletier/go-toml/v2
v2.2.4 // indirect
github.com/quic-go/qpack
v0.5.1 // indirect
github.com/quic-go/quic-go
v0.54.0 // indirect
github.com/ramya-rao-a/go-outline
v0.0.0-20210608161538-9736a4bde949 // indirect
github.com/russross/blackfriday/v2
v2.1.0 // indirect
github.com/sagikazarmark/locafero
v0.11.0 // indirect
github.com/shoenig/go-m1cpu
v0.1.6 // indirect
github.com/shurcooL/sanitized_anchor_name
v1.0.0 // indirect
github.com/sourcegraph/conc
v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero
v1.15.0 // indirect
github.com/spf13/cast
v1.10.0 // indirect
github.com/subosito/gotenv
v1.6.0 // indirect
github.com/swaggo/swag
v1.16.6 // indirect
github.com/twitchyliquid64/golang-asm
v0.15.1 // indirect
github.com/ugorji/go/codec
v1.3.0 // indirect
github.com/urfave/cli/v2
v2.27.7 // indirect
github.com/xrash/smetrics
v0.0.0-20250705151800-55b8f293f342 // indirect
go.uber.org/mock
v0.5.0 // indirect
go.yaml.in/yaml/v2
v2.4.3 // indirect
go.yaml.in/yaml/v3
v3.0.4 // indirect
golang.org/x/arch
v0.20.0 // indirect
golang.org/x/crypto
v0.46.0 // indirect
...
...
@@ -78,8 +67,6 @@ require (
golang.org/x/sync
v0.19.0 // indirect
golang.org/x/tools
v0.40.0 // indirect
google.golang.org/protobuf
v1.36.9 // indirect
gopkg.in/yaml.v2
v2.4.0 // indirect
sigs.k8s.io/yaml
v1.6.0 // indirect
)
require (
...
...
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