Skip to content

Commit

Permalink
Export domain autostart
Browse files Browse the repository at this point in the history
  • Loading branch information
trublast committed Jun 14, 2022
1 parent 62b2f6b commit 5c66e30
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libvirt_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1223,6 +1245,7 @@ func (e *LibvirtExporter) Describe(ch chan<- *prometheus.Desc) {
ch <- libvirtDomainInfoNrVirtCPUDesc
ch <- libvirtDomainInfoCPUTimeDesc
ch <- libvirtDomainInfoVirDomainState
ch <- libvirtDomainInfoAutoStart

// VCPU info
ch <- libvirtDomainVcpuStateDesc
Expand Down

0 comments on commit 5c66e30

Please sign in to comment.