This page is meant as a template for writing a KIP. To create a KIP choose Tools->Copy on this page and modify with your content and replace the heading with the next KIP number and a description of your issue. Replace anything in italics with your own description.

Status

Current state: Under Discussion

Discussion thread: here

JIRA: here

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation


Apache Kafka currently exposes only 2 out of 7 available Linux I/O metrics from /proc/self/io (read_bytes and write_bytes) as linux-disk-read-bytes and linux-disk-write-bytes, preventing operators from understanding critical I/O behaviour in production. 

The 5 missing metrics (rchar, wchar, syscr, syscw, and cancelled_write_bytes) are essential for diagnosing performance issues and optimising Kafka deployments as without these metrics, operators cannot calculate cache hit ratios to understand page cache effectiveness (rchar vs read_bytes), detect write amplification from filesystem overhead (write_bytes vs wchar), identify inefficient I/O patterns from excessive system calls, or monitor log compaction activity. These blind spots make troubleshooting significantly harder. 
 
The proposed change exposes all 7 metrics via JMX with low overhead as the data is already being read from the kernel, we are simply parsing and exposing the 5 additional fields that are currently discarded. 

This brings Kafka's I/O observability in line with industry standards like PostgreSQL and MySQL, enabling operators to proactively monitor I/O health, troubleshoot issues faster, optimise capacity planning by understanding actual storage requirements including amplification, and reduce costs by making data-driven infrastructure decisions.

The change is purely additive, backward compatible, and provides immediate value to anyone running Kafka on Linux in production.

Proposed Changes

Extend Linux I/O Metrics Collected to parse and expose all 7 metrics from /proc/self/io instead of just 2.

New Metrics Overview

Metric Semantics and Behaviour

Scenariorcharwcharsyscrsyscwcancelled_write_bytes







Normal steady-state operation

Available (MB-GB range)

Available (MB-GB range)

Available (thousands-millions)

Available (thousands-millions)

Available (MB range low)

Broker cold start (empty cache)

Equals read_bytes initially

Available

Available

Available

Minimal (near zero)

High cache hit ratio (>90%)

Much larger than read_bytes

Available

Available

Available

Available

Low cache hit ratio (<20%)

Close to read_bytes value

Available

Available

Available

Available

Write amplification scenario

Available

Much smaller than write_bytes

Available

Available

Available

Optimal I/O batching

Available

Available

Low count (large avg size)

Low count (large avg size)

Available

Poor I/O batching (tiny reads/writes)

Available

Available

Very high count (small avg size)

Very high count (small avg size)

Available

Active log compaction

Available

Available

Available

Available

High (MB-GB range)

No log compaction activity

Available

Available

Available

Available

Low (near zero)

Topic deletion in progress

Available

Available

Available

Available

Elevated (MB range)

Non-Linux platform

N/A

N/A

N/A

N/A

N/A

Linux platform without /proc/self/io

N/A

N/A

N/A

N/A

N/A


Metric Cardinality:


Metric Behaviour During Operations:

1. During Normal Operation :All metrics are monotonically increasing counters

2. During Partition Reassignment: Metrics reflect total process I/O per broker, regardless of partition ownership.

3. Metric collection frequency - how often are these updated?
Kernel-Side Update Frequency

Source: /proc/self/io (procfs virtual filesystem)
    - Update mechanism: Updated by Linux kernel in real-time as I/O operations occur
    - Granularity: Every I/O syscall updates the relevant counters immediately
    - Atomicity: All 7 metrics in the file are read atomically in a single file read operation

Example :The kernel updates these instantly as I/O happens:
    rchar: 4052              # Updated on every read() syscall
    wchar: 3000              # Updated on every write() syscall
    syscr: 13                # Incremented on each read syscall
    syscw: 10                # Incremented on each write syscall
    read_bytes: 0            # Updated when data physically read from disk
    write_bytes: 0           # Updated when data physically written to disk
    cancelled_write_bytes: 0 # Updated when buffered writes are cancelled
    
 4. if the linux version would impact the availability of these metrics?
 
   - All metrics require Linux kernel 2.6.20+ (released January 2007)
   - Bottom Line:
        - 100% of modern Linux systems support all 7 metrics
        - Even 10+ year old kernels have full support
        - No distribution-specific patches or backports needed

    Graceful Degradation:
        - Non-Linux systems: Metrics simply not available (existing behavior)
        - Linux without procfs: Detected and disabled automatically
        - Containers without /proc mounted: Detected and disabled
        - No errors, no exceptions - just logs debug message

 5. Container/Virtualization Impact

        Docker/Kubernetes:
        - /proc/self/io works correctly in containers by default
        - No special configuration needed - procfs is mounted automatically

Public Interfaces

JMX Metrics

Scope Note: The `linux-disk-*` prefix is a historical naming convention inherited 
from the two existing metrics. All seven metrics in this group reflect aggregate I/O
for the Kafka broker JVM process across all configured `log.dirs`. They do not provide
per-disk or per-log-directory visibility.

All metrics exposed under kafka.server:type=KafkaServer,name=<metric-name> :

For Example: (Existing metric)

kafka.server type=KafkaServer name=linux-disk-read-bytes  Value=16384 JMXTool=1.5.3 

New Metrics:

Metric Name: linux-disk-rchar
Type: Gauge
Unit: Bytes
Description: Total bytes read (including page cache hits)
Use Case: Calculate cache hit ratio: (rchar - read_bytes) / rchar
────────────────────────────────────────
Metric Name: linux-disk-wchar
Type: Gauge
Unit: Bytes
Description: Total bytes written (including buffered writes)
Use Case: Detect write amplification: write_bytes / wchar
────────────────────────────────────────
Metric Name: linux-disk-syscr
Type: Gauge
Unit: Count
Description: Number of read system calls
Use Case: Identify inefficient I/O patterns: read_bytes / syscr for avg read size
────────────────────────────────────────
Metric Name: linux-disk-syscw
Type: Gauge
Unit: Count
Description: Number of write system calls
Use Case: Analyze write batching: write_bytes / syscw for avg write size
────────────────────────────────────────
Metric Name: linux-disk-cancelled-write-bytes
Type: Gauge
Unit: Bytes
Description: Bytes cancelled before write (truncations)
Use Case: Monitor log compaction and cleanup activity
────────────────────────────────────────
Metric Name: linux-disk-read-bytes (existing)
Type: Gauge
Unit: Bytes
Description: Bytes read from storage layer (actual disk I/O)
Use Case: Track physical disk reads
────────────────────────────────────────
Metric Name: linux-disk-write-bytes (existing)
Type: Gauge
Unit: Bytes
Description: Bytes written to storage layer (actual disk I/O)
Use Case: Track physical disk writes

Compatibility, Deprecation, and Migration Plan

Test Plan

The feature will be validated through:

Rejected Alternatives