Skip to content

Commit

Permalink
add az distribution pie chart (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
knguyen100000010 authored Feb 16, 2024
1 parent 120cd39 commit c2d64a6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ <h4 class="panel-title pull-left">Group Config</h4>
</div>
{% endif %}

<div class="row">
<a type="button" href="/groups/{{ group_name }}/host-az-dist/"
class="deployToolTip btn btn-default btn-block"
data-toggle="tooltip" title="Show host ditribution among availability zones">
<span class="glyphicon glyphicon-stats"></span> Availability Zone Distribution
</a>
</div>

<div class="panel panel-default">
<div class="panel-heading clearfix">
<h4 class="panel-title pull-left">Environments</h4>
Expand Down
31 changes: 31 additions & 0 deletions deploy-board/deploy_board/templates/groups/host_az_dist.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% load utils %}

{% block content %}
<div id="container" style="width: 75%;">
<h2>Host Distribution Among Availability Zones</h2>
<canvas id="pie-chart"></canvas>
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
var config = {
type: 'pie',
data: {
datasets: [{
data: {{ data|safe }},
label: 'Host'
}],
labels: {{ labels|safe }}
},
options: {
responsive: false
}
};

window.onload = function() {
var ctx = document.getElementById('pie-chart').getContext('2d');
window.myPie = new Chart(ctx, config);
};
</script>

{% endblock %}
1 change: 1 addition & 0 deletions deploy-board/deploy_board/webapp/arcee_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
url(r'^groups/names', group_view.get_group_names),
url(r'^groups/search/(?P<group_name>[a-zA-Z0-9\-_]+)/$', group_view.search_groups),
url(r'^groups/search/$', group_view.group_landing),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/host-az-dist/$', group_view.get_host_az_dist),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/$', group_view.GroupDetailView.as_view()),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/config/$', group_view.GroupConfigView.as_view()),
url(r'^groups/(?P<group_name>[a-zA-Z0-9\-_]+)/envs/', group_view.get_envs),
Expand Down
18 changes: 17 additions & 1 deletion deploy-board/deploy_board/webapp/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
# limitations under the License.


from deploy_board.settings import IS_PINTEREST, PHOBOS_URL
from deploy_board.settings import CMDB_API_HOST, IS_PINTEREST, PHOBOS_URL
from django.middleware.csrf import get_token
from django.shortcuts import render, redirect
from django.views.generic import View
from django.template.loader import render_to_string
from django.http import HttpResponse
from django.contrib import messages
from django.contrib.messages import get_messages
from collections import Counter
import json
import requests
import logging
import traceback
from itertools import groupby
Expand Down Expand Up @@ -1464,6 +1466,20 @@ def get_health_check_activities(request, group_name):
})


def get_host_az_dist(request, group_name):
host_az_dist = requests.post(url = CMDB_API_HOST+"/v2/query", json={
"query": "tags.Autoscaling:{} AND state:running".format(group_name),
"fields": "location"
}
)

counter = Counter([x['location'] for x in host_az_dist.json()])

return render(request, 'groups/host_az_dist.tmpl', {
'labels': list(counter.keys()),
'data': list(counter.values()),
})

def get_health_check_details(request, id):
health_check = autoscaling_groups_helper.get_health_check(request, id)
env = environs_helper.get(request, health_check.get('env_id'))
Expand Down

0 comments on commit c2d64a6

Please sign in to comment.