Skip to content

Commit

Permalink
feat: add disk space information to debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasos Bitsios committed Jan 21, 2025
1 parent d8b44a6 commit ee0d5a3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
15 changes: 12 additions & 3 deletions cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"encoding/json"
"fmt"
"os/exec"

cmdutils "github.com/algorandfoundation/nodekit/cmd/utils"
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
"github.com/algorandfoundation/nodekit/internal/algod"
Expand All @@ -12,7 +14,7 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
"os/exec"
"golang.org/x/sys/unix"
)

// DebugInfo represents diagnostic information about
Expand Down Expand Up @@ -72,10 +74,17 @@ var debugCmd = cmdutils.WithAlgodFlags(&cobra.Command{
return err
}
folderDebug, err := utils.ToDataFolderConfig(dataDir)
folderDebug.Token = folderDebug.Token[:3] + "..."
if err != nil {
return err
folderDebug.Token = fmt.Sprint(err)
} else {
folderDebug.Token = folderDebug.Token[:3] + "..."

Check warning on line 80 in cmd/debug.go

View check run for this annotation

Codecov / codecov/patch

cmd/debug.go#L78-L80

Added lines #L78 - L80 were not covered by tests
}

var stat unix.Statfs_t
unix.Statfs(dataDir, &stat)
bytesFree := stat.Bavail * uint64(stat.Bsize)
folderDebug.BytesFree = fmt.Sprintf("%d bytes (%d MB)", bytesFree, bytesFree/1024/1024)

Check warning on line 87 in cmd/debug.go

View check run for this annotation

Codecov / codecov/patch

cmd/debug.go#L83-L87

Added lines #L83 - L87 were not covered by tests
info := DebugInfo{
InPath: system.CmdExists("algod"),
IsRunning: algod.IsRunning(),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ require (
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/sys v0.29.0
golang.org/x/text v0.21.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 9 additions & 7 deletions internal/algod/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ package utils
import (
"encoding/json"
"fmt"
"github.com/algorandfoundation/nodekit/internal/system"
"github.com/spf13/cobra"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/algorandfoundation/nodekit/internal/system"
"github.com/spf13/cobra"
)

const AlgodNetEndpointFileMissingAddress = "missing://endpoint"

type DataFolderConfig struct {
Path string `json:"path"`
Token string `json:"token"`
Endpoint string `json:"endpoint"`
Network string `json:"network"`
PID int `json:"PID"`
Path string `json:"path"`
BytesFree string `json:"bytesFree"`
Token string `json:"token"`
Endpoint string `json:"endpoint"`
Network string `json:"network"`
PID int `json:"PID"`
}

func ToDataFolderConfig(path string) (DataFolderConfig, error) {
Expand Down

0 comments on commit ee0d5a3

Please sign in to comment.