Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dfaast
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Santhosh Kumar
dfaast
Commits
4afabae0
Commit
4afabae0
authored
May 03, 2024
by
Santhosh Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup code
parent
adf37892
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
src/faas.py
src/faas.py
+20
-19
No files found.
src/faas.py
View file @
4afabae0
...
...
@@ -275,21 +275,25 @@ def get_deployment_info():
pod_name
=
pod
.
metadata
.
name
# Get resource metrics for the pod
metrics
=
metrics_api
.
get_namespaced_custom_object
(
group
=
"metrics.k8s.io"
,
version
=
"v1beta1"
,
namespace
=
namespace
,
plural
=
"pods"
,
name
=
pod_name
)
# Extract CPU and memory usage from metrics
cpu_usage
=
metrics
[
"containers"
][
0
][
"usage"
][
"cpu"
]
memory_usage
=
metrics
[
"containers"
][
0
][
"usage"
][
"memory"
]
# Accumulate total usage
cpu_usage_total
+=
int
(
cpu_usage
[:
-
1
])
# Convert string like "1234n" to int (removing "n" suffix)
memory_usage_total
+=
int
(
memory_usage
[:
-
2
])
# Convert string like "1234Ki" to int (removing "Ki" suffix)
print
(
pod_name
)
try
:
metrics
=
metrics_api
.
get_namespaced_custom_object
(
group
=
"metrics.k8s.io"
,
version
=
"v1beta1"
,
namespace
=
namespace
,
plural
=
"pods"
,
name
=
pod_name
)
# Extract CPU and memory usage from metrics
cpu_usage
=
metrics
[
"containers"
][
0
][
"usage"
][
"cpu"
]
memory_usage
=
metrics
[
"containers"
][
0
][
"usage"
][
"memory"
]
# Accumulate total usage
cpu_usage_total
+=
int
(
cpu_usage
[:
-
1
])
# Convert string like "1234n" to int (removing "n" suffix)
memory_usage_total
+=
int
(
memory_usage
[:
-
2
])
# Convert string like "1234Ki" to int (removing "Ki" suffix)
except
ApiException
as
e
:
pass
# Calculate average usage across all pods
num_pods
=
len
(
pods
)
...
...
@@ -312,11 +316,10 @@ def get_deployment_info():
if
e
.
status
==
404
:
exposed_url
=
"Not exposed"
else
:
raise
exposed_url
=
"service error "
# Get HPDA (HorizontalPodAutoscaler) if exists
hpa_name
=
f
"{deployment_name}-hpa"
print
(
"Iam here"
)
try
:
hpa
=
scale_api
.
read_namespaced_horizontal_pod_autoscaler
(
name
=
hpa_name
,
namespace
=
namespace
)
min_replicas
=
hpa
.
spec
.
min_replicas
...
...
@@ -337,11 +340,9 @@ def get_deployment_info():
hpa_info
=
"HPA Error"
# Get replica sets
print
(
"Iam here"
)
replica_sets
=
apps_api
.
list_namespaced_replica_set
(
namespace
=
deployment
.
metadata
.
namespace
)
.
items
# Print deployment info
print
(
"Iam here"
)
print
(
"{:<30} {:<15} {:<15} {:<20} {:<20} {:<20}"
.
format
(
deployment_name
,
replicas
,
json
.
dumps
(
limits
),
json
.
dumps
(
usage
),
exposed_url
,
json
.
dumps
(
hpa_info
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment