SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "github.com/shirou/gopsutil/cpu"
  6.     "github.com/shirou/gopsutil/mem"
  7.     "github.com/shirou/gopsutil/process"
  8.     "github.com/shirou/gopsutil/load"
  9.     "github.com/shirou/gopsutil/disk"
  10.     "github.com/shirou/gopsutil/host"
  11.     "reflect"
  12.     "time"
  13. )
  14.  
  15. func main() {
  16.  
  17.     driveC := "C:"
  18.  
  19.     processor, _ := cpu.Times(false)
  20.     memory,_ := mem.VirtualMemory()
  21.     cpuPercent,_ := cpu.Percent(time.Second,false)
  22.  
  23.  
  24.  
  25.     fmt.Println(reflect.TypeOf(processor))
  26.     fmt.Println(reflect.TypeOf(memory))
  27.     fmt.Println(reflect.TypeOf(cpuPercent))
  28.  
  29.  
  30.     fmt.Println("CPU")
  31.     fmt.Println("CPU name",processor[0].CPU)
  32.     fmt.Println("User time",processor[0].User)
  33.     fmt.Println("Idle time",processor[0].Idle)
  34.     fmt.Println("System time",processor[0].System)
  35.     fmt.Println("Nice time",processor[0].Nice)
  36.     fmt.Println("IOwait time",processor[0].Iowait)
  37.     fmt.Println("Irq time",processor[0].Irq)
  38.     fmt.Println("SoftIrq time",processor[0].Softirq)
  39.  
  40.  
  41.  
  42.     fmt.Println("CPU Percent",cpuPercent)
  43.     //fmt.Println(memory.Total)
  44.  
  45.  
  46.     infoStat, _ := cpu.Info()
  47.     fmt.Printf("n")
  48.     fmt.Println("--> Hardware Info with Context:  ", infoStat)
  49.  
  50.     procCount, _ := cpu.ProcInfo()
  51.     fmt.Printf("n")
  52.     fmt.Println("--> Process Count:  ", procCount)
  53.  
  54.     fmt.Println("-----------------DISK--------------------------------->")
  55.  
  56.     driveUsage, _ := disk.Usage(driveC)
  57.     fmt.Printf("n")
  58.     fmt.Println("--> Disk Usage for :", driveUsage)
  59.  
  60.     partitionInfo, _ := disk.Partitions(true)
  61.     fmt.Printf("n")
  62.     fmt.Println("--> Partitions :", partitionInfo)
  63.  
  64.     folderInfo, _ := disk.IOCounters("C:", "D:")
  65.     //fmt.Printf("nDisk IO counter remainingn")
  66.     fmt.Printf("n")
  67.     fmt.Println("-->Disk IO counter :", folderInfo)
  68.  
  69.     fmt.Printf("Docker remainingn")
  70.     fmt.Printf("n")
  71.  
  72.     fmt.Println("-----------------Host--------------------------------->")
  73.  
  74.     hostInfo, _ := host.Info()
  75.     fmt.Printf("n")
  76.     fmt.Println("--> Host Info :", hostInfo)
  77.  
  78.     /*userName, _ := host.Users()
  79.     fmt.Printf("n")
  80.     fmt.Println("--> Username :", userName)*/
  81.  
  82.     fmt.Println("-----------------Load--------------------------------->")
  83.  
  84.     avgLoad, _ := load.Avg()
  85.     fmt.Printf("n")
  86.     fmt.Println("--> Average Load :", avgLoad)
  87.  
  88.     avgMisc, _ := load.Misc()
  89.     fmt.Printf("n")
  90.     fmt.Println("--> Misc :", avgMisc)
  91.  
  92.     fmt.Println("-----------------RAM--------------------------------->")
  93.  
  94.     virtMemory, _ := mem.VirtualMemory()
  95.     fmt.Printf("n")
  96.     fmt.Println("--> Virtual Memory :", virtMemory)
  97.  
  98.     swapMemory, _ := mem.SwapMemory()
  99.     fmt.Printf("n")
  100.     fmt.Println("--> Swap Memory :", swapMemory)
  101.  
  102.     //fmt.Println("Process running list")
  103.     //processList()
  104.  
  105. }
  106.    
  107. Can creating application as windows service reduce CPU usage ?
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top