mirror of
https://github.com/jkstack/libagent.git
synced 2025-12-24 12:11:57 +08:00
实现log文件列表查询功能
This commit is contained in:
@@ -38,6 +38,11 @@ func (app *app) read(ctx context.Context, cancel context.CancelFunc, conn *webso
|
||||
return
|
||||
}
|
||||
|
||||
next := app.handleSystemPacket(&msg)
|
||||
if !next {
|
||||
continue
|
||||
}
|
||||
|
||||
app.chRead <- &msg
|
||||
}
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@@ -10,7 +10,7 @@ require (
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/jkstack/anet v0.0.0-20230206080421-e4bd2e304c2e
|
||||
github.com/jkstack/jkframe v1.2.2
|
||||
github.com/jkstack/jkframe v1.3.0
|
||||
github.com/kardianos/service v1.2.1
|
||||
github.com/opencontainers/runtime-spec v1.0.2
|
||||
github.com/shirou/gopsutil/v3 v3.23.1
|
||||
|
||||
4
go.sum
4
go.sum
@@ -28,8 +28,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/jkstack/anet v0.0.0-20230206080421-e4bd2e304c2e h1:wMQuhQkz1v2xmhTi1TPCYqbws3dLL5otVQY59Zqd490=
|
||||
github.com/jkstack/anet v0.0.0-20230206080421-e4bd2e304c2e/go.mod h1:L9J4lHwDxTsCPX5MNaVa/0UG36JIiDWIJxlp3jmCQxQ=
|
||||
github.com/jkstack/jkframe v1.2.2 h1:JKeb7Dg0HpyBIap4ZZ88nloojR+WvPFYy1V1jh67p10=
|
||||
github.com/jkstack/jkframe v1.2.2/go.mod h1:9f/mU26CFA4eBx/Zp8EZtuZxTS+4zokiO7yhuMl2zTA=
|
||||
github.com/jkstack/jkframe v1.3.0 h1:BV9PTUMJ1fbqYoRjdDQFk2kp3akgFBczc30rxbMr7Qg=
|
||||
github.com/jkstack/jkframe v1.3.0/go.mod h1:9f/mU26CFA4eBx/Zp8EZtuZxTS+4zokiO7yhuMl2zTA=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
|
||||
41
system_handler.go
Normal file
41
system_handler.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jkstack/anet"
|
||||
"github.com/jkstack/jkframe/logging"
|
||||
)
|
||||
|
||||
func (app *app) handleSystemPacket(msg *anet.Msg) bool {
|
||||
switch msg.Type {
|
||||
case anet.TypeLogLsReq:
|
||||
app.handleLogLs(msg.TaskID)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (app *app) handleLogLs(id string) {
|
||||
files := logging.Files()
|
||||
var fs []anet.LogFile
|
||||
for _, file := range files {
|
||||
fi, err := os.Stat(file)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
fs = append(fs, anet.LogFile{
|
||||
Name: filepath.Base(file),
|
||||
Size: uint64(fi.Size()),
|
||||
ModTime: fi.ModTime(),
|
||||
})
|
||||
}
|
||||
var msg anet.Msg
|
||||
msg.Type = anet.TypeLogLsRep
|
||||
msg.TaskID = id
|
||||
msg.LsLog = &anet.LsLogPayload{
|
||||
Files: fs,
|
||||
}
|
||||
app.chWrite <- &msg
|
||||
}
|
||||
Reference in New Issue
Block a user