Commit 8b741bd2 authored by MaksimSmile13's avatar MaksimSmile13 Committed by Andrey Vertiprahov
Browse files

Fix

1) If one object metric, group metric open, else close
2) Add YY:MM:DD:MM format for Uptime metric
parent 70c9b9f1
......@@ -31,6 +31,7 @@ from noc.inv.models.firmwarepolicy import FirmwarePolicy
from noc.sa.models.servicesummary import ServiceSummary
from noc.core.text import alnum_key, list_to_ranges
from noc.maintenance.models.maintenance import Maintenance
from noc.pm.models.thresholdprofile import ThresholdProfile
from noc.sa.models.useraccess import UserAccess
from noc.core.pm.utils import get_interface_metrics, get_objects_metrics
from noc.pm.models.metrictype import MetricType
......@@ -55,9 +56,32 @@ class ManagedObjectCard(BaseCard):
# get data function
def get_data(self):
intervals = (
("y", 31557617), # 60 * 60 * 24 * 7 * 52
("w", 604800), # 60 * 60 * 24 * 7
("d", 86400), # 60 * 60 * 24
("h", 3600), # 60 * 60
("m", 60),
("s", 1),
)
def display_time(seconds):
result = []
for name, count in intervals:
value = seconds // count
if value:
seconds -= value * count
if value == 1:
name = name.rstrip("s")
result.append("{}{}".format(value, name))
return ", ".join(result[:-1])
def sortdict(dct):
kys = sorted(dct.keys())
res = OrderedDict()
for x in sorted(dct):
for x in kys:
for k, v in dct.items():
if k == x:
res[k] = v
......@@ -189,14 +213,48 @@ class ManagedObjectCard(BaseCard):
objects_metrics, last_time = get_objects_metrics(mo[0])
objects_metrics = objects_metrics.get(mo[0])
meta = {}
m_tp = {}
if mo[0].object_profile.metrics:
for mt in mo[0].object_profile.metrics:
if mt.get("threshold_profile"):
threshold_profile = ThresholdProfile.get_by_id(mt.get("threshold_profile"))
m_tp[MetricType.get_by_id(mt.get("metric_type")).name] = threshold_profile
data = {}
meta = []
metric_type_name = dict(MetricType.objects.filter().scalar("name", "measure"))
metric_type_field = dict(MetricType.objects.filter().scalar("field_name", "measure"))
if objects_metrics:
for path, mres in objects_metrics.items():
t_v = False
for key in mres:
metric_name = "%s | %s" % (key, path) if any(path.split("|")) else key
meta[metric_name] = {"type": metric_type_name[key], "value": mres[key]}
m_path = path if any(path.split("|")) else key
m_path = " | ".join(kk.strip() for kk in m_path.split("|"))
if m_tp.get(key):
t_v = self.get_threshold_config(m_tp.get(key), int(mres[key]))
val = {
"name": m_path,
"type": "" if m_path == "Object | SysUptime" else metric_type_name[key],
"value": display_time(int(mres[key]))
if m_path == "Object | SysUptime"
else mres[key],
"threshold": t_v,
}
if data.get(key):
data[key] += [val]
else:
data[key] = [val]
data = sortdict(data)
for k, d in data.items():
collapsed = False
if len(d) == 1:
collapsed = True
for dd in d:
isdanger = False
if dd["threshold"]:
isdanger = True
collapsed = True
meta.append({"name": k, "value": d, "collapsed": collapsed, "isdanger": isdanger})
for i in Interface.objects.filter(managed_object=self.object.id, type="physical"):
load_in = "-"
......@@ -364,7 +422,7 @@ class ManagedObjectCard(BaseCard):
"links": links,
"alarms": alarm_list,
"interfaces": interfaces,
"metrics": sortdict(meta),
"metrics": meta,
"maintenance": maintenance,
"redundancy": redundancy,
"inventory": self.flatten_inventory(inv),
......
......@@ -7,10 +7,11 @@
<link rel="stylesheet" href="{{ hashed("/ui/pkg/bootstrap/css/bootstrap.min.css") }}">
<!-- Optional theme -->
<link rel="stylesheet" href="{{ hashed("/ui/pkg/bootstrap/css/bootstrap-theme.min.css") }}">
<!-- Latest compiled and minified JavaScript -->
<!--<script src="/ui/pkg/bootstrap/bootstrap/3.3.6/js/bootstrap.min.js"></script>-->
<!-- Fonts -->
<link rel="stylesheet" href="{{ hashed("/ui/pkg/fontawesome/css/font-awesome.min.css") }}">
<!-- Latest compiled and minified JavaScript -->
<script src="{{ hashed("/ui/pkg/jquery/jquery.min.js") }}"></script>
<script type="text/javascript" src="{{ hashed("/ui/pkg/bootstrap/js/bootstrap.min.js") }}"></script>
{% if card_js -%}
{% for js in card_js -%}
<script src="{{ hashed(js) }}"></script>
......
......@@ -5,6 +5,18 @@
width: 100%;
height: 1px;
}
.metric-header .fa {
transition: .3s transform ease-in-out;
}
.metric-header .collapsed .fa {
transform: rotate(90deg);
}
.row-bordered:after {
content: "";
display: block;
border-bottom: 1px solid #c0c0c0;
}
</style>
<div class="panel-{{ {'up': 'success', 'alarm': 'warning', 'down': 'danger', 'unmanaged': 'default'}[current_state] }}">
<div class="panel-heading">
......@@ -227,32 +239,43 @@
{% endif %}
{% if metrics %}
<div class="row">
<div class="col-sm-1">
<div class="col-se-1">
<b>{{ _("Metrics") }}</b>
</div>
<div class="col-sm-10">
<table class="table table-condensed table-hover">
<thead>
<th>{{ _("Name") }}</th>
<th>{{ _("Value") }}</th>
</thead>
<tbody>
{% for m in metrics %}
<tr>
<td>{{ m }}</td>
{% if metrics[m]["type"] != "bool" %}
{% if metrics[m]["type"] == "C" %}
<td>{{ metrics[m]["value"] }}<sup>o</sup>{{ metrics[m]["type"] }} </td>
{% else %}
<td>{{ metrics[m]["value"] }}{{ metrics[m]["type"] }} </td>
{% endif %}
{% else %}
<td> {{ metrics[m]["value"] }} </td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
<div class="panel-group">
{% for m in metrics %}
<div class="panel" style="width: 50%">
<div class="panel-heading metric-header{%- if m.isdanger %} bg-danger{% endif %}"
style="padding: 0;">
<a data-toggle="collapse" {% if not m.collapsed %} class="collapsed" {% endif %} href="#metric-{{ loop.index }}">
<i class="fa fa-chevron-down pull-right"></i>
{{ m.name }}
</a>
</div>
<div id="metric-{{ loop.index }}" class="panel-collapse collapse {% if m.collapsed %} in {% endif %}">
<div class="panel-body">
{% for v in m.value %}
<div class="row row-bordered {% if v.threshold %} bg-danger{% endif %}">
<div class="col-sm-7 col-sm-offset-1">
{{ v.name }}
</div>
{% if v.type != "bool" %}
{% if v.type == "C" %}
<div class="col-sm-4">{{ v.value }}<sup>o</sup>{{ v.type }}</div>
{% else %}
<div class="col-sm-4">{{ v.value }}{{ v.type }}</div>
{% endif %}
{% else %}
<div class="col-sm-4">{{ v.value }}</div>
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div> <!-- row-->
<div class="line"></div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment