@@ -193,6 +193,28 @@ var (
193
193
[]string {"domain" , "vcpu" },
194
194
nil )
195
195
196
+ // storage pool stats
197
+ libvirtStoragePoolState = prometheus .NewDesc (
198
+ prometheus .BuildFQName (namespace , "storage_pool" , "state" ),
199
+ "State of the storage pool." ,
200
+ []string {"storage_pool" },
201
+ nil )
202
+ libvirtStoragePoolCapacity = prometheus .NewDesc (
203
+ prometheus .BuildFQName (namespace , "storage_pool" , "capacity_bytes" ),
204
+ "Size of the storage pool in logical bytes." ,
205
+ []string {"storage_pool" },
206
+ nil )
207
+ libvirtStoragePoolAllocation = prometheus .NewDesc (
208
+ prometheus .BuildFQName (namespace , "storage_pool" , "allocation_bytes" ),
209
+ "Current allocation bytes of the storage pool." ,
210
+ []string {"storage_pool" },
211
+ nil )
212
+ libvirtStoragePoolAvailable = prometheus .NewDesc (
213
+ prometheus .BuildFQName (namespace , "storage_pool" , "available_bytes" ),
214
+ "Remaining free space of the storage pool in bytes." ,
215
+ []string {"storage_pool" },
216
+ nil )
217
+
196
218
// info metrics
197
219
libvirtDomainInfoDesc = prometheus .NewDesc (
198
220
prometheus .BuildFQName (namespace , "domain" , "info" ),
@@ -347,6 +369,21 @@ func CollectFromLibvirt(ch chan<- prometheus.Metric, uri string, driver libvirt.
347
369
return err
348
370
}
349
371
}
372
+
373
+ // collect storage pool metrics
374
+ // see https://libvirt.org/html/libvirt-libvirt-storage.html
375
+ var pools []libvirt.StoragePool
376
+ if pools , _ , err = l .ConnectListAllStoragePools (1 , 0 ); err != nil {
377
+ _ = level .Error (logger ).Log ("err" , "failed to collect storage pools" , "msg" , err )
378
+ return err
379
+ }
380
+ for _ , pool := range pools {
381
+ if err = CollectStoragePoolInfo (ch , l , pool , logger ); err != nil {
382
+ _ = level .Error (logger ).Log ("err" , "failed to collect storage pool info" , "msg" , err )
383
+ return err
384
+ }
385
+ }
386
+
350
387
return nil
351
388
}
352
389
@@ -652,6 +689,41 @@ func CollectDomainVCPUInfo(ch chan<- prometheus.Metric, l *libvirt.Libvirt, doma
652
689
return
653
690
}
654
691
692
+ func CollectStoragePoolInfo (ch chan <- prometheus.Metric , l * libvirt.Libvirt , pool libvirt.StoragePool , logger log.Logger ) (err error ) {
693
+ // Report storage pool metrics
694
+ var rState uint8
695
+ var rCapacity , rAllocation , rAvailable uint64
696
+
697
+ promLabels := []string {
698
+ pool .Name ,
699
+ }
700
+ if rState , rCapacity , rAllocation , rAvailable , err = l .StoragePoolGetInfo (pool ); err != nil {
701
+ _ = level .Warn (logger ).Log ("warn" , "failed to get StoragePoolInfo for pool" , "pool" , pool .Name , "msg" , err )
702
+ return err
703
+ }
704
+ ch <- prometheus .MustNewConstMetric (
705
+ libvirtStoragePoolState ,
706
+ prometheus .GaugeValue ,
707
+ float64 (rState ),
708
+ promLabels ... )
709
+ ch <- prometheus .MustNewConstMetric (
710
+ libvirtStoragePoolCapacity ,
711
+ prometheus .GaugeValue ,
712
+ float64 (rCapacity ),
713
+ promLabels ... )
714
+ ch <- prometheus .MustNewConstMetric (
715
+ libvirtStoragePoolAllocation ,
716
+ prometheus .GaugeValue ,
717
+ float64 (rAllocation ),
718
+ promLabels ... )
719
+ ch <- prometheus .MustNewConstMetric (
720
+ libvirtStoragePoolAvailable ,
721
+ prometheus .GaugeValue ,
722
+ float64 (rAvailable ),
723
+ promLabels ... )
724
+ return
725
+ }
726
+
655
727
// Describe returns metadata for all Prometheus metrics that may be exported.
656
728
func (e * LibvirtExporter ) Describe (ch chan <- * prometheus.Desc ) {
657
729
ch <- libvirtUpDesc
@@ -700,4 +772,10 @@ func (e *LibvirtExporter) Describe(ch chan<- *prometheus.Desc) {
700
772
ch <- libvirtDomainVCPUStatsTime
701
773
ch <- libvirtDomainVCPUStatsWait
702
774
ch <- libvirtDomainVCPUStatsDelay
775
+
776
+ //storage pool metrics
777
+ ch <- libvirtStoragePoolState
778
+ ch <- libvirtStoragePoolCapacity
779
+ ch <- libvirtStoragePoolAllocation
780
+ ch <- libvirtStoragePoolAvailable
703
781
}
0 commit comments