summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/scaleio/collect_storage_pool.go
blob: 409be0bdbbdebc55157271306de94bb67fbdb498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: GPL-3.0-or-later

package scaleio

import "github.com/netdata/netdata/go/go.d.plugin/modules/scaleio/client"

func (s *ScaleIO) collectStoragePool(ss map[string]client.StoragePoolStatistics) map[string]storagePoolMetrics {
	ms := make(map[string]storagePoolMetrics, len(ss))

	for id, stats := range ss {
		pool, ok := s.discovered.pool[id]
		if !ok {
			continue
		}
		var pm storagePoolMetrics
		collectStoragePoolCapacity(&pm, stats, pool)
		collectStoragePoolComponents(&pm, stats)

		ms[id] = pm
	}
	return ms
}

func collectStoragePoolCapacity(pm *storagePoolMetrics, ps client.StoragePoolStatistics, pool client.StoragePool) {
	collectCapacity(&pm.Capacity.capacity, ps.CapacityStatistics)
	pm.Capacity.Utilization = calcCapacityUtilization(ps.CapacityInUseInKb, ps.MaxCapacityInKb, pool.SparePercentage)
	pm.Capacity.AlertThreshold.Critical = pool.CapacityAlertCriticalThreshold
	pm.Capacity.AlertThreshold.High = pool.CapacityAlertHighThreshold
}

func collectStoragePoolComponents(pm *storagePoolMetrics, ps client.StoragePoolStatistics) {
	pm.Components.Devices = ps.NumOfDevices
	pm.Components.Snapshots = ps.NumOfSnapshots
	pm.Components.Volumes = ps.NumOfVolumes
	pm.Components.Vtrees = ps.NumOfVtrees
}

func calcCapacityUtilization(inUse int64, max int64, sparePercent int64) float64 {
	spare := float64(max) / 100 * float64(sparePercent)
	return divFloat(float64(100*inUse), float64(max)-spare)
}