Skip to content

Commit

Permalink
Add libvirt_domain_job metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Коробов Сергей Викторович authored and frittentheke committed Dec 11, 2024
1 parent 7912c75 commit 204c59e
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ libvirt_domain_interface_stats_transmit_bytes_total | "domain", "target_device"
libvirt_domain_interface_stats_transmit_packets_total | "domain", "target_device" | Number of packets transmitted on a network interface
libvirt_domain_interface_stats_transmit_errors_total | "domain", "target_device" | Number of packet transmit errors on a network interface
libvirt_domain_interface_stats_transmit_drops_total | "domain", "target_device" | Number of packet transmit drops on a network interface
libvirt_domain_job_type | "domain" | Code of the domain job type
libvirt_domain_job_time_elapsed_seconds | "domain" | Time elapsed since the start of the domain job
libvirt_domain_job_time_remaining_seconds | "domain" | Time remaining until the end of the domain job
libvirt_domain_job_data_total_bytes | "domain" | Data total of the domain job
libvirt_domain_job_data_processed_bytes | "domain" | Data processed of the domain job
libvirt_domain_job_data_remaining_bytes | "domain" | Data remaining of the domain job
libvirt_domain_job_mem_total_bytes | "domain" | Memory total of the domain job
libvirt_domain_job_mem_processed_bytes | "domain" | Memory processed of the domain job
libvirt_domain_job_mem_remaining_bytes | "domain" | Memory remaining of the domain job
libvirt_domain_job_file_total_bytes | "domain" | File total of the domain job
libvirt_domain_job_file_processed_bytes | "domain" | File processed of the domain job
libvirt_domain_job_file_remaining_bytes | "domain" | File remaining of the domain job
libvirt_domain_vcpu_current | "domain" | Number of current online vCPUs
libvirt_domain_vcpu_delay_seconds_total | "domain", "vcpu" | Time the vCPU spent waiting in the queue instead of running. Exposed to the VM as steal time
libvirt_domain_vcpu_maximum | "domain" | Number of maximum online vCPUs
Expand Down
152 changes: 151 additions & 1 deletion pkg/exporter/prometheus-libvirt-exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,68 @@ var (
[]string{"domain"},
nil)

//domain job info
libvirtDomainJobTypeDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "type"),
"Code of the domain job type",
[]string{"domain"},
nil)
libvirtDomainJobTimeElapsedDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "time_elapsed_seconds"),
"Time elapsed since the start of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobTimeRemainingDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "time_remaining_seconds"),
"Time remaining until the end of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobDataTotalDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "data_total_bytes"),
"Data total of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobDataProcessedDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "data_processed_bytes"),
"Data processed of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobDataRemainingDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "data_remaining_bytes"),
"Data remaining of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobMemTotalDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "memory_total_bytes"),
"Memory total of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobMemProcessedDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "memory_processed_bytes"),
"Memory processed of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobMemRemainingDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "memory_remaining_bytes"),
"Memory remaining of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobFileTotalDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "file_total_bytes"),
"File total of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobFileProcessedDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "file_processed_bytes"),
"File processed of the domain job",
[]string{"domain"},
nil)
libvirtDomainJobFileRemainingDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_job_info", "file_remaining_bytes"),
"File remaining of the domain job",
[]string{"domain"},
nil)

//domain memory stats
libvirtDomainMemoryStatsSwapInBytesDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "domain_memory_stats", "swap_in_bytes"),
Expand Down Expand Up @@ -440,7 +502,7 @@ func CollectDomain(ch chan<- prometheus.Metric, l *libvirt.Libvirt, domain domai
return nil
}

