Skip to content

Commit

Permalink
Merge pull request #123 from algorandfoundation/feat/debug-show-disk-…
Browse files Browse the repository at this point in the history
…stats

feat: add disk space information to debug command
  • Loading branch information
PhearZero authored Jan 21, 2025
2 parents 67b542b + 1d80bb0 commit df7c143
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
17 changes: 14 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,12 +14,13 @@ 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
// the Algod service, path availability, and related metadata.
type DebugInfo struct {
Version string `json:"version"`

// InPath indicates whether the `algod` command-line tool is available in the system's executable path.
InPath bool `json:"inPath"`
Expand Down Expand Up @@ -72,11 +75,19 @@ 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] + "..."
}

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)

info := DebugInfo{
Version: cmd.Root().Version,
InPath: system.CmdExists("algod"),
IsRunning: algod.IsRunning(),
IsService: algod.IsService(),
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 df7c143

Please sign in to comment.