Skip to content

Commit

Permalink
Add cli options for number of disks, cpus
Browse files Browse the repository at this point in the history
also .gitignore vim session file
  • Loading branch information
bioe007 committed Mar 22, 2024
1 parent 56e44b6 commit 3351b31
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ go.work

# ignore binary
synopsys

*.vim
60 changes: 37 additions & 23 deletions synopsys.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"strconv"
"syscall"
"time"

Expand All @@ -16,7 +16,6 @@ import (
"github.com/bioe007/synopsys/uptime"
)

// var scaleMap = map[rune]int{}
var scaleMap = map[rune]int{
'k': 1024,
'K': 1000,
Expand All @@ -28,24 +27,46 @@ var scaleMap = map[rune]int{
'T': 1000 * 1000 * 1000 * 1000,
}

// main stuff getting done
const usage = `Usage:
synopsys [options]
Options:
-i, --interval [integer] Duration in seconds between updates, default 1.
-c, --cpu [integer] Max number of CPU you want to see output.
Default 8.
-d, --disks [integer] Max number of disks you want to see output.
Default 8.
-m, --memscale [kKmMgGtT] Units of memory to display, in kilo/Kibi etc.
Default is megabytes.
`

func main() {
// Argument(s) is only an int to agjust frequency
var num_seconds int
var err error
if len(os.Args) < 2 {
num_seconds = 1
} else {
num_seconds, err = strconv.Atoi(os.Args[1])
if err != nil {
usage()
}
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s\n", usage)
}

var (
num_disks, num_cpu, num_seconds int
mem_scale string
)
flag.IntVar(&num_seconds, "interval", 1,
"The number of seconds to wait between updates.")
flag.IntVar(&num_seconds, "i", 1,
"The number of seconds to wait between updates.")
flag.IntVar(&num_cpu, "cpu", 8, "How many 'hot' CPU to display")
flag.IntVar(&num_cpu, "c", 8, "How many 'hot' CPU to display")
flag.IntVar(&num_disks, "disks", 8, "How many 'hot' CPU to display")
flag.IntVar(&num_disks, "d", 8, "How many 'hot' CPU to display")
flag.StringVar(&mem_scale, "memory", "m", "Choose how to scale memory")
flag.StringVar(&mem_scale, "m", "m", "Choose how to scale memory")
flag.Parse()

// TODO - parse this as an arg
memory.SetScale(scaleMap['m'])
ms := []rune(mem_scale)
memory.SetScale(scaleMap[ms[0]])

ticker := time.NewTicker(time.Duration(num_seconds) * time.Second)
var err error
go func() {
c := new(cpu.CpuInfo)
disks := new(disk.DiskInfo)
Expand All @@ -69,8 +90,6 @@ func main() {
if err != nil {
log.Fatal("disk average failure", err)
}
// TODO
// fmt.Println("Got disks: ", len(disks))

ut, err := uptime.Read_uptime()
if err != nil {
Expand All @@ -81,9 +100,9 @@ func main() {
ut.HoursMinutes(),
ld.InfoPrint(),
// TODO - accept as parameter
c.InfoPrint(14),
c.InfoPrint(num_cpu),
m.InfoPrint(),
disks.InfoPrint(18),
disks.InfoPrint(num_disks),
)
}
}()
Expand All @@ -99,8 +118,3 @@ func main() {
}()
<-done
}

func usage() {
fmt.Printf("Usage: %s [<interval>]", os.Args[0])
os.Exit(0)
}

0 comments on commit 3351b31

Please sign in to comment.