@@ -2,13 +2,15 @@ package metricscollector
2
2
3
3
import (
4
4
"github.com/pkg/errors"
5
+ "github.com/prometheus/client_golang/prometheus"
5
6
"github.com/sirupsen/logrus"
6
7
7
- "github.com/prometheus/client_golang/prometheus "
8
+ imtypes "github.com/longhorn/longhorn-instance-manager/pkg/types "
8
9
9
10
"github.com/longhorn/longhorn-manager/controller"
10
11
"github.com/longhorn/longhorn-manager/datastore"
11
12
"github.com/longhorn/longhorn-manager/engineapi"
13
+ "github.com/longhorn/longhorn-manager/types"
12
14
"github.com/longhorn/longhorn-manager/util"
13
15
14
16
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
@@ -19,10 +21,11 @@ type VolumeCollector struct {
19
21
20
22
proxyConnCounter util.Counter
21
23
22
- capacityMetric metricInfo
23
- sizeMetric metricInfo
24
- stateMetric metricInfo
25
- robustnessMetric metricInfo
24
+ capacityMetric metricInfo
25
+ sizeMetric metricInfo
26
+ stateMetric metricInfo
27
+ robustnessMetric metricInfo
28
+ fileSystemReadOnlyMetric metricInfo
26
29
27
30
volumePerfMetrics
28
31
}
@@ -48,6 +51,16 @@ func NewVolumeCollector(
48
51
proxyConnCounter : util .NewAtomicCounter (),
49
52
}
50
53
54
+ vc .fileSystemReadOnlyMetric = metricInfo {
55
+ Desc : prometheus .NewDesc (
56
+ prometheus .BuildFQName (longhornName , subsystemVolume , "file_system_read_only" ),
57
+ "Volume whose mount point is in read-only mode" ,
58
+ []string {nodeLabel , volumeLabel , pvcLabel , pvcNamespaceLabel },
59
+ nil ,
60
+ ),
61
+ Type : prometheus .GaugeValue ,
62
+ }
63
+
51
64
vc .capacityMetric = metricInfo {
52
65
Desc : prometheus .NewDesc (
53
66
prometheus .BuildFQName (longhornName , subsystemVolume , "capacity_bytes" ),
@@ -156,6 +169,7 @@ func (vc *VolumeCollector) Describe(ch chan<- *prometheus.Desc) {
156
169
ch <- vc .sizeMetric .Desc
157
170
ch <- vc .stateMetric .Desc
158
171
ch <- vc .robustnessMetric .Desc
172
+ ch <- vc .fileSystemReadOnlyMetric .Desc
159
173
}
160
174
161
175
func (vc * VolumeCollector ) Collect (ch chan <- prometheus.Metric ) {
@@ -214,6 +228,18 @@ func (vc *VolumeCollector) collectMetrics(ch chan<- prometheus.Metric, v *longho
214
228
ch <- prometheus .MustNewConstMetric (vc .volumePerfMetrics .iopsMetrics .write .Desc , vc .volumePerfMetrics .iopsMetrics .write .Type , float64 (vc .getVolumeWriteIOPS (metrics )), vc .currentNodeID , v .Name , v .Status .KubernetesStatus .PVCName , v .Status .KubernetesStatus .Namespace )
215
229
ch <- prometheus .MustNewConstMetric (vc .volumePerfMetrics .latencyMetrics .read .Desc , vc .volumePerfMetrics .latencyMetrics .read .Type , float64 (vc .getVolumeReadLatency (metrics )), vc .currentNodeID , v .Name , v .Status .KubernetesStatus .PVCName , v .Status .KubernetesStatus .Namespace )
216
230
ch <- prometheus .MustNewConstMetric (vc .volumePerfMetrics .latencyMetrics .write .Desc , vc .volumePerfMetrics .latencyMetrics .write .Type , float64 (vc .getVolumeWriteLatency (metrics )), vc .currentNodeID , v .Name , v .Status .KubernetesStatus .PVCName , v .Status .KubernetesStatus .Namespace )
231
+
232
+ fileSystemReadOnlyCondition := types .GetCondition (e .Status .Conditions , imtypes .EngineConditionFilesystemReadOnly )
233
+ isPVMountOptionReadOnly , err := vc .ds .IsPVMountOptionReadOnly (v )
234
+ if err != nil {
235
+ vc .logger .WithError (err ).Warn ("Failed to check if volume's PV mount option is read only during metric collection" )
236
+ return
237
+ }
238
+
239
+ if fileSystemReadOnlyCondition .Status == longhorn .ConditionStatusTrue && ! isPVMountOptionReadOnly {
240
+ ch <- prometheus .MustNewConstMetric (vc .fileSystemReadOnlyMetric .Desc , vc .fileSystemReadOnlyMetric .Type , float64 (1 ), vc .currentNodeID , v .Name , v .Status .KubernetesStatus .PVCName , v .Status .KubernetesStatus .Namespace )
241
+ }
242
+
217
243
}
218
244
219
245
func (vc * VolumeCollector ) getEngineClientProxy (engine * longhorn.Engine ) (c engineapi.EngineClientProxy , err error ) {
0 commit comments