//HostSummary  stats for a host system
HostSummary  stats for a host system
// HostSummary stats for a host system
func (c *Client) HostSummary(name, moid string, js bool) (err error) {
	start := time.Now()
	ctx := context.Background()
	ctx, _ = context.WithTimeout(ctx, 30*time.Second)
	v, err := c.m.CreateContainerView(ctx, c.c.ServiceContent.RootFolder, []string{"HostSystem"}, true)
	if err != nil {
		return fmt.Errorf("create container %v", err)
	}
	defer func() { _ = v.Destroy(ctx) }()
	id := types.ManagedObjectReference{
		Type:  "HostSystem",
		Value: moid,
	}
	if moid == "" {
		id, err = c.findOne(name, "HostSystem")
		if err != nil {
			return
		}
	}
	hs := mo.HostSystem{}
	err = v.Properties(ctx, id, nil, &hs)
	if err != nil {
		return errCheck(name, id, fmt.Errorf("hs v.properties %v", err))
	}
	pr := newPrtgData("HostSummary")
	ps1 := ps.SensorChannel{Channel: "Power state", Unit: "Custom", VolumeSize: "Custom", ValueLookup: "prtg.standardlookups.Google.Gsa.Health", LimitWarningMsg: "Host was put to sleep", LimitErrorMsg: "Host in unknown state, please investigate"}
	switch hs.Runtime.PowerState {
	case "poweredOn":
		_ = pr.add(0, ps1)
	case "poweredOff", "standby":
		_ = pr.add(1, ps1)
		_ = pr.print(time.Since(start), false)
		return
	default:
		_ = pr.add(2, ps1)
		_ = pr.print(time.Since(start), false)
		return
	}
	elapsed := time.Since(start)
	freeMemory := hs.Summary.Hardware.MemorySize - (int64(hs.Summary.QuickStats.OverallMemoryUsage) * 1024 * 1024)
	freeMemoryp := freeMemory / (hs.Summary.Hardware.MemorySize / 100)
	_ = pr.add(freeMemory, ps.SensorChannel{Channel: "Memory Free", Unit: "BytesMemory"})
	_ = pr.add(freeMemoryp, ps.SensorChannel{Channel: "Memory Free (Percent)", Unit: "Percent", DecimalMode: "1"})
	totalCPU := int64(hs.Summary.Hardware.CpuMhz) * int64(hs.Summary.Hardware.NumCpuCores)
	freeCPU := totalCPU - int64(hs.Summary.QuickStats.OverallCpuUsage)
	usedCPUP := int64(hs.Summary.QuickStats.OverallCpuUsage) / (totalCPU / 100)
	freeCPUP := freeCPU / (totalCPU / 100)
	_ = pr.add(freeCPUP, ps.SensorChannel{Channel: "CPU Free", Unit: "Percent", DecimalMode: "1"})
	_ = pr.add(usedCPUP, ps.SensorChannel{Channel: "CPU Used", Unit: "Percent", DecimalMode: "1"})
	_ = pr.add(totalCPU-freeCPU, ps.SensorChannel{Channel: "CPU Used MHz", Unit: "Custom", VolumeSize: "One", CustomUnit: "MHz"})
	_ = pr.add(freeCPU, ps.SensorChannel{Channel: "CPU Free MHz", Unit: "Custom", VolumeSize: "One", CustomUnit: "MHz"})
	_ = pr.add(totalCPU, ps.SensorChannel{Channel: "CPU Capacity MHz", Unit: "Custom", VolumeSize: "One", CustomUnit: "MHz"})
	_ = pr.add(boolToInt(hs.Runtime.InMaintenanceMode), ps.SensorChannel{Channel: "Maintenance Mode", Unit: "Custom", VolumeSize: "Custom", ValueLookup: "prtg.standardlookups.boolean.statefalseok"})
	_ = pr.add(triggeredAlarms(hs.TriggeredAlarmState), ps.SensorChannel{Channel: "Triggered Alarms", Unit: "Count", LimitMaxWarning: "1", LimitWarningMsg: "triggered alarms present"})
	pr.text = fmt.Sprint(hs.Runtime.PowerState)
	diskPathDetails := hs.Config.StorageDevice.MultipathInfo
	var triggered bool
	for _, lun := range diskPathDetails.Lun {
		for _, path := range lun.Path {
			if !*path.IsWorkingPath {
				triggered = true
				pr.text = "Path failure " + path.Name
			}
		}
	}
	_ = pr.add(boolToInt(triggered), ps.SensorChannel{Channel: "storage_path_error", Unit: "Custom", VolumeSize: "Custom", ValueLookup: "prtg.standardlookups.boolean.statefalseok", LimitErrorMsg: "check storage paths"})
	err = c.Metrics(id, pr, hsSummaryDefault, 20)
	if err != nil {
		return
	}
	_ = pr.print(elapsed, js)
	return
}
func ( c * Client ) HostSummary ( name , moid string , js bool ) ( err error ) { start := time . Now ( ) ctx := context . Background ( ) ctx , _ = context . WithTimeout ( ctx , 30 * time . Second ) v , err := c . m . CreateContainerView ( ctx , c . c . ServiceContent . RootFolder , [ ] string { " " } , true ) if err != nil { return fmt . Errorf ( " " , err ) } defer func ( ) { _ = v . Destroy ( ctx ) } ( ) id := types . ManagedObjectReference { Type : " " , Value : moid , } if moid == " " { id , err = c . findOne ( name , " " ) if err != nil { return } } hs := mo . HostSystem { } err = v . Properties ( ctx , id , nil , & hs ) if err != nil { return errCheck ( name , id , fmt . Errorf ( " " , err ) ) } pr := newPrtgData ( " " ) ps1 := ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " , ValueLookup : " " , LimitWarningMsg : " " , LimitErrorMsg : " " } switch hs . Runtime . PowerState { case " " : _ = pr . add ( 0 , ps1 ) case " " , " " : _ = pr . add ( 1 , ps1 ) _ = pr . print ( time . Since ( start ) , false ) return default : _ = pr . add ( 2 , ps1 ) _ = pr . print ( time . Since ( start ) , false ) return } elapsed := time . Since ( start ) freeMemory := hs . Summary . Hardware . MemorySize - ( int64 ( hs . Summary . QuickStats . OverallMemoryUsage ) * 1024 * 1024 ) freeMemoryp := freeMemory / ( hs . Summary . Hardware . MemorySize / 100 ) _ = pr . add ( freeMemory , ps . SensorChannel { Channel : " " , Unit : " " } ) _ = pr . add ( freeMemoryp , ps . SensorChannel { Channel : " " , Unit : " " , DecimalMode : " " } ) totalCPU := int64 ( hs . Summary . Hardware . CpuMhz ) * int64 ( hs . Summary . Hardware . NumCpuCores ) freeCPU := totalCPU - int64 ( hs . Summary . QuickStats . OverallCpuUsage ) usedCPUP := int64 ( hs . Summary . QuickStats . OverallCpuUsage ) / ( totalCPU / 100 ) freeCPUP := freeCPU / ( totalCPU / 100 ) _ = pr . add ( freeCPUP , ps . SensorChannel { Channel : " " , Unit : " " , DecimalMode : " " } ) _ = pr . add ( usedCPUP , ps . SensorChannel { Channel : " " , Unit : " " , DecimalMode : " " } ) _ = pr . add ( totalCPU - freeCPU , ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " , CustomUnit : " " } ) _ = pr . add ( freeCPU , ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " , CustomUnit : " " } ) _ = pr . add ( totalCPU , ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " , CustomUnit : " " } ) _ = pr . add ( boolToInt ( hs . Runtime . InMaintenanceMode ) , ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " , ValueLookup : " " } ) _ = pr . add ( triggeredAlarms ( hs . TriggeredAlarmState ) , ps . SensorChannel { Channel : " " , Unit : " " , LimitMaxWarning : " " , LimitWarningMsg : " " } ) pr . text = fmt . Sprint ( hs . Runtime . PowerState ) diskPathDetails := hs . Config . StorageDevice . MultipathInfo var triggered bool for _ , lun := range diskPathDetails . Lun { for _ , path := range lun . Path { if ! * path . IsWorkingPath { triggered = true pr . text = " " + path . Name } } } _ = pr . add ( boolToInt ( triggered ) , ps . SensorChannel { Channel : " " , Unit : " " , VolumeSize : " " , ValueLookup : " " , LimitErrorMsg : " " } ) err = c . Metrics ( id , pr , hsSummaryDefault , 20 ) if err != nil { return } _ = pr . print ( elapsed , js ) return }
HostSummary  stats for a host system
HostSummary stats for a host system