master
go 68 lines 1.75 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build linux || netbsd
4
5 package lvm
6
7 import (
8 "fmt"
9
10 "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi"
11 )
12
13 const (
14 prioLVDataPercent = 2920 + iota
15 prioLVMetadataPercent
16 )
17
18 var lvThinPoolChartsTmpl = collectorapi.Charts{
19 lvDataSpaceUtilizationChartTmpl.Copy(),
20 lvMetadataSpaceUtilizationChartTmpl.Copy(),
21 }
22
23 var (
24 lvDataSpaceUtilizationChartTmpl = collectorapi.Chart{
25 ID: "lv_%s_vg_%s_lv_data_space_utilization",
26 Title: "Logical volume space allocated for data",
27 Units: "percentage",
28 Fam: "lv space usage",
29 Ctx: "lvm.lv_data_space_utilization",
30 Type: collectorapi.Area,
31 Priority: prioLVDataPercent,
32 Dims: collectorapi.Dims{
33 {ID: "lv_%s_vg_%s_data_percent", Name: "utilization", Div: 100},
34 },
35 }
36 lvMetadataSpaceUtilizationChartTmpl = collectorapi.Chart{
37 ID: "lv_%s_vg_%s_lv_metadata_space_utilization",
38 Title: "Logical volume space allocated for metadata",
39 Units: "percentage",
40 Fam: "lv space usage",
41 Ctx: "lvm.lv_metadata_space_utilization",
42 Type: collectorapi.Area,
43 Priority: prioLVMetadataPercent,
44 Dims: collectorapi.Dims{
45 {ID: "lv_%s_vg_%s_metadata_percent", Name: "utilization", Div: 100},
46 },
47 }
48 )
49
50 func (c *Collector) addLVMThinPoolCharts(lvName, vgName string) {
51 charts := lvThinPoolChartsTmpl.Copy()
52
53 for _, chart := range *charts {
54 chart.ID = fmt.Sprintf(chart.ID, lvName, vgName)
55 chart.Labels = []collectorapi.Label{
56 {Key: "lv_name", Value: lvName},
57 {Key: "vg_name", Value: vgName},
58 {Key: "volume_type", Value: "thin_pool"},
59 }
60 for _, dim := range chart.Dims {
61 dim.ID = fmt.Sprintf(dim.ID, lvName, vgName)
62 }
63 }
64
65 if err := c.Charts().Add(*charts...); err != nil {
66 c.Warning(err)
67 }
68 }