Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions helm/bundles/cortex-nova/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ cortex-core:
(sum by (node) (node_memory_MemTotal_bytes) / count by (node) (node_memory_MemTotal_bytes))
)) * 100
type: node_exporter_metric
- alias: kvm_libvirt_domain_steal_time
query: rate(kvm_libvirt_domain_steal_time[1m])
type: kvm_cpu_steal_time_metric

openstack:
nova:
Expand Down Expand Up @@ -197,6 +200,16 @@ cortex-core:
- alias: vrops_hostsystem_cpu_contention_short_term_percentage

# KVM-specific extractors.
- name: libvirt_domain_cpu_steal_time_extractor
dependencies:
sync:
prometheus:
metrics:
- alias: kvm_libvirt_domain_steal_time
openstack:
nova:
types:
- servers
- name: node_exporter_host_cpu_usage_extractor
dependencies:
sync:
Expand Down
1 change: 1 addition & 0 deletions internal/extractor/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var SupportedExtractors = []plugins.FeatureExtractor{
// KVM-specific extractors
&kvm.NodeExporterHostCPUUsageExtractor{},
&kvm.NodeExporterHostMemoryActiveExtractor{},
&kvm.LibvirtDomainCPUStealTimeExtractor{},
// NetApp-specific extractors
&netapp.StoragePoolCPUUsageExtractor{},
// Shared extractors
Expand Down
56 changes: 56 additions & 0 deletions internal/extractor/plugins/kvm/cpu_steal_time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2025 SAP SE
// SPDX-License-Identifier: Apache-2.0

package kvm

import (
_ "embed"

"github.com/cobaltcore-dev/cortex/internal/db"
"github.com/cobaltcore-dev/cortex/internal/extractor/plugins"
"github.com/cobaltcore-dev/cortex/internal/sync/prometheus"
)

// Feature that maps CPU steal time of kvm hosts.
type LibvirtDomainCPUStealTime struct {
Instance string
}

// Table under which the feature is stored.
func (LibvirtDomainCPUStealTime) TableName() string {
return "feature_libvirt_domain_cpu_steal_time"
}

// Indexes for the feature.
func (LibvirtDomainCPUStealTime) Indexes() []db.Index {
return nil
}

// Extractor that extracts CPU steal time
type LibvirtDomainCPUStealTimeExtractor struct {
// Common base for all extractors that provides standard functionality.
plugins.BaseExtractor[
struct{}, // No options passed through yaml config
LibvirtDomainCPUStealTime, // Feature model
]
}

// Name of this feature extractor that is used in the yaml config, for logging etc.
func (*LibvirtDomainCPUStealTimeExtractor) GetName() string {
return "libvirt_domain_cpu_steal_time_extractor"
}

// Get message topics that trigger a re-execution of this extractor.
func (LibvirtDomainCPUStealTimeExtractor) Triggers() []string {
return []string{
prometheus.TriggerMetricAliasSynced("kvm_libvirt_domain_steal_time"),
}
}

//go:embed cpu_steal_time.sql
var cpuStealTimeSQL string

// Extract CPU steal time of kvm hosts.
func (e *LibvirtDomainCPUStealTimeExtractor) Extract() ([]plugins.Feature, error) {
return e.ExtractSQL(cpuStealTimeSQL)
}
7 changes: 7 additions & 0 deletions internal/extractor/plugins/kvm/cpu_steal_time.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT * FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY os.id ORDER BY kvm.timestamp DESC) as rn
FROM kvm_cpu_steal_time_metrics kvm
LEFT JOIN openstack_servers os ON os.os_ext_srv_attr_instance_name = kvm.domain
) ranked
WHERE rn = 1 AND os.id IS NOT NULL;
1 change: 1 addition & 0 deletions internal/sync/prometheus/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var SupportedSyncers = map[string]syncerFunc{
"netapp_aggregate_labels_metric": newSyncerOfType[NetAppAggregateLabelsMetric],
"netapp_node_metric": newSyncerOfType[NetAppNodeMetric],
"netapp_volume_aggregate_labels_metric": newSyncerOfType[NetAppVolumeAggrLabelsMetric],
"kvm_cpu_steal_time_metric": newSyncerOfType[KVMCPUStealTimeMetric],
}

// Syncer that syncs all configured metrics.
Expand Down
26 changes: 26 additions & 0 deletions internal/sync/prometheus/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,29 @@ func (m NetAppVolumeAggrLabelsMetric) With(n string, t time.Time, v float64) Pro
m.Value = v
return m
}

type KVMCPUStealTimeMetric struct {
// The name of the metric.
Name string `db:"name"`
Instance string `json:"instance" db:"instance"`
Domain string `json:"domain" db:"domain"`
Node string `json:"node" db:"node"`
// Timestamp of the metric value.
Timestamp time.Time `json:"timestamp" db:"timestamp"`
// The value of the metric (usually 1 for label metrics).
Value float64 `json:"value" db:"value"`
}

func (m KVMCPUStealTimeMetric) TableName() string {
return "kvm_cpu_steal_time_metrics"
}
func (m KVMCPUStealTimeMetric) Indexes() []db.Index { return nil }
func (m KVMCPUStealTimeMetric) GetName() string { return m.Name }
func (m KVMCPUStealTimeMetric) GetTimestamp() time.Time { return m.Timestamp }
func (m KVMCPUStealTimeMetric) GetValue() float64 { return m.Value }
func (m KVMCPUStealTimeMetric) With(n string, t time.Time, v float64) PrometheusMetric {
m.Name = n
m.Timestamp = t
m.Value = v
return m
}
Loading