Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lofar-scripts-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vlad Kondratiev
lofar-scripts-repo
Commits
a1f4d772
Commit
a1f4d772
authored
4 months ago
by
Vlad Kondratiev
Browse files
Options
Downloads
Patches
Plain Diff
added new script to get info about volume usage on CEP4
parent
3c4f0199
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
l2com/cep4-usage.py
+81
-0
81 additions, 0 deletions
l2com/cep4-usage.py
with
81 additions
and
0 deletions
l2com/cep4-usage.py
0 → 100755
+
81
−
0
View file @
a1f4d772
#!/usr/bin/env python
#
#
import
os
,
sys
,
re
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
subprocess
import
datetime
targetdir
=
"
/data/projects
"
globdir
=
"
/data
"
def
human_size
(
size
,
f
):
if
(
size
/
f
<
1
):
return
"
%ldB
"
%
(
size
)
if
(
size
/
f
/
f
<
1
):
return
"
%.1fk
"
%
(
size
/
f
)
if
(
size
/
f
/
f
/
f
<
1
):
return
"
%.1fM
"
%
(
size
/
f
/
f
)
if
(
size
/
f
/
f
/
f
/
f
<
1
):
return
"
%.1fG
"
%
(
size
/
f
/
f
/
f
)
if
(
size
/
f
/
f
/
f
/
f
/
f
<
1
):
return
"
%.1fT
"
%
(
size
/
f
/
f
/
f
/
f
)
def
duh
(
path
):
"""
disk usage in human readable format (e.g.
'
2.1GB
'
)
"""
return
subprocess
.
check_output
([
'
du
'
,
'
-sh
'
,
path
]).
split
()[
0
].
decode
(
'
utf-8
'
)
def
duB
(
path
):
"""
disk usage in bytes format
"""
return
subprocess
.
check_output
([
'
du
'
,
'
-sB 1
'
,
path
]).
split
()[
0
].
decode
(
'
utf-8
'
)
text
=
""
p
=
os
.
popen
(
'
df -H %s
'
%
(
globdir
))
for
line
in
p
.
readlines
():
text
+=
line
projects
=
{}
files
=
[
f
for
f
in
os
.
listdir
(
targetdir
)
if
os
.
path
.
isdir
(
os
.
path
.
join
(
targetdir
,
f
))
and
f
[
0
]
!=
"
.
"
]
text
+=
"
\n
"
+
"
-
"
*
55
text
+=
"
\n
%-30s %10s
\n
"
%
(
"
Project
"
,
"
Size
"
)
text
+=
"
"
+
"
-
"
*
55
text
+=
"
\n
"
for
f
in
files
:
dirsize
=
duh
(
os
.
path
.
join
(
targetdir
,
f
))
dirsize_in_bytes
=
duB
(
os
.
path
.
join
(
targetdir
,
f
))
projects
[
f
]
=
(
dirsize
,
dirsize_in_bytes
)
text
+=
"
%-30s %10s
\n
"
%
(
f
,
dirsize
)
text
+=
"
"
+
"
-
"
*
55
labels
=
np
.
array
([
str
(
ii
)
for
ii
in
projects
.
keys
()])
sizes
=
[
float
(
s
)
for
(
d
,
s
)
in
projects
.
values
()]
total
=
np
.
sum
(
sizes
)
sizes_percent
=
np
.
array
([
s
*
100.
/
total
for
s
in
sizes
])
text
+=
"
\n
%-30s %10s
"
%
(
"
Total
"
,
human_size
(
total
,
1024
))
now
=
datetime
.
datetime
.
utcnow
()
updated
=
"
Updated: %s UTC
"
%
(
now
)
pie_labels
=
[]
pie_sizes
=
[]
rest_size
=
0.
for
(
l
,
s
)
in
zip
(
labels
,
sizes_percent
):
if
s
<
1.0
:
rest_size
+=
s
else
:
pie_labels
.
append
(
l
)
pie_sizes
.
append
(
s
)
pie_labels
.
append
(
"
others
"
)
pie_sizes
.
append
(
rest_size
)
fig
,
(
ax1
,
ax2
)
=
plt
.
subplots
(
1
,
2
,
figsize
=
(
10
,
5
))
fig
.
suptitle
(
"
CEP4 /data volume usage
"
)
ax1
.
annotate
(
text
,
xycoords
=
"
axes fraction
"
,
xy
=
(
0.0
,
0.99
),
bbox
=
dict
(
facecolor
=
'
0.95
'
,
boxstyle
=
"
round
"
),
ha
=
'
left
'
,
va
=
'
top
'
,
multialignment
=
"
left
"
,
zorder
=
2
,
fontsize
=
10
)
ax1
.
annotate
(
updated
,
xycoords
=
"
axes fraction
"
,
xy
=
(
0.0
,
0.0
),
ha
=
'
left
'
,
va
=
'
bottom
'
,
multialignment
=
"
left
"
,
zorder
=
2
,
fontsize
=
8
)
ax1
.
axis
(
'
off
'
)
ax2
.
pie
(
pie_sizes
,
labels
=
pie_labels
,
autopct
=
'
%1.1f%%
'
)
#, pctdistance=1.25, labeldistance=.6)
plt
.
tight_layout
()
plt
.
gcf
().
set_size_inches
(
10
,
5
)
# Width=10in, Height=5in
plt
.
savefig
(
"
cep4-usage.png
"
,
bbox_inches
=
'
tight
'
,
dpi
=
100
)
# output figure size will be (10,5)x100 in pixels
plt
.
show
()
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