Skip to content

Commit d1237b5

Browse files
authored
Merge pull request #753 from globocom/dev
Dev
2 parents 42eccb3 + 9102fee commit d1237b5

File tree

11 files changed

+16939
-8
lines changed

11 files changed

+16939
-8
lines changed

dbaas/admin/static/admin/css/datatables.css

Lines changed: 592 additions & 0 deletions
Large diffs are not rendered by default.

dbaas/admin/static/admin/css/datatables.min.css

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dbaas/admin/static/admin/js/datatables.js

Lines changed: 15633 additions & 0 deletions
Large diffs are not rendered by default.

dbaas/admin/static/admin/js/datatables.min.js

Lines changed: 213 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dbaas/admin/templates/admin/base.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<link rel="stylesheet" type="text/css" href="{% static "admin/css/bootstrap.min.css" %}" />
1515
<link rel="stylesheet" type="text/css" href="{% static "admin/css/bootstrap-responsive.min.css" %}" />
1616
<link rel="stylesheet" type="text/css" href="{% static "admin/css/notification.css" %}" />
17+
<link rel="stylesheet" type="text/css" href="{% static "admin/css/datatables.min.css" %}" />
1718

1819
<!-- Font Awesome -->
1920
<link rel="stylesheet" href="{% static "assets/css/font-awesome.min.css" %}">
@@ -192,6 +193,7 @@
192193
{% endblock js_footer_commons %}
193194
<script type="text/javascript" src="{% static 'admin/js/mustache2.js' %}"></script>
194195
<script type="text/javascript" src="{% static 'admin/js/notification.js' %}"></script>
196+
<script type="text/javascript" src="{% static 'admin/js/datatables.min.js' %}"></script>
195197

196198
<script type="text/javascript">
197199
Base.init(

dbaas/admin/templates/admin/base_site.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
{% if config_docs_url %}
1515
<a href="{{ config_docs_url }}" target="_blank" class="brand" id="site-docs">Docs</a>
1616
{% endif %}
17+
<a href="http://dbmonitor.globoi.com" target="_blank" class="brand" id="site-db-monitor">DBMonitor</a>
18+
1719
{% endblock %}
1820

1921
{% block nav-global %}{% endblock %}

dbaas/admin/templates/admin/index.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ <h2>{% trans 'My Actions' %}</h2>
7575
<div class="span12 app-list">
7676
{% endif %}
7777
{% if app_list %}
78-
<h2>{% trans 'Apps' %}</h2>
78+
<h2 id="apps-list-title">{% trans 'Apps' %}</h2>
7979
{% for app in app_list %}
80-
<table summary="{% blocktrans with name=app.name %}Models available in the {{ name }} application.{% endblocktrans %}" class="table table-striped table-hover table-bordered table-condensed">
80+
<table summary="{% blocktrans with name=app.name %}Models available in the {{ name }} application.{% endblocktrans %}" class="table table-striped table-hover table-bordered table-condensed" id="app-{{ app.app_label }}">
8181
<thead>
8282
<tr>
8383
<th colspan="4">
@@ -161,8 +161,18 @@ <h3>
161161
}
162162
}
163163

164+
reorder_apps = function(){
165+
first_app = 'logical';
166+
app = $(`#app-${first_app}`);
167+
app.clone().insertAfter('#apps-list-title')
168+
app.remove();
169+
}
170+
164171
$(window).resize(swap_if_necessary);
165-
$(document).ready(swap_if_necessary);
172+
$(document).ready(function() {
173+
reorder_apps();
174+
swap_if_necessary();
175+
});
166176
})(django.jQuery);
167177
</script>
168178
{% endblock js_footer %}

dbaas/drivers/redis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ def get_cluster_client(self, instance, default_timeout=False):
678678
{'host': instance.address, 'port': instance.port}
679679
for instance in self.instances_filtered
680680
],
681+
max_connections=None,
681682
password=self.databaseinfra.password,
682683
socket_timeout=REDIS_CONNECTION_DEFAULT_TIMEOUT if default_timeout else self.connection_timeout_in_seconds,
683684
socket_connect_timeout=REDIS_CONNECTION_SOCKET_TIMEOUT if default_timeout else self.connection_socket_timeout_in_seconds,

