Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

Commit afd6065

Browse files
committed
Merge branch 'GHOST-724-error-500-on-health-status-page' into 'master'
GHOST-724: catch exception if NIC status is unavailable Closes GHOST-724 See merge request claranet/cloudnative/projects/ghost/flask-ui!1
2 parents 5c3a6e5 + 7a43593 commit afd6065

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

health.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Library to easily manage Host Health"""
44

55
from __future__ import division
6+
import logging
67
import psutil
78
import threading
89
import time
@@ -70,10 +71,13 @@ def get_host_health(cpu_percent, cpu_percent_details):
7071

7172
status['boot_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(psutil.boot_time()))
7273

73-
status['network_stats'] = psutil.net_if_stats()
74-
for (key, item) in status['network_stats'].items():
75-
status['network_stats'][key] = status['network_stats'][key]._replace(duplex=duplex_map[item.duplex])
76-
status['network_io'] = psutil.net_io_counters(pernic=True)
74+
try:
75+
status['network_stats'] = psutil.net_if_stats()
76+
for (key, item) in status['network_stats'].items():
77+
status['network_stats'][key] = status['network_stats'][key]._replace(duplex=duplex_map[item.duplex])
78+
status['network_io'] = psutil.net_io_counters(pernic=True)
79+
except OSError as err:
80+
logging.error("Error while reading NIC status: {}}".format(err))
7781

7882
return status
7983

templates/ghost_health_status_content.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ <h4><i class="fa fa-clock-o"></i> Boot date</h4>
3838
<br />
3939
<h4><i class="fa fa-wifi"></i> Network</h4>
4040
<div class="health-network-wrap">
41-
{% for nic in status['network_io'] %}
42-
{% if nic != 'lo' %}
43-
{% set nic_stats = status.network_stats[nic] %}
44-
<p class="health-info">stats: speed={{ nic_stats.speed}}MB, duplex={{ nic_stats.duplex}}, mtu={{ nic_stats.mtu}}, up={{ "yes" if nic_stats.isup else "no" }}</p>
45-
{% set nic_io = status.network_io[nic] %}
46-
<p class="health-info">incoming: bytes={{ nic_io.bytes_recv }}, pkts={{ nic_io.packets_recv }}, err={{ nic_io.errin }}, drops={{ nic_io.dropin }}</p>
47-
<p class="health-info">outgoing: bytes={{ nic_io.bytes_sent }}, pkts={{ nic_io.packets_sent }}, err={{ nic_io.errout }}, drops={{ nic_io.dropout }}</p>
48-
{% endif %}
49-
{% endfor %}
41+
{% if not 'network_io' in status %}
42+
<p class="health-info">N/A</p>
43+
{% else %}
44+
{% for nic in status['network_io'] %}
45+
{% if nic != 'lo' %}
46+
{% set nic_stats = status.network_stats[nic] %}
47+
<p class="health-info">stats: speed={{ nic_stats.speed}}MB, duplex={{ nic_stats.duplex}}, mtu={{ nic_stats.mtu}}, up={{ "yes" if nic_stats.isup else "no" }}</p>
48+
{% set nic_io = status.network_io[nic] %}
49+
<p class="health-info">incoming: bytes={{ nic_io.bytes_recv }}, pkts={{ nic_io.packets_recv }}, err={{ nic_io.errin }}, drops={{ nic_io.dropin }}</p>
50+
<p class="health-info">outgoing: bytes={{ nic_io.bytes_sent }}, pkts={{ nic_io.packets_sent }}, err={{ nic_io.errout }}, drops={{ nic_io.dropout }}</p>
51+
{% endif %}
52+
{% endfor %}
53+
{% endif %}
5054
</div>
5155
</div>
5256

0 commit comments

Comments
 (0)