惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Martin Fowler
Martin Fowler
I
InfoQ
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
B
Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
V
Visual Studio Blog

OneUptime Blog

How to Monitor Azure App Services (PaaS) with OpenTelemetry Grafana Stack vs OneUptime: DIY Observability or Unified Platform? Your AI Workloads Are About to Blow Up Your Observability Bill The Great Observability Consolidation Is Here How to Write Custom Object Classes for Ceph How to Write Custom Ceph Manager Modules How to Write a ceph.conf Configuration File How to Use Rook-Ceph with OpenShift How to Use Rook-Ceph with Longhorn for Comparison How to Configure Volume Snapshot Class for RBD in Rook How to Configure VolumeReplicationClass Scheduling Intervals in Rook How to Set Up Volume Replication with Rook-Ceph How to Create Volume Group Snapshots with Rook CSI How to Visualize Ceph Network Performance in Grafana How to Enable Virtual Host-Style Bucket Access in Rook How to View Runtime Configuration via Admin Socket How to View Quota Settings and Update Stats in Ceph RGW How to View PG Scaling Recommendations with autoscale-status How to View Performance Metrics in the Ceph Dashboard How to View OSD Performance Counters in Ceph How to View Connection Status via Admin Socket How to View Ceph Cluster Summary Dashboard via CLI How to Version Control Rook-Ceph Configuration How to Version Control Ceph Infrastructure with Terraform How to Verify Kubernetes Node Requirements for Rook-Ceph Deployment How to Verify Health Before and After Rook Upgrades How to Verify Data Integrity with Deep Scrubbing How to Verify Complete Rook-Ceph Cleanup How to Verify Backup Integrity from Ceph Snapshots How to Use Rook-Ceph with Velero for Kubernetes Backup
How to View PG Distribution via Admin Socket
Nawaz Dhandala · 2026-03-31 · via OneUptime Blog

Overview

Placement groups (PGs) are the fundamental units of data distribution in Ceph. Each OSD hosts a subset of PGs, and uneven distribution leads to hotspots. The admin socket provides commands to inspect which PGs are on a specific OSD and their current state.

Listing PGs on an OSD

# Show all PGs on OSD 0
ceph daemon osd.0 dump_pgs

# Count PGs on each OSD
for osd in $(ceph osd ls); do
    COUNT=$(ceph daemon osd.$osd dump_pgs 2>/dev/null | python3 -c \
    "import sys,json; d=json.load(sys.stdin); print(len(d.get('pg_stats',d if isinstance(d,list) else [])))" 2>/dev/null)
    echo "OSD $osd: $COUNT PGs"
done

Getting PG States on an OSD

# Dump PGs with state information
ceph daemon osd.0 dump_pgs | python3 -c "
import sys, json
data = json.load(sys.stdin)
pgs = data if isinstance(data, list) else data.get('pg_stats', [])
states = {}
for pg in pgs:
    state = pg.get('state', 'unknown')
    states[state] = states.get(state, 0) + 1
for state, count in sorted(states.items()):
    print(f'{state}: {count}')
"

Checking Primary vs Replica PGs

# Check how many PGs have OSD 0 as primary
ceph pg dump --format json 2>/dev/null | python3 -c "
import sys, json
data = json.load(sys.stdin)
pgs = data.get('pg_stats', [])
count = sum(1 for pg in pgs if pg.get('acting_primary') == 0)
print(f'PGs with OSD 0 as primary: {count}')
"

# More detailed breakdown: primary vs replica for OSD 0
ceph pg dump --format json 2>/dev/null | python3 -c "
import sys, json
data = json.load(sys.stdin)
pgs = data.get('pg_stats', [])
primary = 0
replica = 0
for pg in pgs:
    acting = pg.get('acting', [])
    if acting and acting[0] == 0:
        primary += 1
    elif 0 in acting:
        replica += 1
print(f'Primary: {primary}, Replica: {replica}')
"

Identifying Uneven PG Distribution

# Get PG count per OSD (dynamically find the PGS column from the header)
ceph osd df | awk 'NR==1{for(i=1;i<=NF;i++) if($i=="PGS") c=i} NR>1 && $1~/^[0-9]/ && c{print "OSD "$1": "$c" PGs"}' | head -20

# Check the OSD with most and fewest PGs
ceph osd df | awk 'NR==1{for(i=1;i<=NF;i++) if($i=="PGS") c=i} NR>1 && $1~/^[0-9]/ && c{print $1, $c}' | sort -k2 -n | head -5   # least PGs
ceph osd df | awk 'NR==1{for(i=1;i<=NF;i++) if($i=="PGS") c=i} NR>1 && $1~/^[0-9]/ && c{print $1, $c}' | sort -k2 -rn | head -5  # most PGs

Viewing PG Map Details for an OSD

# Request the latest OSD map from the monitor
ceph daemon osd.0 get_latest_osdmap

# Dump the current OSD map epoch
ceph daemon osd.0 osd_map_epoch

Rebalancing PG Distribution

If PGs are unevenly distributed, check CRUSH weights:

# Show CRUSH weight for each OSD
ceph osd tree | grep osd

# Reweight if one OSD is significantly over-represented
ceph osd reweight osd.0 0.95

# Or use automatic reweighting
ceph osd reweight-by-utilization

Monitoring PG State Changes

# Watch PG state changes on a specific OSD
watch -n 10 'ceph daemon osd.0 dump_pgs | python3 -c "
import sys, json
data = json.load(sys.stdin)
pgs = data if isinstance(data, list) else data.get(\"pg_stats\", [])
active = sum(1 for p in pgs if \"active\" in p.get(\"state\",\"\"))
print(f\"Active PGs: {active}/{len(pgs)}\")
"'

Summary

The admin socket dump_pgs command reveals all placement groups hosted on a specific OSD along with their state. Use this to diagnose PG imbalances causing OSD hotspots, verify primary and replica distribution, and confirm PG health during cluster operations. Combine with ceph osd df and CRUSH reweighting to address uneven distributions.