dbaas/logical/migrations/0036_auto__add_field_databasehistory_apps_bind_name.py

Lines changed: 385 additions & 0 deletions
Large diffs are not rendered by default.

dbaas/logical/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class DatabaseHistory(models.Model):
9797
description = models.TextField(
9898
verbose_name=_("Description"), null=True, blank=True
9999
)
100+
apps_bind_name = models.TextField(
101+
verbose_name=_("apps_bind_name"), null=True, blank=True
102+
)
100103

101104

102105
class Database(BaseModel):

dbaas/logical/templates/logical/database/details/cost_tab.html

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,39 @@ <h2>Period:</h2>
2121
</div>
2222
</div>
2323
</div>
24+
<div class="row-fluid" style="margin-top: 3em;">
25+
<table id="details-table" class="stripe hover dt-head-center">
26+
<thead>
27+
<tr>
28+
<th>DB Name</th>
29+
<th>Date</th>
30+
<th>Total Cost</th>
31+
<th>Infra Cost</th>
32+
<th>DBaaS Cost</th>
33+
<th>Service</th>
34+
<th>SKU</th>
35+
<th>Utilization</th>
36+
<th>Utilization Metric</th>
37+
</tr>
38+
</thead>
39+
<tbody>
40+
41+
</tbody>
42+
<tfoot>
43+
<tr>
44+
<th>DB Name</th>
45+
<th>Date</th>
46+
<th>Total Cost</th>
47+
<th>Infra Cost</th>
48+
<th>DBaaS Cost</th>
49+
<th>Service</th>
50+
<th>SKU</th>
51+
<th>Utilization</th>
52+
<th>Utilization Metric</th>
53+
</tr>
54+
</tfoot>
55+
</table>
56+
</div>
2457

2558
{% endblock %}
2659

@@ -40,14 +73,25 @@ <h2>Period:</h2>
4073

4174
$(document).ready(function(){
4275
$(".form-actions").hide();
43-
$.get(costApi + infraName, function(data){
76+
$("#details-table").hide(); // hide table headers while there is no data
77+
78+
var todayDate = new Date();
79+
var [past30daysDate] = new Date(new Date().setDate(todayDate.getDate() - 30)).toISOString().split("T"); // get the date from "today" minus 30 days, and format it to ISO string whitout the time Eg. (2022-07-02)
80+
todayDate = todayDate.toISOString().split("T")[0]; // convert "today" Date object to ISO string without the time. Eg. (2022-08-01)
81+
82+
var url = `${costApi}${infraName}/${past30daysDate}/${todayDate}`
83+
$.get(url, function(data){
4484
var [labels, costs] = [[], []];
4585
data.items.forEach(function(item){
46-
labels.push(item.usage_date)
47-
costs.push(
48-
item.cost
49-
)
86+
var index = labels.indexOf(item.usage_date);
87+
if (index !== -1) {
88+
costs[index] += item.cost;
89+
} else {
90+
labels.push(item.usage_date);
91+
costs.push(item.cost);
92+
}
5093
})
94+
5195
const chartData = {
5296
labels: labels,
5397
datasets: [{
@@ -58,6 +102,37 @@ <h2>Period:</h2>
58102
tension: 0.1,
59103
}]
60104
};
105+
$("#details-table").show();
106+
$('#details-table').DataTable({
107+
data: data.items,
108+
columns: [
109+
{data: 'database_name'},
110+
{data: 'usage_date'},
111+
{
112+
data: 'cost',
113+
render: function (data, type, row) {
114+
return parseFloat(data).toFixed(2)
115+
}
116+
},
117+
{
118+
data: 'cost_infra',
119+
render: function (data, type, row) {
120+
return parseFloat(data).toFixed(2)
121+
}
122+
},
123+
{
124+
data: 'cost_dbaas',
125+
render: function (data, type, row) {
126+
return parseFloat(data).toFixed(2)
127+
}
128+
},
129+
{data: 'infra_service_description'},
130+
{data: 'infra_sku_description'},
131+
{data: 'utilization'},
132+
{data: 'utilization_metric'}
133+
],
134+
pageLength: 25
135+
});
61136

62137
const config = {
63138
type: 'line',

0 commit comments

Comments
 (0)