diff --git a/pkg/db/seeds.go b/pkg/db/seeds.go index d56326f..a0a55be 100644 --- a/pkg/db/seeds.go +++ b/pkg/db/seeds.go @@ -24,6 +24,12 @@ var appuioCloudLoadbalancerQuery string //go:embed seeds/appuio_cloud_persistent_storage.promql var appuioCloudPersistentStorageQuery string +//go:embed seeds/appuio_managed_openshift_vcpu_app.promql +var appuioManagedOpenShiftvCPUAppQuery string + +//go:embed seeds/appuio_managed_openshift_vcpu_storage.promql +var appuioManagedOpenShiftvCPUStorageQuery string + //go:embed seeds/appcat_postgresql_vshn_standalone.promql var appcatPostgresqlVSHNStandalone string @@ -60,6 +66,18 @@ var DefaultQueries = []Query{ Query: appuioCloudPersistentStorageQuery, Unit: "GiB", }, + { + Name: "appuio_managed_openshift_vcpu_app", + Description: "vCPU aggregated by cluster and service level for app nodes", + Query: appuioManagedOpenShiftvCPUAppQuery, + Unit: "vCPU", + }, + { + Name: "appuio_managed_openshift_vcpu_app", + Description: "vCPU aggregated by cluster and service level for storage nodes", + Query: appuioManagedOpenShiftvCPUStorageQuery, + Unit: "vCPU", + }, { Name: "appcat_postgresql_vshn_standalone", Description: "Number of VSHN managed standalone postgres instances", diff --git a/pkg/db/seeds/appuio_managed_openshift_vcpu_app.promql b/pkg/db/seeds/appuio_managed_openshift_vcpu_app.promql new file mode 100644 index 0000000..abebfd5 --- /dev/null +++ b/pkg/db/seeds/appuio_managed_openshift_vcpu_app.promql @@ -0,0 +1,36 @@ +# Calculates vCPUs for app nodes of a cluster +# Structure of resulting product label "query:cluster:tenant::class" + +# Max values over one hour. +max_over_time( + # Add the final product label by joining the base product with the cluster ID, the tenant, and the service class. + label_join( + label_replace( + # Add the base product identifier. + label_replace( + sum by(cluster_id, vshn_service_level, tenant_id) ( + sum by (tenant_id, cluster_id, instance, vshn_service_level) ( + min without(prometheus_replica) (node_cpu_info) + ) * on (tenant_id, cluster_id, instance, vshn_service_level) + label_join( + (group without(prometheus_replica) (kube_node_role{role="app"})), "instance", "", "node") + ), + "product", + "appuio_managed_openshift_vcpu_app", + "product", + ".*" + ), + "class", + "$1", + "vshn_service_level", + "(.*)" + ), + "product", + ":", + "product", + "cluster_id", + "tenant_id", + "empty", # empty namespace + "class" + )[59m:1m] +) diff --git a/pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql b/pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql new file mode 100644 index 0000000..05d5e5e --- /dev/null +++ b/pkg/db/seeds/appuio_managed_openshift_vcpu_storage.promql @@ -0,0 +1,36 @@ +# Calculates vCPUs for storage nodes of a cluster +# Structure of resulting product label "query:cluster:tenant::class" + +# Max values over one hour. +max_over_time( + # Add the final product label by joining the base product with the cluster ID, the tenant, and the service class. + label_join( + label_replace( + # Add the base product identifier. + label_replace( + sum by(cluster_id, vshn_service_level, tenant_id) ( + sum by (tenant_id, cluster_id, instance, vshn_service_level) ( + min without(prometheus_replica) (node_cpu_info) + ) * on (tenant_id, cluster_id, instance, vshn_service_level) + label_join( + (group without(prometheus_replica) (kube_node_role{role="storage"})), "instance", "", "node") + ), + "product", + "appuio_managed_openshift_vcpu_storage", + "product", + ".*" + ), + "class", + "$1", + "vshn_service_level", + "(.*)" + ), + "product", + ":", + "product", + "cluster_id", + "tenant_id", + "empty", # empty namespace + "class" + )[59m:1m] +) diff --git a/pkg/db/seeds_test.go b/pkg/db/seeds_test.go index 8be69fb..596e51e 100644 --- a/pkg/db/seeds_test.go +++ b/pkg/db/seeds_test.go @@ -22,7 +22,7 @@ func (s *SeedsTestSuite) TestSeedDefaultQueries() { _, err := d.Exec("DELETE FROM queries") require.NoError(t, err) - expQueryNum := 6 + expQueryNum := 7 count := "SELECT COUNT(*) FROM queries" requireQueryEqual(t, d, 0, count)