func cpuMetrics()

in internal/hostmetrics/osmetricreader/osmetricreader.go [276:362]


func cpuMetrics(cpuStats *statspb.CpuStats, instanceProperties *iipb.InstanceProperties, startTime int64) []*mpb.Metric {
	// CPU metrics.
	var cpuMetrics []*mpb.Metric
	if instanceProperties.GetCpuPlatform() != "" {
		cpuMetrics = []*mpb.Metric{
			&mpb.Metric{
				Name:            "Processor Type",
				Context:         mpb.Context_CONTEXT_HOST,
				Category:        mpb.Category_CATEGORY_CPU,
				Type:            mpb.Type_TYPE_STRING,
				Unit:            mpb.Unit_UNIT_NONE,
				RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
				LastRefresh:     startTime,
				Value:           instanceProperties.GetCpuPlatform(),
			},
		}
	}
	// usually 2 threads per core.
	var threadsPerCore int64 = 2
	if cpuStats.GetCpuCount() > 0 && cpuStats.GetCpuCores() > 9 {
		threadsPerCore = cpuStats.GetCpuCount() / cpuStats.GetCpuCores()
	}

	cpuMetrics = append(cpuMetrics,
		&mpb.Metric{
			Name:            "Number of Threads per Core",
			Context:         mpb.Context_CONTEXT_HOST,
			Category:        mpb.Category_CATEGORY_CPU,
			Type:            mpb.Type_TYPE_INT64,
			Unit:            mpb.Unit_UNIT_NONE,
			RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
			LastRefresh:     startTime,
			Value:           strconv.FormatInt(threadsPerCore, 10),
		},
		&mpb.Metric{
			Name:            "Current HW frequency",
			Context:         mpb.Context_CONTEXT_HOST,
			Category:        mpb.Category_CATEGORY_CPU,
			Type:            mpb.Type_TYPE_INT64,
			Unit:            mpb.Unit_UNIT_MHZ,
			RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
			LastRefresh:     startTime,
			Value:           strconv.FormatInt(cpuStats.GetMaxMhz(), 10),
		},
		&mpb.Metric{
			Name:            "Max. HW frequency",
			Context:         mpb.Context_CONTEXT_HOST,
			Category:        mpb.Category_CATEGORY_CPU,
			Type:            mpb.Type_TYPE_INT64,
			Unit:            mpb.Unit_UNIT_MHZ,
			RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
			LastRefresh:     startTime,
			Value:           strconv.FormatInt(cpuStats.GetMaxMhz(), 10),
		},
		&mpb.Metric{
			Name:            "Reference Compute Unit [CU]",
			Context:         mpb.Context_CONTEXT_VM,
			Category:        mpb.Category_CATEGORY_CPU,
			Type:            mpb.Type_TYPE_STRING,
			Unit:            mpb.Unit_UNIT_NONE,
			RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
			LastRefresh:     startTime,
			Value:           cpuStats.GetProcessorType(),
		},
		&mpb.Metric{
			Name:            "Phys. Processing Power per vCPU",
			Context:         mpb.Context_CONTEXT_VM,
			Category:        mpb.Category_CATEGORY_CPU,
			Type:            mpb.Type_TYPE_DOUBLE,
			Unit:            mpb.Unit_UNIT_CU,
			RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
			LastRefresh:     startTime,
			Value:           "1.00",
		},
		&mpb.Metric{
			Name:            "Guaranteed VM Processing Power",
			Context:         mpb.Context_CONTEXT_VM,
			Category:        mpb.Category_CATEGORY_CPU,
			Type:            mpb.Type_TYPE_DOUBLE,
			Unit:            mpb.Unit_UNIT_CU,
			RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
			LastRefresh:     startTime,
			Value:           strconv.FormatInt(cpuStats.GetCpuCount(), 10) + ".00",
		},
	)
	return cpuMetrics
}