CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-fabric8--openshift-client

Java client library for OpenShift REST APIs, providing fluent DSL access to OpenShift resources and operations.

Pending
Overview
Eval results
Files

monitoring.mddocs/

Monitoring and Observability

Prometheus-based monitoring stack management through the monitoring.coreos.com API group. Provides comprehensive monitoring, alerting, and observability capabilities with Prometheus, Alertmanager, and related monitoring resources.

Capabilities

Monitoring Stack Management

/**
 * Access to Monitoring API Group (monitoring.coreos.com/v1)
 * Prometheus-based monitoring and alerting resources
 */
OpenShiftMonitoringAPIGroupDSL monitoring();

interface OpenShiftMonitoringAPIGroupDSL {
    /** Prometheus instances for metrics collection */
    NonNamespaceOperation<Prometheus, PrometheusList, Resource<Prometheus>> prometheuses();
    
    /** Alertmanager instances for alert handling */
    NonNamespaceOperation<Alertmanager, AlertmanagerList, Resource<Alertmanager>> alertmanagers();
    
    /** Alertmanager configuration */
    MixedOperation<AlertmanagerConfig, AlertmanagerConfigList, Resource<AlertmanagerConfig>> alertmanagerConfigs();
    
    /** Prometheus alerting and recording rules */
    NonNamespaceOperation<PrometheusRule, PrometheusRuleList, Resource<PrometheusRule>> prometheusRules();
    
    /** Service monitoring configurations */
    MixedOperation<ServiceMonitor, ServiceMonitorList, Resource<ServiceMonitor>> serviceMonitors();
    
    /** Pod monitoring configurations */
    MixedOperation<PodMonitor, PodMonitorList, Resource<PodMonitor>> podMonitors();
    
    /** Probe configurations for blackbox monitoring */
    MixedOperation<Probe, ProbeList, Resource<Probe>> probes();
    
    /** Thanos ruler instances for long-term storage */
    NonNamespaceOperation<ThanosRuler, ThanosRulerList, Resource<ThanosRuler>> thanosRulers();
}

Service and Pod Monitoring

Configure monitoring for services and pods to collect metrics and enable observability.

/**
 * Service monitoring for scraping metrics from services
 */
MixedOperation<ServiceMonitor, ServiceMonitorList, Resource<ServiceMonitor>> serviceMonitors();

/**
 * Pod monitoring for scraping metrics directly from pods
 */
MixedOperation<PodMonitor, PodMonitorList, Resource<PodMonitor>> podMonitors();

Usage Examples:

// Create service monitor for application metrics
ServiceMonitor serviceMonitor = new ServiceMonitorBuilder()
    .withMetadata(new ObjectMetaBuilder()
        .withName("my-app-monitor")
        .withNamespace("monitoring")
        .addToLabels("app", "my-app")
        .build())
    .withSpec(new ServiceMonitorSpecBuilder()
        .withSelector(new LabelSelectorBuilder()
            .addToMatchLabels("app", "my-app")
            .build())
        .addNewEndpoint()
            .withPort("metrics")
            .withPath("/metrics")
            .withInterval("30s")
            .withScrapeTimeout("10s")
        .endEndpoint()
        .build())
    .build();

client.monitoring().serviceMonitors()
    .inNamespace("monitoring")
    .create(serviceMonitor);

// Create pod monitor for pod-level metrics
PodMonitor podMonitor = new PodMonitorBuilder()
    .withMetadata(new ObjectMetaBuilder()
        .withName("my-app-pods")
        .withNamespace("monitoring")
        .build())
    .withSpec(new PodMonitorSpecBuilder()
        .withSelector(new LabelSelectorBuilder()
            .addToMatchLabels("app", "my-app")
            .build())
        .addNewPodMetricsEndpoint()
            .withPort("metrics")
            .withPath("/metrics")
            .withInterval("30s")
        .endPodMetricsEndpoint()
        .build())
    .build();

client.monitoring().podMonitors()
    .inNamespace("monitoring")
    .create(podMonitor);

Alerting Rules and Configuration

Define Prometheus alerting rules and configure Alertmanager for alert routing and notifications.

/**
 * Prometheus rules for alerting and recording rules
 */
NonNamespaceOperation<PrometheusRule, PrometheusRuleList, Resource<PrometheusRule>> prometheusRules();

/**
 * Alertmanager configuration for alert routing
 */
MixedOperation<AlertmanagerConfig, AlertmanagerConfigList, Resource<AlertmanagerConfig>> alertmanagerConfigs();

Usage Examples:

