From 5c66e30ac2d6dd3deba6fff02021f603d98b4857 Mon Sep 17 00:00:00 2001 From: Maksim Kiselev Date: Tue, 14 Jun 2022 20:11:38 +0300 Subject: [PATCH] Export domain autostart --- libvirt_exporter.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libvirt_exporter.go b/libvirt_exporter.go index 53466ae..6fe6148 100644 --- a/libvirt_exporter.go +++ b/libvirt_exporter.go @@ -102,6 +102,12 @@ var ( "6: the domain is crashed, 7: the domain is suspended by guest power management", []string{"host", "domain"}, nil) + libvirtDomainInfoAutoStart = prometheus.NewDesc( + prometheus.BuildFQName("libvirt", "domain_info", "autostart_enabled"), + "Is autostart enabled for domain.", + []string{"host", "domain"}, + nil) + libvirtDomainVcpuTimeDesc = prometheus.NewDesc( prometheus.BuildFQName("libvirt", "domain_vcpu", "time_seconds_total"), @@ -434,6 +440,16 @@ func CollectDomain(ch chan<- prometheus.Metric, stat libvirt.DomainStats, hostNa return err } + // Report domain autostart. + autostart, err := stat.Domain.GetAutostart() + if err != nil { + return err + } + autostart_int := 0 + if autostart { + autostart_int = 1 + } + ch <- prometheus.MustNewConstMetric( libvirtDomainInfoMetaDesc, prometheus.GaugeValue, @@ -479,6 +495,12 @@ func CollectDomain(ch chan<- prometheus.Metric, stat libvirt.DomainStats, hostNa float64(info.State), hostName, domainName) + ch <- prometheus.MustNewConstMetric( + libvirtDomainInfoAutoStart, + prometheus.GaugeValue, + float64(autostart_int), + hostName, + domainName) domainStatsVcpu, err := stat.Domain.GetVcpus() if err != nil { @@ -1223,6 +1245,7 @@ func (e *LibvirtExporter) Describe(ch chan<- *prometheus.Desc) { ch <- libvirtDomainInfoNrVirtCPUDesc ch <- libvirtDomainInfoCPUTimeDesc ch <- libvirtDomainInfoVirDomainState + ch <- libvirtDomainInfoAutoStart // VCPU info ch <- libvirtDomainVcpuStateDesc