Browse Source

Add skeleton for reading CPU utilization

Oz Tiram 5 years ago
parent
commit
71343faf7a
2 changed files with 31 additions and 2 deletions
  1. 20 1
      gupta.go
  2. 11 1
      gupta_test.go

+ 20 - 1
gupta.go

@@ -4,8 +4,10 @@ import (
 	"fmt"
 )
 
+const version = "0.0.1"
+
 func Hello() string {
-	return "Hello, world"
+	return fmt.Sprintf("Welcome to gupta version %s", version)
 }
 
 func Run(load, cpu, memory bool, partition, networkInterface string) (cpuLoad, cpuUsage, memoryUsage float64) {
@@ -24,3 +26,20 @@ type GuptaReport struct {
 func (g *GuptaReport) GetCPULoad() string {
 	return fmt.Sprintf("%.2f", g.cpuLoad)
 }
+
+type CPULoad struct {
+	user       int
+	nice       int
+	system     int
+	idle       int
+	iowait     int
+	irq        int
+	softirq    int
+	steal      int
+	guest      int
+	guest_nice int
+}
+
+func (c *CPULoad) ReadInfo(rawInfo []string) {
+	c.user = 1
+}

+ 11 - 1
gupta_test.go

@@ -1,12 +1,13 @@
 package gupta
 
 import (
+	"fmt"
 	"testing"
 )
 
 func TestHello(t *testing.T) {
 	got := Hello()
-	want := "Hello, world"
+	want := fmt.Sprintf("Welcome to gupta version %s", version)
 
 	if got != want {
 		t.Errorf("got %q want %q", got, want)
@@ -46,3 +47,12 @@ func TestGuptaHasReport(t *testing.T) {
 	}
 
 }
+
+func TestGetCPULoad(t *testing.T) {
+	cpuload := CPULoad{}
+	cpuload.ReadInfo(make([]string, 3))
+
+	if cpuload.user != 1 {
+		t.Errorf("got %v want %v", cpuload.user, 1)
+	}
+}