Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add disk space information to debug command #123

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
"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 @@
return err
}
folderDebug, err := utils.ToDataFolderConfig(dataDir)
folderDebug.Token = folderDebug.Token[:3] + "..."
if err != nil {
return err
folderDebug.Token = fmt.Sprint(err)

Check warning on line 79 in cmd/debug.go

View check run for this annotation

Codecov / codecov/patch

cmd/debug.go#L79

Added line #L79 was not covered by tests
} else {
folderDebug.Token = folderDebug.Token[:3] + "..."
tasosbit marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading