From dc2d847fa9107425ed11332ba3f18a04e595dc8b Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Sun, 18 Apr 2021 02:36:08 +0300 Subject: [PATCH 1/8] Export version information (qemu and libvirt) --- libvirt_exporter.go | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/libvirt_exporter.go b/libvirt_exporter.go index e7f9043..f2df0ba 100644 --- a/libvirt_exporter.go +++ b/libvirt_exporter.go @@ -18,15 +18,17 @@ package main import ( "encoding/xml" + "fmt" + "log" + "net/http" + "os" + "strconv" + "github.com/AlexZzz/libvirt-exporter/libvirtSchema" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "gopkg.in/alecthomas/kingpin.v2" "libvirt.org/libvirt-go" - "log" - "net/http" - "os" - "strconv" ) var ( @@ -35,7 +37,11 @@ var ( "Whether scraping libvirt's metrics was successful.", nil, nil) - + libvirtVersionInfoDesc = prometheus.NewDesc( + prometheus.BuildFQName("libvirt", "", "version_info"), + "Versions of libvirt components", + []string{"hypervisor", "library"}, + nil) libvirtDomainInfoMetaDesc = prometheus.NewDesc( prometheus.BuildFQName("libvirt", "domain_info", "meta"), "Domain metadata", @@ -667,6 +673,25 @@ func CollectFromLibvirt(ch chan<- prometheus.Metric, uri string) error { } defer conn.Close() + qemuVersionNum, err := conn.GetVersion() + if err != nil { + return err + } + qemuVersion := fmt.Sprintf("%d.%d.%d", qemuVersionNum/1000000%10, qemuVersionNum/1000%10, qemuVersionNum%10) + + libvirtVersionNum, err := conn.GetLibVersion() + if err != nil { + return err + } + libvirtVersion := fmt.Sprintf("%d.%d.%d", libvirtVersionNum/1000000%10, libvirtVersionNum/1000%10, libvirtVersionNum%10) + + ch <- prometheus.MustNewConstMetric( + libvirtVersionInfoDesc, + prometheus.GaugeValue, + 1.0, + qemuVersion, + libvirtVersion) + stats, err := conn.GetAllDomainStats([]*libvirt.Domain{}, libvirt.DOMAIN_STATS_STATE|libvirt.DOMAIN_STATS_CPU_TOTAL| libvirt.DOMAIN_STATS_INTERFACE|libvirt.DOMAIN_STATS_BALLOON|libvirt.DOMAIN_STATS_BLOCK| libvirt.DOMAIN_STATS_PERF|libvirt.DOMAIN_STATS_VCPU, @@ -728,8 +753,9 @@ func NewLibvirtExporter(uri string) (*LibvirtExporter, error) { // Describe returns metadata for all Prometheus metrics that may be exported. func (e *LibvirtExporter) Describe(ch chan<- *prometheus.Desc) { - // Status + // Status and versions ch <- libvirtUpDesc + ch <- libvirtVersionInfoDesc // Domain info ch <- libvirtDomainInfoMetaDesc From a862edb7d721db277cd2d28f9c1f67d06c45150b Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Sun, 18 Apr 2021 11:28:23 +0300 Subject: [PATCH 2/8] Account for non-single digit versions --- libvirt_exporter.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libvirt_exporter.go b/libvirt_exporter.go index f2df0ba..03acb52 100644 --- a/libvirt_exporter.go +++ b/libvirt_exporter.go @@ -677,13 +677,13 @@ func CollectFromLibvirt(ch chan<- prometheus.Metric, uri string) error { if err != nil { return err } - qemuVersion := fmt.Sprintf("%d.%d.%d", qemuVersionNum/1000000%10, qemuVersionNum/1000%10, qemuVersionNum%10) + qemuVersion := fmt.Sprintf("%d.%d.%d", qemuVersionNum/1000000%1000, qemuVersionNum/1000%1000, qemuVersionNum%1000) libvirtVersionNum, err := conn.GetLibVersion() if err != nil { return err } - libvirtVersion := fmt.Sprintf("%d.%d.%d", libvirtVersionNum/1000000%10, libvirtVersionNum/1000%10, libvirtVersionNum%10) + libvirtVersion := fmt.Sprintf("%d.%d.%d", libvirtVersionNum/1000000%1000, libvirtVersionNum/1000%1000, libvirtVersionNum%1000) ch <- prometheus.MustNewConstMetric( libvirtVersionInfoDesc, From a9e6e43ad076c59bd96a2ff8e542ee24b30aba39 Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Sun, 18 Apr 2021 12:40:32 +0300 Subject: [PATCH 3/8] Add libvirt_version_info metrics to docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 42fbd77..018ed0c 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ libvirt_domain_memory_stats_unused_bytes{domain="..."} libvirt_domain_memory_stats_usable_bytes{domain="..."} libvirt_domain_memory_stats_used_percent{domain="..."} +libvirt_version_info{hypervisor="...",library="..."} libvirt_up ``` From 6a918eb2df354fd9e11ddced31b66ae897f1d97c Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Wed, 21 Apr 2021 00:00:34 +0300 Subject: [PATCH 4/8] Rename labels, add new one, clarify with comments --- libvirt_exporter.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/libvirt_exporter.go b/libvirt_exporter.go index 03acb52..192fa12 100644 --- a/libvirt_exporter.go +++ b/libvirt_exporter.go @@ -37,10 +37,10 @@ var ( "Whether scraping libvirt's metrics was successful.", nil, nil) - libvirtVersionInfoDesc = prometheus.NewDesc( - prometheus.BuildFQName("libvirt", "", "version_info"), - "Versions of libvirt components", - []string{"hypervisor", "library"}, + libvirtVersionsInfoDesc = prometheus.NewDesc( + prometheus.BuildFQName("libvirt", "", "versions_info"), + "Versions of virtualization components", + []string{"hypervisor_running_version", "libvirtd_running_version", "library_version"}, nil) libvirtDomainInfoMetaDesc = prometheus.NewDesc( prometheus.BuildFQName("libvirt", "domain_info", "meta"), @@ -673,24 +673,31 @@ func CollectFromLibvirt(ch chan<- prometheus.Metric, uri string) error { } defer conn.Close() - qemuVersionNum, err := conn.GetVersion() + hypervisorVersionNum, err := conn.GetVersion() // virConnectGetVersion, hypervisor running, e.g. QEMU if err != nil { return err } - qemuVersion := fmt.Sprintf("%d.%d.%d", qemuVersionNum/1000000%1000, qemuVersionNum/1000%1000, qemuVersionNum%1000) + hypervisorVersion := fmt.Sprintf("%d.%d.%d", hypervisorVersionNum/1000000%1000, hypervisorVersionNum/1000%1000, hypervisorVersionNum%1000) - libvirtVersionNum, err := conn.GetLibVersion() + libvirtdVersionNum, err := conn.GetLibVersion() // virConnectGetLibVersion, libvirt daemon running if err != nil { return err } - libvirtVersion := fmt.Sprintf("%d.%d.%d", libvirtVersionNum/1000000%1000, libvirtVersionNum/1000%1000, libvirtVersionNum%1000) + libvirtdVersion := fmt.Sprintf("%d.%d.%d", libvirtdVersionNum/1000000%1000, libvirtdVersionNum/1000%1000, libvirtdVersionNum%1000) + + libraryVersionNum, err := libvirt.GetVersion() // virGetVersion, version of library, i.e. libvirt library used here, not the daemon + if err != nil { + return err + } + libraryVersion := fmt.Sprintf("%d.%d.%d", libraryVersionNum/1000000%1000, libraryVersionNum/1000%1000, libraryVersionNum%1000) ch <- prometheus.MustNewConstMetric( - libvirtVersionInfoDesc, + libvirtVersionsInfoDesc, prometheus.GaugeValue, 1.0, - qemuVersion, - libvirtVersion) + hypervisorVersion, + libvirtdVersion, + libraryVersion) stats, err := conn.GetAllDomainStats([]*libvirt.Domain{}, libvirt.DOMAIN_STATS_STATE|libvirt.DOMAIN_STATS_CPU_TOTAL| libvirt.DOMAIN_STATS_INTERFACE|libvirt.DOMAIN_STATS_BALLOON|libvirt.DOMAIN_STATS_BLOCK| @@ -755,7 +762,7 @@ func NewLibvirtExporter(uri string) (*LibvirtExporter, error) { func (e *LibvirtExporter) Describe(ch chan<- *prometheus.Desc) { // Status and versions ch <- libvirtUpDesc - ch <- libvirtVersionInfoDesc + ch <- libvirtVersionsInfoDesc // Domain info ch <- libvirtDomainInfoMetaDesc From 6a97c1e9055ee0823bf5fe98e96ca418b6cbc940 Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Wed, 21 Apr 2021 00:03:12 +0300 Subject: [PATCH 5/8] Remove unnecessary deps, go mod tidy --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index bc9f5e1..a7f892a 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,6 @@ go 1.12 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect github.com/prometheus/client_golang v1.1.0 gopkg.in/alecthomas/kingpin.v2 v2.2.6 libvirt.org/libvirt-go v7.2.0+incompatible From f8a7032b87d488a7fc64048e19baf5df632a96b0 Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Wed, 21 Apr 2021 00:27:19 +0300 Subject: [PATCH 6/8] Clarify labels --- libvirt_exporter.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libvirt_exporter.go b/libvirt_exporter.go index 192fa12..b838404 100644 --- a/libvirt_exporter.go +++ b/libvirt_exporter.go @@ -40,7 +40,7 @@ var ( libvirtVersionsInfoDesc = prometheus.NewDesc( prometheus.BuildFQName("libvirt", "", "versions_info"), "Versions of virtualization components", - []string{"hypervisor_running_version", "libvirtd_running_version", "library_version"}, + []string{"hypervisor_running", "libvirtd_running", "libvirt_library"}, nil) libvirtDomainInfoMetaDesc = prometheus.NewDesc( prometheus.BuildFQName("libvirt", "domain_info", "meta"), @@ -685,7 +685,7 @@ func CollectFromLibvirt(ch chan<- prometheus.Metric, uri string) error { } libvirtdVersion := fmt.Sprintf("%d.%d.%d", libvirtdVersionNum/1000000%1000, libvirtdVersionNum/1000%1000, libvirtdVersionNum%1000) - libraryVersionNum, err := libvirt.GetVersion() // virGetVersion, version of library, i.e. libvirt library used here, not the daemon + libraryVersionNum, err := libvirt.GetVersion() // virGetVersion, version of libvirt (dynamic) library used by this binary (exporter), not the daemon version if err != nil { return err } From 44ba366723ab15480868ad0d98f73174ec0d07dc Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Wed, 21 Apr 2021 00:38:19 +0300 Subject: [PATCH 7/8] Update docs --- CHANGELOG.md | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1674f72..3129bb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1.1] - 2021-04-21 +### Added +- Add libvirt_versions_info metric. + ## [2.1.0] - 2021-04-12 ### Added - Add delay time metric. Exposed to vm as a steal time. diff --git a/README.md b/README.md index 018ed0c..cef1ab1 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ libvirt_domain_memory_stats_unused_bytes{domain="..."} libvirt_domain_memory_stats_usable_bytes{domain="..."} libvirt_domain_memory_stats_used_percent{domain="..."} -libvirt_version_info{hypervisor="...",library="..."} +libvirt_versions_info{hypervisor_running="...",libvirtd_running="...",libvirt_library="..."} libvirt_up ``` From 5444a4b63fee785e2d07a28b6708ab3f05f0c5df Mon Sep 17 00:00:00 2001 From: nedvna <72229464+nedvna@users.noreply.github.com> Date: Wed, 21 Apr 2021 14:07:43 +0300 Subject: [PATCH 8/8] Fix changelog --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3129bb0..29b5208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - -## [2.1.1] - 2021-04-21 ### Added - Add libvirt_versions_info metric.