| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | package mainimport (	"bytes"	"encoding/json"	"flag"	"fmt"	"github.com/oz123/gupta"	"log"	"os"	"time")func readProcStatLine(r *os.File) string {	buf := make([]byte, 80)	r.ReadAt(buf, 0)	idx := bytes.Index(buf, []byte("cpu0"))	line := string(buf[:idx])	r.Seek(0, 0)	return line}func main() {	var freq int	var partition, netInterface string	var load, memory, cpu bool	flag.IntVar(&freq, "i", 5, "polling inteval")	flag.BoolVar(&memory, "m", false, "Poll memory")	flag.BoolVar(&load, "l", false, "Poll load")	flag.BoolVar(&cpu, "c", false, "poll CPU usage")	flag.StringVar(&partition, "p", "", "Poll disk usage (partition)")	flag.StringVar(&netInterface, "n", "", "Network usage (interface)")	flag.Parse()	fmt.Println(gupta.Hello())	r, _ := os.Open("/proc/stat")	m, _ := os.Open("/proc/meminfo")	for true {		line := readProcStatLine(r)		time.Sleep(time.Second)		lineNew := readProcStatLine(r)		cpustat := gupta.NewCPUStat(line, lineNew)		fmt.Printf("CPU usage %.2f%%\n", cpustat.CPUUsage())		mem := gupta.NewMemory(m)		//fmt.Printf("Memory free %d\n", mem.Total())		report := gupta.GuptaReport{}		report.MemoryUsage = mem		writer := os.Stdout		enc := json.NewEncoder(writer)		if err := enc.Encode(&report); err != nil {			log.Println(err)		}		m.Seek(0, 0)	}}
 |