From 204c59e936bf635cc76e619972df483d4c56c75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=BE=D0=B1=D0=BE=D0=B2=20=D0=A1=D0=B5?= =?UTF-8?q?=D1=80=D0=B3=D0=B5=D0=B9=20=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Tue, 15 Oct 2024 15:17:42 +0300 Subject: [PATCH] Add libvirt_domain_job metrics --- README.md | 12 ++ pkg/exporter/prometheus-libvirt-exporter.go | 152 +++++++++++++++++++- 2 files changed, 163 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 853aeb4..48d4732 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pkg/exporter/prometheus-libvirt-exporter.go b/pkg/exporter/prometheus-libvirt-exporter.go index 7a363d8..f428cf6 100644 --- a/pkg/exporter/prometheus-libvirt-exporter.go +++ b/pkg/exporter/prometheus-libvirt-exporter.go @@ -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"), @@ -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) } @@ -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 @@ -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