master
go 129 lines 3.2 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package adaptecraid
4
5 import (
6 "fmt"
7 "strconv"
8
9 "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi"
10 )
11
12 const (
13 prioLDStatus = collectorapi.Priority + iota
14
15 prioPDState
16 prioPDSmartWarnings
17 prioPDSmartTemperature
18 )
19
20 var ldChartsTmpl = collectorapi.Charts{
21 ldStatusChartTmpl.Copy(),
22 }
23
24 var (
25 ldStatusChartTmpl = collectorapi.Chart{
26 ID: "logical_device_%s_status",
27 Title: "Logical Device status",
28 Units: "status",
29 Fam: "ld health",
30 Ctx: "adaptecraid.logical_device_status",
31 Type: collectorapi.Line,
32 Priority: prioLDStatus,
33 Dims: collectorapi.Dims{
34 {ID: "ld_%s_health_state_ok", Name: "ok"},
35 {ID: "ld_%s_health_state_critical", Name: "critical"},
36 },
37 }
38 )
39
40 var pdChartsTmpl = collectorapi.Charts{
41 pdStateChartTmpl.Copy(),
42 pdSmartWarningChartTmpl.Copy(),
43 pdTemperatureChartTmpl.Copy(),
44 }
45
46 var (
47 pdStateChartTmpl = collectorapi.Chart{
48 ID: "physical_device_%s_state",
49 Title: "Physical Device state",
50 Units: "state",
51 Fam: "pd health",
52 Ctx: "adaptecraid.physical_device_state",
53 Type: collectorapi.Line,
54 Priority: prioPDState,
55 Dims: collectorapi.Dims{
56 {ID: "pd_%s_health_state_ok", Name: "ok"},
57 {ID: "pd_%s_health_state_critical", Name: "critical"},
58 },
59 }
60 pdSmartWarningChartTmpl = collectorapi.Chart{
61 ID: "physical_device_%s_smart_warnings",
62 Title: "Physical Device SMART warnings",
63 Units: "warnings",
64 Fam: "pd smart",
65 Ctx: "adaptecraid.physical_device_smart_warnings",
66 Type: collectorapi.Line,
67 Priority: prioPDSmartWarnings,
68 Dims: collectorapi.Dims{
69 {ID: "pd_%s_smart_warnings", Name: "smart"},
70 },
71 }
72 pdTemperatureChartTmpl = collectorapi.Chart{
73 ID: "physical_device_%s_temperature",
74 Title: "Physical Device temperature",
75 Units: "Celsius",
76 Fam: "pd temperature",
77 Ctx: "adaptecraid.physical_device_temperature",
78 Type: collectorapi.Line,
79 Priority: prioPDSmartTemperature,
80 Dims: collectorapi.Dims{
81 {ID: "pd_%s_temperature", Name: "temperature"},
82 },
83 }
84 )
85
86 func (c *Collector) addLogicalDeviceCharts(ld *logicalDevice) {
87 charts := ldChartsTmpl.Copy()
88
89 for _, chart := range *charts {
90 chart.ID = fmt.Sprintf(chart.ID, ld.number)
91 chart.Labels = []collectorapi.Label{
92 {Key: "ld_number", Value: ld.number},
93 {Key: "ld_name", Value: ld.name},
94 {Key: "raid_level", Value: ld.raidLevel},
95 }
96 for _, dim := range chart.Dims {
97 dim.ID = fmt.Sprintf(dim.ID, ld.number)
98 }
99 }
100
101 if err := c.Charts().Add(*charts...); err != nil {
102 c.Warning(err)
103 }
104 }
105
106 func (c *Collector) addPhysicalDeviceCharts(pd *physicalDevice) {
107 charts := pdChartsTmpl.Copy()
108
109 if _, err := strconv.ParseInt(pd.temperature, 10, 64); err != nil {
110 _ = charts.Remove(pdTemperatureChartTmpl.ID)
111 }
112
113 for _, chart := range *charts {
114 chart.ID = fmt.Sprintf(chart.ID, pd.number)
115 chart.Labels = []collectorapi.Label{
116 {Key: "pd_number", Value: pd.number},
117 {Key: "location", Value: pd.location},
118 {Key: "vendor", Value: pd.vendor},
119 {Key: "model", Value: pd.model},
120 }
121 for _, dim := range chart.Dims {
122 dim.ID = fmt.Sprintf(dim.ID, pd.number)
123 }
124 }
125
126 if err := c.Charts().Add(*charts...); err != nil {
127 c.Warning(err)
128 }
129 }