for _, collectFunc := range []collectFunc{CollectDomainBlockDeviceInfo, CollectDomainNetworkInfo, CollectDomainMemoryStatInfo, CollectDomainVCPUInfo} {
for _, collectFunc := range []collectFunc{CollectDomainBlockDeviceInfo, CollectDomainNetworkInfo, CollectDomainJobInfo, CollectDomainMemoryStatInfo, CollectDomainVCPUInfo} {
if err = collectFunc(ch, l, domain, promLabels, logger); err != nil {
_ = level.Warn(logger).Log("warn", "failed to collect some domain info", "domain", domain.libvirtDomain.Name, "msg", err)
}
Expand Down Expand Up @@ -568,6 +630,80 @@ func CollectDomainNetworkInfo(ch chan<- prometheus.Metric, l *libvirt.Libvirt, d
return
}

func CollectDomainJobInfo(ch chan<- prometheus.Metric, l *libvirt.Libvirt, domain domainMeta, promLabels []string, logger log.Logger) (err error) {
var rType int32
var rTimeElapsed, rTimeRemaining, rDataTotal, rDataProcessed, rDataRemaining, rMemTotal,
rMemProcessed, rMemRemaining, rFileTotal, rFileProcessed, rFileRemaining uint64

if rType, rTimeElapsed, rTimeRemaining, rDataTotal, rDataProcessed, rDataRemaining,
rMemTotal, rMemProcessed, rMemRemaining, rFileTotal, rFileProcessed, rFileRemaining, err = l.DomainGetJobInfo(domain.libvirtDomain); err != nil {
_ = level.Warn(logger).Log("warn", "failed to get job info", "domain", domain.libvirtDomain.Name, "msg", err)
return err
}

ch <- prometheus.MustNewConstMetric(
libvirtDomainJobTypeDesc,
prometheus.GaugeValue,
float64(rType),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobTimeElapsedDesc,
prometheus.GaugeValue,
float64(rTimeElapsed),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobTimeRemainingDesc,
prometheus.GaugeValue,
float64(rTimeRemaining),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobDataTotalDesc,
prometheus.GaugeValue,
float64(rDataTotal),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobDataProcessedDesc,
prometheus.GaugeValue,
float64(rDataProcessed),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobDataRemainingDesc,
prometheus.GaugeValue,
float64(rDataRemaining),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobMemTotalDesc,
prometheus.GaugeValue,
float64(rMemTotal),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobMemProcessedDesc,
prometheus.GaugeValue,
float64(rMemProcessed),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobMemRemainingDesc,
prometheus.GaugeValue,
float64(rMemRemaining),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobFileTotalDesc,
prometheus.GaugeValue,
float64(rFileTotal),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobFileProcessedDesc,
prometheus.GaugeValue,
float64(rFileProcessed),
promLabels...)
ch <- prometheus.MustNewConstMetric(
libvirtDomainJobFileRemainingDesc,
prometheus.GaugeValue,
float64(rFileRemaining),
promLabels...)
return
}

func CollectDomainMemoryStatInfo(ch chan<- prometheus.Metric, l *libvirt.Libvirt, domain domainMeta, promLabels []string, logger log.Logger) (err error) {
//collect stat info
var rStats []libvirt.DomainMemoryStat
Expand Down Expand Up @@ -757,6 +893,20 @@ func (e *LibvirtExporter) Describe(ch chan<- *prometheus.Desc) {
ch <- libvirtDomainInterfaceTxErrsDesc
ch <- libvirtDomainInterfaceTxDropDesc

//domain job
ch <- libvirtDomainJobTypeDesc
ch <- libvirtDomainJobTimeElapsedDesc
ch <- libvirtDomainJobTimeRemainingDesc
ch <- libvirtDomainJobDataTotalDesc
ch <- libvirtDomainJobDataProcessedDesc
ch <- libvirtDomainJobDataRemainingDesc
ch <- libvirtDomainJobMemTotalDesc
ch <- libvirtDomainJobMemProcessedDesc
ch <- libvirtDomainJobMemRemainingDesc
ch <- libvirtDomainJobFileTotalDesc
ch <- libvirtDomainJobFileProcessedDesc
ch <- libvirtDomainJobFileRemainingDesc

//domain mem stat
ch <- libvirtDomainMemoryStatsSwapInBytesDesc
ch <- libvirtDomainMemoryStatsSwapOutBytesDesc
Expand Down

0 comments on commit 204c59e

Please sign in to comment.