@@ -3,27 +3,43 @@ package exporter
33import (
44 "log"
55 "strconv"
6+
7+ "github.com/prometheus/client_golang/prometheus"
68)
79
810type StorageInventoryCollector struct {
9- endpoint string
11+ endpoint string
12+ metricsDropper * MetricsDropper
1013}
1114
1215func NewStorageInventoryCollector (endpoint string ) * StorageInventoryCollector {
1316 return & StorageInventoryCollector {
1417 endpoint : endpoint ,
18+ metricsDropper : NewMetricsDropper (
19+ StorageInventory ,
20+ StorageInventoryMax ,
21+ ),
1522 }
1623}
1724
1825func (c * StorageInventoryCollector ) Collect (frmAddress string , sessionName string ) {
1926 details := []ContainerDetail {}
2027 err := retrieveData (frmAddress + c .endpoint , & details )
2128 if err != nil {
29+ c .metricsDropper .DropStaleMetricLabels ()
2230 log .Printf ("error reading inventory statistics from FRM: %s\n " , err )
2331 return
2432 }
2533
2634 for _ , detail := range details {
35+ c .metricsDropper .CacheFreshMetricLabel (prometheus.Labels {
36+ "url" : frmAddress ,
37+ "session_name" : sessionName ,
38+ "container_name" : detail .Name ,
39+ "x" : strconv .FormatFloat (detail .Location .X , 'f' , - 1 , 64 ),
40+ "y" : strconv .FormatFloat (detail .Location .Y , 'f' , - 1 , 64 ),
41+ "z" : strconv .FormatFloat (detail .Location .Z , 'f' , - 1 , 64 ),
42+ })
2743 for _ , item := range detail .Inventory {
2844 StorageInventory .WithLabelValues (
2945 item .Name ,
@@ -36,6 +52,7 @@ func (c *StorageInventoryCollector) Collect(frmAddress string, sessionName strin
3652 ).Set (float64 (item .Amount ))
3753 }
3854 }
55+ c .metricsDropper .DropStaleMetricLabels ()
3956}
4057
4158func (c * StorageInventoryCollector ) DropCache () {}
0 commit comments