Skip to content

Commit

Permalink
feat:WAF、网站监控增加日志定时清理 (#7057)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 authored Nov 14, 2024
1 parent 03e9077 commit 82e15cb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion agent/app/dto/response/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type FileTree struct {
}

type DirSizeRes struct {
Size float64 `json:"size" validate:"required"`
Size int64 `json:"size" validate:"required"`
}

type FileProcessKeys struct {
Expand Down
14 changes: 0 additions & 14 deletions agent/app/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"
"io/fs"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -403,19 +402,6 @@ func (f *FileService) DirSize(req request.DirSizeReq) (response.DirSizeRes, erro
if req.Path == "/proc" {
return res, nil
}
cmd := exec.Command("du", "-s", req.Path)
output, err := cmd.Output()
if err == nil {
fields := strings.Fields(string(output))
if len(fields) == 2 {
var cmdSize int64
_, err = fmt.Sscanf(fields[0], "%d", &cmdSize)
if err == nil {
res.Size = float64(cmdSize * 1024)
return res, nil
}
}
}
fo := files.NewFileOp()
size, err := fo.GetDirSize(req.Path)
if err != nil {
Expand Down
20 changes: 17 additions & 3 deletions agent/utils/files/file_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io/fs"
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -502,9 +503,22 @@ func (f FileOp) CopyFile(src, dst string) error {
return cmd.ExecCmd(fmt.Sprintf(`cp -f '%s' '%s'`, src, dst+"/"))
}

func (f FileOp) GetDirSize(path string) (float64, error) {
func (f FileOp) GetDirSize(path string) (int64, error) {
duCmd := exec.Command("du", "-s", path)
output, err := duCmd.Output()
if err == nil {
fields := strings.Fields(string(output))
if len(fields) == 2 {
var cmdSize int64
_, err = fmt.Sscanf(fields[0], "%d", &cmdSize)
if err == nil {
return cmdSize * 1024, nil
}
}
}

var size int64
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
Expand All @@ -516,7 +530,7 @@ func (f FileOp) GetDirSize(path string) (float64, error) {
if err != nil {
return 0, err
}
return float64(size), nil
return size, nil
}

func getFormat(cType CompressType) archiver.CompressedArchive {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/styles/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ html {
color: #8f959e;
width: 100%;
display: inline-block;
height: 12px;
}

.input-error {
Expand Down

0 comments on commit 82e15cb

Please sign in to comment.