Merge "Add Billing Statistics page"

This commit is contained in:
Jenkins 2014-04-29 14:45:19 +00:00 committed by Gerrit Code Review
commit 979ccb8950
9 changed files with 140 additions and 19 deletions

View File

@ -127,7 +127,6 @@ function remove_nodes(old_nodes, new_nodes){
}
function build_links(){
debugger;
for (var i=0;i<nodes.length;i++){
build_node_links(nodes[i]);
build_reverse_links(nodes[i]);

View File

@ -11,8 +11,12 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from muranodashboard.environments import api
from muranodashboard.environments import consts
from muranodashboard.common import utils
LOG = logging.getLogger(__name__)
class StatsModel(object):
@ -23,6 +27,68 @@ class StatsModel(object):
return st_list
class BillingStats(object):
def get_stats_for_env(self, request, environment_id):
st_list = api.muranoclient(request).instance_statistics.get(
environment_id)
return st_list
def get_all(self, request):
env_list = api.environments_list(request)
stats = []
LOG.debug('Got env list: {0}'.format(env_list))
for env in env_list:
env_entry = utils.Bunch(name=env.name,
id=env.id)
services = self.build_service_list(request, env)
LOG.debug('Processing env: {0}'.format(env))
env_stats = self.get_stats_for_env(request, env.id)
stats_list = []
for entry in env_stats:
instance_id = entry.instance_id
service = services[instance_id]
stat_entry = utils.Bunch(**entry.to_dict())
stat_entry.service = service['name']
stat_entry.service_type = service['type']
stats_list.append(stat_entry)
env_entry.instances = stats_list
stats.append(env_entry)
LOG.debug('Created statistics: {0}'.format(stats))
return stats
def _get_instances_ids(self, service):
# TODO(tsufiev): un-hardcode instance id detection
ids = []
def _rec(node):
if isinstance(node, dict) and node.get('?', {}).get('type'):
_type = node['?']['type']
if _type.endswith('Instance') or _type.endswith('Host'):
ids.append(node['?']['id'])
if isinstance(node, dict):
for _node in node.values():
_rec(_node)
elif isinstance(node, list):
for _node in node:
_rec(_node)
for item in service:
_rec(item)
return ids
def build_service_list(self, request, env):
serv_list = api.services_list(request, env.id)
LOG.debug('Got Service List: {0}'.format(serv_list))
id_list = {}
for service in serv_list:
ids = self._get_instances_ids(service)
storage = service['?'][consts.DASHBOARD_ATTRS_KEY]
info = {'name': storage['name'], 'type': service['?']['type']}
id_list.update(dict((_id, info) for _id in ids))
return id_list
class Stats(object):
def __init__(self, from_dict):
for k, v in from_dict.items():

View File

@ -19,26 +19,30 @@ from muranodashboard.stats import models
class APIStatsTab(tabs.Tab):
name = _("Murano API Servers")
slug = "_murano_srv"
slug = "murano_srv"
template_name = "stats/_api_srv.html"
preload = False
def get_context_data(self, request):
stm = models.StatsModel()
stats = stm.get_api_stats(request)
context = {}
context["api_servers"] = stats
stats = models.StatsModel().get_api_stats(request)
return {'api_servers': stats}
class InstanceStatsTab(tabs.Tab):
name = _("Murano Instance Statistics")
slug = "murano_eng"
template_name = "stats/_billing.html"
preload = False
def get_context_data(self, request):
stm = models.BillingStats()
stats = stm.get_all(request)
context = {'stats': stats,
'grp_id': 'murano_billing',
'offset': ''}
return context
class EngineStatsTab(tabs.Tab):
name = _("Murano Engine Servers")
slug = "_murano_eng"
template_name = "stats/_eng_srv.html"
def get_context_data(self, request):
pass
class StatsTabs(tabs.TabGroup):
slug = "stats_group"
tabs = (APIStatsTab, EngineStatsTab)
tabs = (InstanceStatsTab, APIStatsTab)

View File

@ -1,3 +1,3 @@
{% for srv in api_servers %}
{% include "stats/_srv_instance.html" with server=srv %}
{% include "stats/_srv_instance.html" with server=srv %}
{% endfor %}

View File

@ -0,0 +1,9 @@
{% load i18n sizeformat %}
<div class="panel-group {{ offset }}" id="{{ grp_id }}">
{% for env in stats %}
{% with parent=grp_id env=env t="stats/_billing_stats.html" %}
{% include t %}
{% endwith %}
{% endfor %}
</div>

View File

@ -0,0 +1,15 @@
<tr>
<td>
{{ instance.service }}
</td>
<td>
{{ instance.service_type }}
</td>
<td>
{{ instance.duration }} sec.
</td>
<td>
{{ instance.active }}
</td>
</tr>

View File

@ -0,0 +1,28 @@
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#{{ parent }}" href="#{{ env.id }}">
{{ env.name }}
</a>
</h4>
</div>
<div id="{{ env.id }}" class="panel-collapse collapse in">
<div class="panel-body">
<table class="table">
<thead>
<tr class="tablesorter-headerRow">
<th> Component Name </th>
<th> Component Type </th>
<th> Duration </th>
<th> Active </th>
</tr>
</thead>
{% for entry in env.instances %}
{% with instance=entry t="stats/_billing_entry.html" %}
{% include t %}
{% endwith %}
{% endfor %}
</table>
</div>
</div>
</div>

View File

@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Murano Stats" %}{% endblock %}
{% block title %}{% trans "Murano Statistics" %}{% endblock %}
{% block page_header %}
{% include "stats/_page_header.html" with title=_("Murano Server Stats") %}