in internal/hostmetrics/osmetricreader/osmetricreader.go [202:271]
func networkMetrics(cpuStats *statspb.CpuStats, instanceProperties *iipb.InstanceProperties, startTime int64) []*mpb.Metric {
var networkMetrics []*mpb.Metric
for _, networkAdapter := range instanceProperties.GetNetworkAdapters() {
adapterID := networkAdapter.GetName()
networkMetrics = append(networkMetrics,
&mpb.Metric{
Name: "Adapter ID",
Context: mpb.Context_CONTEXT_VM,
Category: mpb.Category_CATEGORY_NETWORK,
Type: mpb.Type_TYPE_STRING,
Unit: mpb.Unit_UNIT_NONE,
RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
LastRefresh: startTime,
Value: adapterID,
DeviceId: adapterID,
},
)
networkMetrics = append(networkMetrics,
&mpb.Metric{
Name: "Mapping",
Context: mpb.Context_CONTEXT_VM,
Category: mpb.Category_CATEGORY_NETWORK,
Type: mpb.Type_TYPE_STRING,
Unit: mpb.Unit_UNIT_NONE,
RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
LastRefresh: startTime,
Value: networkAdapter.GetMapping(),
DeviceId: adapterID,
},
)
bandwidth := min(16, cpuStats.GetCpuCount()*2) * 1000
networkMetrics = append(networkMetrics,
&mpb.Metric{
Name: "Minimum Network Bandwidth",
Context: mpb.Context_CONTEXT_VM,
Category: mpb.Category_CATEGORY_NETWORK,
Type: mpb.Type_TYPE_INT64,
Unit: mpb.Unit_UNIT_MBPS,
RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
LastRefresh: startTime,
Value: strconv.FormatInt(bandwidth, 10),
DeviceId: adapterID,
},
&mpb.Metric{
Name: "Maximum Network Bandwidth",
Context: mpb.Context_CONTEXT_VM,
Category: mpb.Category_CATEGORY_NETWORK,
Type: mpb.Type_TYPE_INT64,
Unit: mpb.Unit_UNIT_MBPS,
RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
LastRefresh: startTime,
Value: strconv.FormatInt(bandwidth, 10),
DeviceId: adapterID,
},
&mpb.Metric{
Name: "Current Network Bandwidth",
Context: mpb.Context_CONTEXT_VM,
Category: mpb.Category_CATEGORY_NETWORK,
Type: mpb.Type_TYPE_INT64,
Unit: mpb.Unit_UNIT_MBPS,
RefreshInterval: mpb.RefreshInterval_REFRESHINTERVAL_RESTART,
LastRefresh: startTime,
Value: strconv.FormatInt(bandwidth, 10),
DeviceId: adapterID,
},
)
}
return networkMetrics
}