Skip to content
Merged
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
1 change: 1 addition & 0 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (

TrackDatabaseChanges = kingpin.Flag("track-database-changes", "Track schema and settings changes in databases").Envar("TRACK_DATABASE_CHANGES").Default("true").Bool()
TrackDatabaseSizes = kingpin.Flag("track-database-sizes", "Collect per-database and per-table size metrics").Envar("TRACK_DATABASE_SIZES").Default("true").Bool()
TrackDatabaseBloat = kingpin.Flag("track-database-bloat", "Estimate per-database, per-table and per-index bloat (Postgres only)").Envar("TRACK_DATABASE_BLOAT").Default("true").Bool()
MaxTablesPerDatabase = kingpin.Flag("max-tables-per-database", "Skip databases with more tables than this limit").Envar("MAX_TABLES_PER_DATABASE").Default("1000").Int()
ExcludeDatabases = kingpin.Flag("exclude-databases", "Databases to exclude from schema and size tracking").Envar("EXCLUDE_DATABASES").Default("postgres", "mysql", "information_schema", "performance_schema", "sys").Strings()
)
Expand Down
12 changes: 0 additions & 12 deletions metrics/ksm/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ var resourceLabels = map[string][]string{
"resource_name": {"name"},
}

func info(name string, path []string, labels map[string][]string) crs.Generator {
return crs.Generator{
Name: name,
Each: crs.Metric{
Type: metric.Info,
Info: &crs.MetricInfo{
MetricMeta: crs.MetricMeta{Path: path, LabelsFromPath: labels},
},
},
}
}