// Create Prometheus alerting rules
PrometheusRule alertingRules = new PrometheusRuleBuilder()
    .withMetadata(new ObjectMetaBuilder()
        .withName("my-app-alerts")
        .withNamespace("monitoring")
        .addToLabels("app", "my-app")
        .build())
    .withSpec(new PrometheusRuleSpecBuilder()
        .addNewGroup()
            .withName("my-app.rules")
            .withInterval("30s")
            .addNewRule()
                .withAlert("HighErrorRate")
                .withExpr("rate(http_requests_total{status=~\"5..\"}[5m]) > 0.1")
                .withFor("5m")
                .addToLabels("severity", "warning")
                .addToAnnotations("summary", "High error rate detected")
                .addToAnnotations("description", "Error rate is {{ $value }} errors per second")
            .endRule()
            .addNewRule()
                .withAlert("HighMemoryUsage")
                .withExpr("container_memory_usage_bytes / container_spec_memory_limit_bytes > 0.9")
                .withFor("10m")
                .addToLabels("severity", "critical")
                .addToAnnotations("summary", "High memory usage")
            .endRule()
        .endGroup()
        .build())
    .build();

client.monitoring().prometheusRules().create(alertingRules);

// Create Alertmanager configuration
AlertmanagerConfig amConfig = new AlertmanagerConfigBuilder()
    .withMetadata(new ObjectMetaBuilder()
        .withName("my-app-alerts")
        .withNamespace("monitoring")
        .build())
    .withSpec(new AlertmanagerConfigSpecBuilder()
        .addNewRoute()
            .withGroupBy("alertname", "cluster", "service")
            .withGroupWait("10s")
            .withGroupInterval("10s")
            .withRepeatInterval("1h")
            .withReceiver("web.hook")
            .addNewMatch()
                .withName("app")
                .withValue("my-app")
            .endMatch()
        .endRoute()
        .addNewReceiver()
            .withName("web.hook")
            .addNewWebhookConfig()
                .withUrl("http://my-webhook-service.monitoring.svc.cluster.local:8080/webhook")
                .withSendResolved(true)
            .endWebhookConfig()
        .endReceiver()
        .build())
    .build();

client.monitoring().alertmanagerConfigs()
    .inNamespace("monitoring")
    .create(amConfig);

Prometheus and Alertmanager Instances

Deploy and configure Prometheus and Alertmanager instances for custom monitoring requirements.

/**
 * Prometheus instances for metrics collection and storage
 */
NonNamespaceOperation<Prometheus, PrometheusList, Resource<Prometheus>> prometheuses();

/**
 * Alertmanager instances for alert processing
 */
NonNamespaceOperation<Alertmanager, AlertmanagerList, Resource<Alertmanager>> alertmanagers();

Usage Examples:

// Create custom Prometheus instance
Prometheus prometheus = new PrometheusBuilder()
    .withMetadata(new ObjectMetaBuilder()
        .withName("my-prometheus")
        .withNamespace("monitoring")
        .build())
    .withSpec(new PrometheusSpecBuilder()
        .withReplicas(2)
        .withRetention("30d")
        .withServiceAccountName("prometheus")
        .withServiceMonitorSelector(new LabelSelectorBuilder()
            .addToMatchLabels("team", "backend")
            .build())
        .withRuleSelector(new LabelSelectorBuilder()
            .addToMatchLabels("prometheus", "my-prometheus")
            .build())
        .withResources(new ResourceRequirementsBuilder()
            .addToRequests("memory", new Quantity("2Gi"))
            .addToRequests("cpu", new Quantity("1"))
            .addToLimits("memory", new Quantity("4Gi"))
            .addToLimits("cpu", new Quantity("2"))
            .build())
        .withStorage(new StorageSpecBuilder()
            .withVolumeClaimTemplate(new EmbeddedPersistentVolumeClaimBuilder()
                .withMetadata(new ObjectMetaBuilder()
                    .withName("prometheus-storage")
                    .build())
                .withSpec(new PersistentVolumeClaimSpecBuilder()
                    .withAccessModes("ReadWriteOnce")
                    .withResources(new ResourceRequirementsBuilder()
                        .addToRequests("storage", new Quantity("50Gi"))
                        .build())
                    .build())
                .build())
            .build())
        .build())
    .build();

client.monitoring().prometheuses().create(prometheus);

// Create Alertmanager instance
Alertmanager alertmanager = new AlertmanagerBuilder()
    .withMetadata(new ObjectMetaBuilder()
        .withName("my-alertmanager")
        .withNamespace("monitoring")
        .build())
    .withSpec(new AlertmanagerSpecBuilder()
        .withReplicas(3)
        .withRetention("120h")
        .withConfigSecret("alertmanager-config")
        .withResources(new ResourceRequirementsBuilder()
            .addToRequests("memory", new Quantity("200Mi"))
            .addToRequests("cpu", new Quantity("100m"))
            .build())
        .build())
    .build();

