Skip to content

Commit

Permalink
Merge pull request #52 from eslam-gomaa/feat/support-auto-convert-met…
Browse files Browse the repository at this point in the history
…ric-units-per-column-for-advancedTable-data-type

support autoConvertValue on the metric level for advancedTable data type
  • Loading branch information
eslam-gomaa authored Jun 29, 2024
2 parents 0db1bb3 + a518f0c commit f1fb4fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
22 changes: 10 additions & 12 deletions examples/dashboards/pods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ dashboard:
left_a:
size: 0
ratio: 1
# left_b:
# size: 25
# ratio: 1
# left_c:
# size: 0
# ratio: 1
# left_d:
# size: 0
# ratio: 1
middle:
enable: false
size: 0
Expand Down Expand Up @@ -102,8 +93,9 @@ dashboard:
box: right_a
type: asciiGraph # || progressBarList || asciiText
metricUnit: mb
# Sorting is important if you expect lots of results
metric: >
sum(container_memory_usage_bytes{namespace=~"$namespace", pod=~"$pod", pod!=""}) by (pod) / 1024 / 1024
sort_desc(sum(container_memory_usage_bytes{namespace=~"$namespace", pod=~"$pod", pod!=""}) by (pod) / 1024 / 1024)
custom_key: "🥕 {{pod}}"
asciiGraphOptions:
height: 0
Expand Down Expand Up @@ -161,6 +153,7 @@ dashboard:
metric: |
sort_desc(sum(container_memory_usage_bytes{namespace=~"$namespace", pod=~"$pod", pod!=""}) by (pod, topology_ebs_csi_aws_com_zone))
metricUnit: byte
autoConvertValue: true
- memory usage %:
metric: |
sort_desc(
Expand All @@ -171,19 +164,22 @@ dashboard:
) * 100
)
metricUnit: percentage
autoConvertValue: true
- memory limit:
metric: |
sort_desc(sum(container_spec_memory_limit_bytes{namespace=~"$namespace", pod=~"$pod", pod!=""}) by (pod, topology_ebs_csi_aws_com_zone))
metricUnit: byte
autoConvertValue: true
- memory cache:
metric: |
sort_desc(sum(container_memory_cache{namespace=~"$namespace", pod=~"$pod", pod!=""}) by (pod, topology_ebs_csi_aws_com_zone))
metricUnit: byte
autoConvertValue: true
- memory swap:
metric: |
sum(container_memory_swap{namespace=~"$namespace", pod=~"$pod", pod!=""}) by (pod, topology_ebs_csi_aws_com_zone)
metricUnit: byte
autoConvertValdue: true
autoConvertValue: true
# - file descriptors:
# metric: |
# sort_desc(sum(container_file_descriptors{namespace=~"$namespace", pod=~"$pod"}) by (pod, topology_ebs_csi_aws_com_zone))
Expand All @@ -193,15 +189,17 @@ dashboard:
100 * sum(irate(container_cpu_usage_seconds_total{image!="", container!="POD", namespace=~"$namespace", pod!=""}[5m])) by (pod, namespace) /
sum(kube_pod_container_resource_limits{namespace=~"$namespace", container!="POD", pod!=""}) by (pod, namespace)
metricUnit: percentage
autoConvertValue: true
- AWS AZ:
metric: |
sort_desc(sum(container_memory_usage_bytes{namespace=~"$namespace", pod=~"$pod", pod!=""}) by (pod, topology_ebs_csi_aws_com_zone))
metricUnit: byte
autoConvertValue: true
valueFromLabel: topology_ebs_csi_aws_com_zone
custom_key: "{{pod}}" # "{{pod}} - {{topology_ebs_csi_aws_com_zone}}"
advancedTableOptions:
tableType: plain # https://github.com/astanin/python-tabulate?tab=readme-ov-file#table-format
headersUppercase: true
autoConvertValue: true
# autoConvertValue: true
showTableIndex: true
updateIntervalSeconds: 3
4 changes: 1 addition & 3 deletions kubePtop/dashboard_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,14 +656,12 @@ def build_advanced_table(self, name, layout_box_name, advanced_table_options, me
table_type_ = advanced_table_options.get("tableType", 'plain')
# show_value_ = advanced_table_options.get("showValue", True)
header_upper_case_ = advanced_table_options.get("headersUppercase", True)
auto_convert_value_ = advanced_table_options.get("autoConvertValue", True)
show_table_index_ = advanced_table_options.get("showTableIndex", True)
update_interval_ = advanced_table_options.get("updateIntervalSeconds", 5)
else:
table_type_ = 'plain'
# show_value_ = True
header_upper_case_ = True
auto_convert_value_ = True
show_table_index_ = True
update_interval_ = 5

Expand All @@ -685,7 +683,7 @@ def build_advanced_table(self, name, layout_box_name, advanced_table_options, me
while True:
table = [header]
for column, column_info in columns_dct.items():

auto_convert_value_ = column_info.get('autoConvertValue', False)
metric_data = self.get_metric_data(column_info['metric'], custom_key=custom_key, value_from_label=column_info.get('valueFromLabel', ''))

if not metric_data['success']:
Expand Down
10 changes: 5 additions & 5 deletions kubePtop/dashboard_yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,11 @@ def validate_dashboard_schema(self, dashboard_yaml_data):
'required': True,
'default': True,
},
'autoConvertValue': {
'type': 'boolean',
'required': True,
'default': False,
},
# 'autoConvertValue': {
# 'type': 'boolean',
# 'required': True,
# 'default': False,
# },
'showTableIndex': {
'type': 'boolean',
'required': True,
Expand Down

0 comments on commit f1fb4fc

Please sign in to comment.