EOX GitLab Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rgw_storage_report
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Baudoin
rgw_storage_report
Commits
5546a5ab
Commit
5546a5ab
authored
6 months ago
by
Nicolas Baudoin
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
051943d5
Branches
main
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rgw_storage_report.sh
+171
-0
171 additions, 0 deletions
rgw_storage_report.sh
with
171 additions
and
0 deletions
rgw_storage_report.sh
0 → 100644
+
171
−
0
View file @
5546a5ab
#!/bin/bash
# Function to convert bytes to human-readable format
human_readable
()
{
local
bytes
=
$1
if
[
$bytes
-lt
1024
]
;
then
echo
"
${
bytes
}
B"
elif
[
$bytes
-lt
$((
1024
*
1024
))
]
;
then
echo
"
$(
echo
"scale=2;
$bytes
/1024"
| bc
)
KB"
elif
[
$bytes
-lt
$((
1024
*
1024
*
1024
))
]
;
then
echo
"
$(
echo
"scale=2;
$bytes
/(1024*1024)"
| bc
)
MB"
elif
[
$bytes
-lt
$((
1024
*
1024
*
1024
*
1024
))
]
;
then
echo
"
$(
echo
"scale=2;
$bytes
/(1024*1024*1024)"
| bc
)
GB"
else
echo
"
$(
echo
"scale=2;
$bytes
/(1024*1024*1024*1024)"
| bc
)
TB"
fi
}
# Function to convert human-readable sizes (e.g., "40 TiB") to bytes
convert_to_bytes
()
{
local
size
=
$1
local
value
=
$(
echo
$size
|
awk
'{print $1}'
)
local
unit
=
$(
echo
$size
|
awk
'{print $2}'
)
case
$unit
in
B
)
echo
"
$value
"
;;
KB
)
echo
$(
awk
"BEGIN {printf
\"
%.0f
\"
,
$value
* 1024}"
)
;;
MB
)
echo
$(
awk
"BEGIN {printf
\"
%.0f
\"
,
$value
* 1024 * 1024}"
)
;;
GB
)
echo
$(
awk
"BEGIN {printf
\"
%.0f
\"
,
$value
* 1024 * 1024 * 1024}"
)
;;
TB|TiB
)
echo
$(
awk
"BEGIN {printf
\"
%.0f
\"
,
$value
* 1024 * 1024 * 1024 * 1024}"
)
;;
*
)
echo
"Unknown unit:
$unit
"
>
&2
exit
1
;;
esac
}
# Temporary file to store bucket data
bucket_tmp_file
=
$(
mktemp
)
# Declare associative arrays to store user usage and quota information
declare
-A
user_usage_map
declare
-A
user_quota_map
# Loop through each bucket and gather information
buckets
=
$(
radosgw-admin bucket list | jq
-r
'.[]'
)
for
bucket
in
$buckets
;
do
# Get bucket stats
bucket_stats
=
$(
radosgw-admin bucket stats
--bucket
=
"
$bucket
"
)
# Extract relevant fields
owner
=
$(
echo
"
$bucket_stats
"
| jq
-r
'.owner'
)
usage
=
$(
echo
"
$bucket_stats
"
| jq
-r
'.usage["rgw.main"].size_utilized'
)
# Handle null usage gracefully
if
[
"
$usage
"
=
"null"
]
;
then
usage
=
0
fi
# Accumulate usage for the user
if
[[
-z
"
${
user_usage_map
[
$owner
]
}
"
]]
;
then
user_usage_map[
$owner
]=
$usage
else
user_usage_map[
$owner
]=
$((${
user_usage_map
[
$owner
]
}
+
$usage
))
fi
# Store the data for sorting
echo
"
$usage
$bucket
$owner
"
>>
$bucket_tmp_file
# Retrieve the user's quota information if not already retrieved
if
[[
-z
"
${
user_quota_map
[
$owner
]
}
"
]]
;
then
user_info
=
$(
radosgw-admin user info
--uid
=
"
$owner
"
)
user_quota_size
=
$(
echo
"
$user_info
"
| jq
-r
'.user_quota.max_size'
)
# Handle cases where quota is not set
if
[
"
$user_quota_size
"
=
"null"
]
;
then
user_quota_size
=
-1
# No quota
fi
user_quota_map[
$owner
]=
$user_quota_size
fi
done
# Print the sorted bucket table
echo
"Bucket Usage Table:"
print_header
()
{
printf
"%-25s %-20s %-15s
\n
"
"Bucket"
"Owner"
"Usage"
}
print_header
sort
-nr
$bucket_tmp_file
|
while
read
usage bucket owner
;
do
usage_human
=
$(
human_readable
"
$usage
"
)
printf
"%-25s %-20s %-15s
\n
"
"
$bucket
"
"
$owner
"
"
$usage_human
"
done
# Now, print the sorted user usage totals as a table with quota and percentage used
echo
-e
"
\n
User Usage Totals:"
user_tmp_file
=
$(
mktemp
)
total_accumulated_quota
=
0
total_accumulated_usage
=
0
for
user
in
"
${
!user_usage_map[@]
}
"
;
do
echo
"
${
user_usage_map
[
$user
]
}
$user
"
>>
$user_tmp_file
# Accumulate total usage and quota
total_accumulated_usage
=
$((
$total_accumulated_usage
+
${
user_usage_map
[
$user
]
}))
if
[[
${
user_quota_map
[
$user
]
}
-ne
-1
]]
;
then
total_accumulated_quota
=
$((
$total_accumulated_quota
+
${
user_quota_map
[
$user
]
}))
fi
done
printf
"%-20s %-15s %-15s %-15s
\n
"
"User"
"Total Usage"
"Quota"
"Usage (%)"
printf
"%-20s %-15s %-15s %-15s
\n
"
"----"
"-----------"
"-----"
"---------"
sort
-nr
$user_tmp_file
|
while
read
usage user
;
do
user_usage_human
=
$(
human_readable
"
$usage
"
)
user_quota
=
${
user_quota_map
[
$user
]
}
if
[
"
$user_quota
"
-eq
-1
]
;
then
user_quota_human
=
"No quota"
percentage
=
"N/A"
else
user_quota_human
=
$(
human_readable
"
$user_quota
"
)
percentage
=
$(
echo
"scale=2;
$usage
/
$user_quota
*100"
| bc
)
fi
printf
"%-20s %-15s %-15s %-15s
\n
"
"
$user
"
"
$user_usage_human
"
"
$user_quota_human
"
"
$percentage
%"
done
# Retrieve the global default quota for the RGW bucket pool using the ceph command
global_default_quota_human
=
$(
ceph osd pool get-quota default.rgw.buckets.data 2>/dev/null |
grep
"max bytes"
|
awk
'{print $4, $5}'
)
# Convert the human-readable global quota to bytes
global_default_quota
=
$(
convert_to_bytes
"
$global_default_quota_human
"
)
# Convert the global quota to human-readable form for display
global_default_quota_human_readable
=
$(
human_readable
"
$global_default_quota
"
)
# Calculate the percentages
total_quota_percentage
=
$(
echo
"scale=2;
$total_accumulated_quota
/
$global_default_quota
*100"
| bc
)
total_usage_percentage
=
$(
echo
"scale=2;
$total_accumulated_usage
/
$global_default_quota
*100"
| bc
)
echo
-e
"
\n\n
------------------GLOBAL STATS-------------------------------"
# Display the global quota and accumulated values
echo
-e
"
\n\n
Global Default Quota:"
echo
"Global default quota for the RGW bucket pool:
$global_default_quota_human_readable
"
# Display total accumulated quotas and usage
echo
-e
"
\n\n
Accumulated Quota and Usage:"
echo
-e
"
\n
Total accumulated quota of all users:
$(
human_readable
$total_accumulated_quota
)
"
echo
"Percentage of accumulated quota vs. global quota:
$total_quota_percentage
%"
echo
-e
"
\n\n
Total accumulated usage of all users:
$(
human_readable
$total_accumulated_usage
)
"
echo
"Percentage of accumulated usage vs. global quota:
$total_usage_percentage
%"
# Cleanup temporary files
rm
-f
$bucket_tmp_file
rm
-f
$user_tmp_file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment