-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathall_data_to_move.awk
120 lines (115 loc) · 3.31 KB
/
all_data_to_move.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/awk -f
#
# Pipe the output of 'ceph pg dump' into this script.
#
# Dumps the listing of data counts going to / moving from
# each OSD ID with data remaining to move during
# backfill/recovery operations.
#
# Output format is CSV -- you'll likely want to redirect
# the output to a file, then open with Excel / LibreCalc
# or similar.
#
# NOTE: Total gigabytes output assumes replicated pool,
# for EC, divide the value by K ( EC K+M ) to get a 'close'
# estimate.
#
# To have the script do that for you, provide '-v k=#'
# where # is the K value for EC K+M.
#
# Example:
# ceph pg dump | ./all_data_to_move.awk -v k=8
#
# NOTE: If not all Pools are EC or Replicated, you will
# need to grep for a specific poolid (or IDs) on the input
# to this script so that the 'k' value applies properly.
#
# Example, pool 3 is EC 8+3, but the rest are replicated
# ceph pg dump | grep ^3\\. | ./all_data_to_move.awk -v k=8
# ceph pg dump | grep -v ^3\\. | ./all_data_to_move.awk
#
#
BEGIN {
if(k=="")
k=1
}
function movePG(toosdid,fromosdid) {
if(toosdid>=0) {
osds[toosdid]=1
osdmove["pgcount"][toosdid]["to"]++
osdmove["objects"][toosdid]["to"]+=$2
osdmove["degraded"][toosdid]["to"]+=$4
osdmove["misplaced"][toosdid]["to"]+=$5
osdmove["gigabytes"][toosdid]["to"]+=$7/1024/1024/1024
}
if(fromosdid>=0) {
osds[fromosdid]=1
osdmove["pgcount"][fromosdid]["from"]++
osdmove["objects"][fromosdid]["from"]+=$2
osdmove["degraded"][fromosdid]["from"]+=$4
osdmove["misplaced"][fromosdid]["from"]+=$5
osdmove["gigabytes"][fromosdid]["from"]+=$7/1024/1024/1024
}
}
/^[0-9][0-9]*\.[0-9a-f][0-9a-f]* / {
gsub(/(\[|\])/,"",$17)
gsub(/(\[|\])/,"",$19)
split($17,upset,",")
split($19,actset,",")
if(k>1) {
# EC Pool, check positions, not just presence / absence
for(i=1;i<=length(upset);i++) {
if(upset[i]!=actset[i])
movePG(upset[i],actset[i])
}
} else {
for(upid in upset) {
didmatch=0
for(actid in actset) {
if(upid==actid)
didmatch=1
}
if(didmatch==0)
movePG(upid,-1)
}
for(actid in actset) {
didmatch=0
for(upid in upset) {
if(upid==actid)
didmatch=1
}
if(didmatch==0)
movePG(-1,actid)
}
}
}
END {
txtfields="pgcount objects degraded misplaced gigabytes"
txtdirs="to from"
split(txtfields,fields," ")
split(txtdirs,dirs," ")
printf("osd.id")
for(fid in fields) {
for(did in dirs) {
printf(",%s %s",dirs[did],fields[fid])
if(field=="gigabytes" && k>1) {
printf("/%d",k)
}
}
}
print ""
osdcount=asorti(osds,sortedosds)
for(id=1;id<=osdcount;id++) {
printf("%s",sortedosds[id])
for(fid in fields) {
for(did in dirs) {
if(field=="gigabytes") {
printf(",%0.2f",osdmove[fields[fid]][sortedosds[id]][dirs[did]]/k)
} else {
printf(",%s",osdmove[fields[fid]][sortedosds[id]][dirs[did]])
}
}
}
print ""
}
}