func merge(base map[string][]string, extra map[string][]string) map[string][]string {
out := make(map[string][]string, len(base)+len(extra))
for k, v := range base {
Expand Down
80 changes: 80 additions & 0 deletions metrics/ksm/cnpg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package ksm

import (
crs "k8s.io/kube-state-metrics/v2/pkg/customresourcestate"
)

func cnpg() []crs.Resource {
operator := map[string]string{"operator": "cnpg"}
commonLabels := crs.Labels{
CommonLabels: operator,
LabelsFromPath: map[string][]string{
"uid": {"metadata", "uid"},
"name": {"metadata", "name"},
"namespace": {"metadata", "namespace"},
},
}
prefix := "pg"
gvk := func(kind string) crs.GroupVersionKind {
return crs.GroupVersionKind{Group: "postgresql.cnpg.io", Version: "v1", Kind: kind}
}
return []crs.Resource{
{
GroupVersionKind: gvk("Cluster"),
MetricNamePrefix: &prefix,
Labels: commonLabels,
ErrorLogV: 4,
Metrics: []crs.Generator{
infoConst("backup_target_info", []string{"spec", "backup"}, map[string][]string{
"path": {"barmanObjectStore", "destinationPath"},
"endpoint": {"barmanObjectStore", "endpointURL"},
"retention_policy": {"retentionPolicy"},
}, map[string]string{"method": "barmanObjectStore", "type": "object-storage"}),
info("cluster_status", []string{"status", "conditions"}, map[string][]string{
"type": {"type"},
"status": {"status"},
"reason": {"reason"},
}),
gaugeTimestampByMethod("backup_last_successful_timestamp_seconds", []string{"status", "lastSuccessfulBackupByMethod"}),
gaugeTimestampByMethod("backup_first_recoverability_point_timestamp_seconds", []string{"status", "firstRecoverabilityPointByMethod"}),
gaugeTimestamp("backup_last_failed_timestamp_seconds", []string{"status"}, "lastFailedBackup"),
},
},
{
GroupVersionKind: gvk("Backup"),
MetricNamePrefix: &prefix,
Labels: commonLabels,
ErrorLogV: 4,
Metrics: []crs.Generator{
info("backup_info", []string{}, map[string][]string{
"cluster": {"spec", "cluster", "name"},
"method": {"status", "method"},
}),
info("backup_status", []string{}, map[string][]string{
"status": {"status", "phase"},
}),
gaugeTimestamp("backup_completed_timestamp_seconds", []string{"status"}, "stoppedAt"),
},
},
{
GroupVersionKind: gvk("ScheduledBackup"),
MetricNamePrefix: &prefix,
Labels: crs.Labels{
CommonLabels: operator,
LabelsFromPath: map[string][]string{
"uid": {"metadata", "uid"},
"name": {"metadata", "name"},
"namespace": {"metadata", "namespace"},
"cluster": {"spec", "cluster", "name"},
},
},
ErrorLogV: 4,
Metrics: []crs.Generator{
info("backup_schedule_info", []string{"spec"}, map[string][]string{
"schedule": {"schedule"},
}),
gaugeTimestamp("backup_next_scheduled_timestamp_seconds", []string{"status"}, "nextScheduleTime"),
},
},
}
}
50 changes: 50 additions & 0 deletions metrics/ksm/generators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ksm

import (
crs "k8s.io/kube-state-metrics/v2/pkg/customresourcestate"
"k8s.io/kube-state-metrics/v2/pkg/metric"
)

func info(name string, path []string, labels map[string][]string) crs.Generator {
return crs.Generator{
Name: name,
Each: crs.Metric{
Type: metric.Info,
Info: &crs.MetricInfo{
MetricMeta: crs.MetricMeta{Path: path, LabelsFromPath: labels},
},
},
}
}

func infoConst(name string, path []string, labels map[string][]string, constLabels map[string]string) crs.Generator {
g := info(name, path, labels)
g.Labels = crs.Labels{CommonLabels: constLabels}
return g
}

func gaugeTimestamp(name string, path []string, valueFrom string) crs.Generator {
return crs.Generator{
Name: name,
Each: crs.Metric{
Type: metric.Gauge,
Gauge: &crs.MetricGauge{
MetricMeta: crs.MetricMeta{Path: path},
ValueFrom: []string{valueFrom},
},
},
}
}

func gaugeTimestampByMethod(name string, path []string) crs.Generator {
return crs.Generator{
Name: name,
Each: crs.Metric{
Type: metric.Gauge,
Gauge: &crs.MetricGauge{
MetricMeta: crs.MetricMeta{Path: path},
LabelFromKey: "method",
},
},
}
}
2 changes: 2 additions & 0 deletions metrics/ksm/ksm.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (ksm *KSM) Stop() {

func customResourceConfig() string {
resources := append(fluxcd(), argocd()...)
resources = append(resources, cnpg()...)
resources = append(resources, perconaPG()...)
cfg := crs.Metrics{
Spec: crs.MetricsSpec{Resources: resources},
}
Expand Down
59 changes: 59 additions & 0 deletions metrics/ksm/percona_pg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ksm

import (
crs "k8s.io/kube-state-metrics/v2/pkg/customresourcestate"
)

func perconaPG() []crs.Resource {
operator := map[string]string{"operator": "percona"}
commonLabels := crs.Labels{
CommonLabels: operator,
LabelsFromPath: map[string][]string{
"uid": {"metadata", "uid"},
"name": {"metadata", "name"},
"namespace": {"metadata", "namespace"},
},
}
prefix := "pg"
return []crs.Resource{
{
GroupVersionKind: crs.GroupVersionKind{Group: "pgv2.percona.com", Version: "v2", Kind: "PerconaPGCluster"},
MetricNamePrefix: &prefix,
Labels: commonLabels,
ErrorLogV: 4,
Metrics: []crs.Generator{
infoConst("backup_target_info", []string{"spec", "backups", "pgbackrest", "repos"}, map[string][]string{
"method": {"name"},
"s3_bucket": {"s3", "bucket"},
"s3_endpoint": {"s3", "endpoint"},
"gcs_bucket": {"gcs", "bucket"},
"azure_container": {"azure", "container"},
"schedule": {"schedules", "full"},
}, map[string]string{"type": "object-storage"}),
info("cluster_status", []string{"status", "conditions"}, map[string][]string{
"type": {"type"},
"status": {"status"},
"reason": {"reason"},
}),
},
},
{
GroupVersionKind: crs.GroupVersionKind{Group: "pgv2.percona.com", Version: "v2", Kind: "PerconaPGBackup"},
MetricNamePrefix: &prefix,
Labels: commonLabels,
ErrorLogV: 4,
Metrics: []crs.Generator{
info("backup_info", []string{}, map[string][]string{
"cluster": {"spec", "pgCluster"},
"method": {"status", "repo", "name"},
"kind": {"status", "backupType"},
"path": {"status", "destination"},
}),
info("backup_status", []string{}, map[string][]string{
"status": {"status", "state"},
}),
gaugeTimestamp("backup_completed_timestamp_seconds", []string{"status"}, "completed"),
},
},
}
}
2 changes: 1 addition & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (ms *Metrics) startExporters() {
}
}
}
if err := t.StartExporter(ms.reg, credentials, ms.scrapeInterval, ms.scrapeTimeout, ms.changeEmitter, *flags.MaxTablesPerDatabase, *flags.TrackDatabaseSizes, *flags.ExcludeDatabases); err != nil {
if err := t.StartExporter(ms.reg, credentials, ms.scrapeInterval, ms.scrapeTimeout, ms.changeEmitter, *flags.MaxTablesPerDatabase, *flags.TrackDatabaseSizes, *flags.TrackDatabaseBloat, *flags.ExcludeDatabases); err != nil {
t.logger.Errorf("failed to start exporter: %s", err)
continue
}
Expand Down
Loading
Loading