Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions receiver/vcenterreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ func (vc *vcenterClient) VAppInventoryListObjects(
return allVApps, nil
}

// PerfMetricsQueryResult contains performance metric related data
type PerfMetricsQueryResult struct {
// perfMetricsQueryResult contains performance metric related data
type perfMetricsQueryResult struct {
// Contains performance metrics keyed by MoRef string
resultsByRef map[string]*performance.EntityMetric
}
Expand All @@ -321,9 +321,9 @@ func (vc *vcenterClient) PerfMetricsQuery(
spec vt.PerfQuerySpec,
names []string,
objs []vt.ManagedObjectReference,
) (*PerfMetricsQueryResult, error) {
) (*perfMetricsQueryResult, error) {
if vc.pm == nil {
return &PerfMetricsQueryResult{}, nil
return &perfMetricsQueryResult{}, nil
}
vc.pm.Sort = true
sample, err := vc.pm.SampleByName(ctx, spec, names, objs)
Expand All @@ -339,27 +339,27 @@ func (vc *vcenterClient) PerfMetricsQuery(
for i := range result {
resultsByRef[result[i].Entity.Value] = &result[i]
}
return &PerfMetricsQueryResult{
return &perfMetricsQueryResult{
resultsByRef: resultsByRef,
}, nil
}

// VSANQueryResults contains all returned vSAN metric related data
type VSANQueryResults struct {
// vSANQueryResults contains all returned vSAN metric related data
type vSANQueryResults struct {
// Contains vSAN metric data keyed by UUID string
MetricResultsByUUID map[string]*VSANMetricResults
MetricResultsByUUID map[string]*vSANMetricResults
}

// VSANMetricResults contains vSAN metric related data for a single resource
type VSANMetricResults struct {
// vSANMetricResults contains vSAN metric related data for a single resource
type vSANMetricResults struct {
// Contains UUID info for related resource
UUID string
// Contains returned metric value info for all metrics
MetricDetails []*VSANMetricDetails
MetricDetails []*vSANMetricDetails
}

// VSANMetricDetails contains vSAN metric data for a single metric
type VSANMetricDetails struct {
// vSANMetricDetails contains vSAN metric data for a single metric
type vSANMetricDetails struct {
// Contains the metric label
MetricLabel string
// Contains the metric interval in seconds
Expand All @@ -374,25 +374,25 @@ type VSANMetricDetails struct {
type vSANQueryType string

const (
VSANQueryTypeClusters vSANQueryType = "cluster-domclient:*"
VSANQueryTypeHosts vSANQueryType = "host-domclient:*"
VSANQueryTypeVirtualMachines vSANQueryType = "virtual-machine:*"
vSANQueryTypeClusters vSANQueryType = "cluster-domclient:*"
vSANQueryTypeHosts vSANQueryType = "host-domclient:*"
vSANQueryTypeVirtualMachines vSANQueryType = "virtual-machine:*"
)

// getLabelsForQueryType returns the appropriate labels for each query type
func (vc *vcenterClient) getLabelsForQueryType(queryType vSANQueryType) []string {
switch queryType {
case VSANQueryTypeClusters:
case vSANQueryTypeClusters:
return []string{
"iopsRead", "iopsWrite", "throughputRead", "throughputWrite",
"latencyAvgRead", "latencyAvgWrite", "congestion",
}
case VSANQueryTypeHosts:
case vSANQueryTypeHosts:
return []string{
"iopsRead", "iopsWrite", "throughputRead", "throughputWrite",
"latencyAvgRead", "latencyAvgWrite", "congestion", "clientCacheHitRate",
}
case VSANQueryTypeVirtualMachines:
case vSANQueryTypeVirtualMachines:
return []string{
"iopsRead", "iopsWrite", "throughputRead", "throughputWrite",
"latencyRead", "latencyWrite",
Expand All @@ -406,29 +406,29 @@ func (vc *vcenterClient) getLabelsForQueryType(queryType vSANQueryType) []string
func (vc *vcenterClient) VSANClusters(
ctx context.Context,
clusterRefs []*vt.ManagedObjectReference,
) (*VSANQueryResults, error) {
results, err := vc.vSANQuery(ctx, VSANQueryTypeClusters, clusterRefs)
err = vc.handleVSANError(err, VSANQueryTypeClusters)
) (*vSANQueryResults, error) {
results, err := vc.vSANQuery(ctx, vSANQueryTypeClusters, clusterRefs)
err = vc.handleVSANError(err, vSANQueryTypeClusters)
return results, err
}

// VSANHosts returns host VSAN performance metrics for a group of clusters
func (vc *vcenterClient) VSANHosts(
ctx context.Context,
clusterRefs []*vt.ManagedObjectReference,
) (*VSANQueryResults, error) {
results, err := vc.vSANQuery(ctx, VSANQueryTypeHosts, clusterRefs)
err = vc.handleVSANError(err, VSANQueryTypeHosts)
) (*vSANQueryResults, error) {
results, err := vc.vSANQuery(ctx, vSANQueryTypeHosts, clusterRefs)
err = vc.handleVSANError(err, vSANQueryTypeHosts)
return results, err
}

// VSANVirtualMachines returns virtual machine vSAN performance metrics for a group of clusters
func (vc *vcenterClient) VSANVirtualMachines(
ctx context.Context,
clusterRefs []*vt.ManagedObjectReference,
) (*VSANQueryResults, error) {
results, err := vc.vSANQuery(ctx, VSANQueryTypeVirtualMachines, clusterRefs)
err = vc.handleVSANError(err, VSANQueryTypeVirtualMachines)
) (*vSANQueryResults, error) {
results, err := vc.vSANQuery(ctx, vSANQueryTypeVirtualMachines, clusterRefs)
err = vc.handleVSANError(err, vSANQueryTypeVirtualMachines)
return results, err
}

Expand All @@ -437,9 +437,9 @@ func (vc *vcenterClient) vSANQuery(
ctx context.Context,
queryType vSANQueryType,
clusterRefs []*vt.ManagedObjectReference,
) (*VSANQueryResults, error) {
allResults := VSANQueryResults{
MetricResultsByUUID: map[string]*VSANMetricResults{},
) (*vSANQueryResults, error) {
allResults := vSANQueryResults{
MetricResultsByUUID: map[string]*vSANMetricResults{},
}

for _, clusterRef := range clusterRefs {
Expand All @@ -459,9 +459,9 @@ func (vc *vcenterClient) vSANQueryByCluster(
ctx context.Context,
queryType vSANQueryType,
clusterRef *vt.ManagedObjectReference,
) (*VSANQueryResults, error) {
queryResults := VSANQueryResults{
MetricResultsByUUID: map[string]*VSANMetricResults{},
) (*vSANQueryResults, error) {
queryResults := vSANQueryResults{
MetricResultsByUUID: map[string]*vSANMetricResults{},
}
// Not all vCenters support vSAN so just return an empty result
if vc.vsanDriver == nil {
Expand All @@ -482,7 +482,7 @@ func (vc *vcenterClient) vSANQueryByCluster(
return nil, fmt.Errorf("problem retrieving %s vSAN metrics for cluster %s: %w", queryType, clusterRef.Value, err)
}

queryResults.MetricResultsByUUID = map[string]*VSANMetricResults{}
queryResults.MetricResultsByUUID = map[string]*vSANMetricResults{}
for _, rawResult := range rawResults {
metricResults, err := vc.convertVSANResultToMetricResults(rawResult)
if err != nil && metricResults != nil {
Expand Down Expand Up @@ -527,15 +527,15 @@ func (vc *vcenterClient) handleVSANError(
}
}

func (vc *vcenterClient) convertVSANResultToMetricResults(vSANResult types.VsanPerfEntityMetricCSV) (*VSANMetricResults, error) {
func (vc *vcenterClient) convertVSANResultToMetricResults(vSANResult types.VsanPerfEntityMetricCSV) (*vSANMetricResults, error) {
uuid, err := vc.uuidFromEntityRefID(vSANResult.EntityRefId)
if err != nil {
return nil, err
}

metricResults := VSANMetricResults{
metricResults := vSANMetricResults{
UUID: uuid,
MetricDetails: []*VSANMetricDetails{},
MetricDetails: []*vSANMetricDetails{},
}

// Parse all timestamps
Expand Down Expand Up @@ -569,15 +569,15 @@ func (vc *vcenterClient) convertVSANResultToMetricResults(vSANResult types.VsanP
func (vc *vcenterClient) convertVSANValueToMetricDetails(
vSANValue types.VsanPerfMetricSeriesCSV,
timestamps []time.Time,
) (*VSANMetricDetails, error) {
) (*vSANMetricDetails, error) {
metricLabel := vSANValue.MetricId.Label
metricInterval := vSANValue.MetricId.MetricsCollectInterval
// If not found assume the interval is 5m
if metricInterval == 0 {
vc.logger.Warn(fmt.Sprintf("no interval found for vSAN metric [%s] so assuming 5m", metricLabel))
metricInterval = 300
}
metricDetails := VSANMetricDetails{
metricDetails := vSANMetricDetails{
MetricLabel: metricLabel,
Interval: metricInterval,
Timestamps: []*time.Time{},
Expand Down
6 changes: 3 additions & 3 deletions receiver/vcenterreceiver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (v *vcenterMetricScraper) recordClusterStats(
}

// recordClusterVSANMetrics records vSAN metrics for a vSphere Cluster
func (v *vcenterMetricScraper) recordClusterVSANMetrics(vSANMetrics *VSANMetricResults) {
func (v *vcenterMetricScraper) recordClusterVSANMetrics(vSANMetrics *vSANMetricResults) {
for _, metric := range vSANMetrics.MetricDetails {
for i, value := range metric.Values {
timestamp := metric.Timestamps[i]
Expand Down Expand Up @@ -223,7 +223,7 @@ func (v *vcenterMetricScraper) recordHostSystemStats(
}

// recordHostVSANMetrics records vSAN metrics for a vSphere host
func (v *vcenterMetricScraper) recordHostVSANMetrics(vSANMetrics *VSANMetricResults) {
func (v *vcenterMetricScraper) recordHostVSANMetrics(vSANMetrics *vSANMetricResults) {
for _, metric := range vSANMetrics.MetricDetails {
for i, value := range metric.Values {
timestamp := metric.Timestamps[i]
Expand Down Expand Up @@ -497,7 +497,7 @@ func (v *vcenterMetricScraper) recordVMPerformanceMetrics(entityMetric *performa
}

// recordVMVSANMetrics records vSAN metrics for a vSphere Virtual Machine
func (v *vcenterMetricScraper) recordVMVSANMetrics(vSANMetrics *VSANMetricResults) {
func (v *vcenterMetricScraper) recordVMVSANMetrics(vSANMetrics *vSANMetricResults) {
for _, metric := range vSANMetrics.MetricDetails {
for i, value := range metric.Values {
timestamp := metric.Timestamps[i]
Expand Down
12 changes: 6 additions & 6 deletions receiver/vcenterreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type vcenterScrapeData struct {
hostPerfMetricsByRef map[string]*performance.EntityMetric
vmsByRef map[string]*mo.VirtualMachine
vmPerfMetricsByRef map[string]*performance.EntityMetric
vmVSANMetricsByUUID map[string]*VSANMetricResults
hostVSANMetricsByUUID map[string]*VSANMetricResults
clusterVSANMetricsByUUID map[string]*VSANMetricResults
vmVSANMetricsByUUID map[string]*vSANMetricResults
hostVSANMetricsByUUID map[string]*vSANMetricResults
clusterVSANMetricsByUUID map[string]*vSANMetricResults
}

type vcenterMetricScraper struct {
Expand Down Expand Up @@ -82,9 +82,9 @@ func newVcenterScrapeData() *vcenterScrapeData {
rPoolsByRef: make(map[string]*mo.ResourcePool),
vmsByRef: make(map[string]*mo.VirtualMachine),
vmPerfMetricsByRef: make(map[string]*performance.EntityMetric),
vmVSANMetricsByUUID: make(map[string]*VSANMetricResults),
hostVSANMetricsByUUID: make(map[string]*VSANMetricResults),
clusterVSANMetricsByUUID: make(map[string]*VSANMetricResults),
vmVSANMetricsByUUID: make(map[string]*vSANMetricResults),
hostVSANMetricsByUUID: make(map[string]*vSANMetricResults),
clusterVSANMetricsByUUID: make(map[string]*vSANMetricResults),
}
}

Expand Down