client.monitoring().alertmanagers().create(alertmanager);

Blackbox Monitoring and Probes

Configure external endpoint monitoring using blackbox exporter probes.

/**
 * Probe configurations for blackbox monitoring of external endpoints
 */
MixedOperation<Probe, ProbeList, Resource<Probe>> probes();

Usage Examples:

// Create HTTP probe for external service monitoring
Probe httpProbe = new ProbeBuilder()
    .withMetadata(new ObjectMetaBuilder()
        .withName("external-api-probe")
        .withNamespace("monitoring")
        .build())
    .withSpec(new ProbeSpecBuilder()
        .withProberSpec(new ProberSpecBuilder()
            .withUrl("blackbox-exporter:9115")
            .build())
        .withModule("http_2xx")
        .withTargets(new TargetsBuilder()
            .withStaticConfig(new StaticConfigBuilder()
                .withStatic("https://api.example.com/health")
                .withLabels(Map.of(
                    "service", "external-api",
                    "environment", "production"
                ))
                .build())
            .build())
        .withInterval("30s")
        .withScrapeTimeout("10s")
        .build())
    .build();

client.monitoring().probes()
    .inNamespace("monitoring")
    .create(httpProbe);

Usage Patterns

Complete Monitoring Setup

try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {
    String monitoringNamespace = "app-monitoring";
    
    // 1. Create service monitor for application
    ServiceMonitor appMonitor = new ServiceMonitorBuilder()
        .withMetadata(new ObjectMetaBuilder()
            .withName("my-app")
            .withNamespace(monitoringNamespace)
            .addToLabels("app", "my-app")
            .build())
        .withSpec(new ServiceMonitorSpecBuilder()
            .withSelector(new LabelSelectorBuilder()
                .addToMatchLabels("app", "my-app")
                .build())
            .addNewEndpoint()
                .withPort("metrics")
                .withPath("/metrics")
                .withInterval("30s")
            .endEndpoint()
            .build())
        .build();
    
    client.monitoring().serviceMonitors()
        .inNamespace(monitoringNamespace)
        .create(appMonitor);
    
    // 2. Create alerting rules
    PrometheusRule rules = new PrometheusRuleBuilder()
        .withMetadata(new ObjectMetaBuilder()
            .withName("my-app-alerts")
            .withNamespace(monitoringNamespace)
            .addToLabels("prometheus", "app-prometheus")
            .build())
        .withSpec(new PrometheusRuleSpecBuilder()
            .addNewGroup()
                .withName("my-app.rules")
                .addNewRule()
                    .withAlert("AppDown")
                    .withExpr("up{job=\"my-app\"} == 0")
                    .withFor("5m")
                    .addToLabels("severity", "critical")
                    .addToAnnotations("summary", "Application is down")
                .endRule()
            .endGroup()
            .build())
        .build();
    
    client.monitoring().prometheusRules().create(rules);
    
    // 3. Configure alert routing
    AlertmanagerConfig alertConfig = new AlertmanagerConfigBuilder()
        .withMetadata(new ObjectMetaBuilder()
            .withName("my-app-routing")
            .withNamespace(monitoringNamespace)
            .build())
        .withSpec(new AlertmanagerConfigSpecBuilder()
            .addNewRoute()
                .withReceiver("slack-notifications")
                .addNewMatch()
                    .withName("app")
                    .withValue("my-app")
                .endMatch()
            .endRoute()
            .addNewReceiver()
                .withName("slack-notifications")
                .addNewSlackConfig()
                    .withApiUrl(new SecretKeySelectorBuilder()
                        .withName("slack-webhook")
                        .withKey("url")
                        .build())
                    .withChannel("#alerts")
                    .withTitle("Alert: {{ .GroupLabels.alertname }}")
                    .withText("{{ range .Alerts }}{{ .Annotations.summary }}{{ end }}")
                .endSlackConfig()
            .endReceiver()
            .build())
        .build();
    
    client.monitoring().alertmanagerConfigs()
        .inNamespace(monitoringNamespace)
        .create(alertConfig);
}

Install with Tessl CLI

npx tessl i tessl/maven-io-fabric8--openshift-client

docs

client-setup.md

configuration-management.md

core-resources.md

index.md

machine-management.md

monitoring.md

multicluster-management.md

operator-management.md

security-rbac.md

tile.json