use numeric size field in arthur JSON output

This commit is contained in:
Max Erenberg 2023-05-01 18:00:41 -04:00 committed by Mirror
parent 79ca1950f5
commit 8d078d04de
1 changed files with 11 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"text/tabwriter"
"time"
@ -37,7 +38,7 @@ var layoutHtmlTemplate string
type EnrichedRepoStatusInfo struct {
serverArthurPkg.RepoStatusInfo
Size string `json:"size,omitempty"`
Size uint64 `json:"size,omitempty"`
}
type EnrichedStatusInfo struct {
Repos []*EnrichedRepoStatusInfo `json:"repos"`
@ -161,12 +162,12 @@ func unixTimeToStr(unixTime int64) string {
// getFilesystemSizes parses the output of the `zfs list` command and returns
// a map which looks like {"debian":"1.62T","gnu":"148G",...}.
func getFilesystemSizes() map[string]string {
pattern := regexp.MustCompile(`^cscmirror\d/([^ ]+) (.*)$`)
result := make(map[string]string)
func getFilesystemSizes() map[string]uint64 {
pattern := regexp.MustCompile(`^cscmirror\d/([^ ]+) (\d+)$`)
result := make(map[string]uint64)
// Use the absolute path to the zfs command because /sbin isn't in the
// mirror user's PATH variable when running from cron
cmd := exec.Command("sh", "-c", `/sbin/zfs list -t filesystem -H | awk '/^cscmirror[[:digit:]]\// {print $1 " " $2}'`)
cmd := exec.Command("sh", "-c", `/sbin/zfs list -t filesystem -H -p | awk '/^cscmirror[[:digit:]]\// {print $1 " " $2}'`)
output, err := cmd.Output()
if err != nil {
fmt.Fprintf(os.Stderr, "zfs list failed: %+v\n", err)
@ -182,7 +183,11 @@ func getFilesystemSizes() map[string]string {
continue
}
projectName := string(matches[1])
diskUsage := string(matches[2])
diskUsage, parseErr := strconv.ParseUint(string(matches[2]), 10, 64)
if parseErr != nil {
fmt.Fprintf(os.Stderr, "could not parse int: %s\n", string(matches[2]))
continue
}
result[projectName] = diskUsage
}
return result