|
| 1 | +// Copyright 2025 SAP SE |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package kvm |
| 5 | + |
| 6 | +import ( |
| 7 | + _ "embed" |
| 8 | + |
| 9 | + "github.com/cobaltcore-dev/cortex/internal/db" |
| 10 | + "github.com/cobaltcore-dev/cortex/internal/extractor/plugins" |
| 11 | + "github.com/cobaltcore-dev/cortex/internal/sync/prometheus" |
| 12 | +) |
| 13 | + |
| 14 | +// Feature that maps CPU steal time of kvm hosts. |
| 15 | +type LibvirtDomainCPUStealTime struct { |
| 16 | + Instance string |
| 17 | +} |
| 18 | + |
| 19 | +// Table under which the feature is stored. |
| 20 | +func (LibvirtDomainCPUStealTime) TableName() string { |
| 21 | + return "feature_libvirt_domain_cpu_steal_time" |
| 22 | +} |
| 23 | + |
| 24 | +// Indexes for the feature. |
| 25 | +func (LibvirtDomainCPUStealTime) Indexes() []db.Index { |
| 26 | + return nil |
| 27 | +} |
| 28 | + |
| 29 | +// Extractor that extracts CPU steal time |
| 30 | +type LibvirtDomainCPUStealTimeExtractor struct { |
| 31 | + // Common base for all extractors that provides standard functionality. |
| 32 | + plugins.BaseExtractor[ |
| 33 | + struct{}, // No options passed through yaml config |
| 34 | + LibvirtDomainCPUStealTime, // Feature model |
| 35 | + ] |
| 36 | +} |
| 37 | + |
| 38 | +// Name of this feature extractor that is used in the yaml config, for logging etc. |
| 39 | +func (*LibvirtDomainCPUStealTimeExtractor) GetName() string { |
| 40 | + return "libvirt_domain_cpu_steal_time_extractor" |
| 41 | +} |
| 42 | + |
| 43 | +// Get message topics that trigger a re-execution of this extractor. |
| 44 | +func (LibvirtDomainCPUStealTimeExtractor) Triggers() []string { |
| 45 | + return []string{ |
| 46 | + prometheus.TriggerMetricAliasSynced("kvm_libvirt_domain_steal_time"), |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +//go:embed cpu_steal_time.sql |
| 51 | +var cpuStealTimeSQL string |
| 52 | + |
| 53 | +// Extract CPU steal time of kvm hosts. |
| 54 | +func (e *LibvirtDomainCPUStealTimeExtractor) Extract() ([]plugins.Feature, error) { |
| 55 | + return e.ExtractSQL(cpuStealTimeSQL) |
| 56 | +} |
0 commit comments