1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
'use strict';
var HistogramState = {
fetchInterval: 300000,
retryInterval: 5000,
loading: false,
scheduledLoad: false,
ops: new Map(),
};
function onHistogramLoaded(data) {
HistogramState.loading = false;
if (data['Status']['Code'] != 'SUCCESS') {
onHistogramFailed(data);
return;
}
$('#ds-hist-error').html('');
$('#ds-hist-tables').empty();
if (data.TableHistograms) {
for (var table of data.TableHistograms) {
addTableHistograms(table);
}
}
$('#ds-ops-list-table').trigger('update', [true]);
scheduleLoadHistogram(HistogramState.fetchInterval);
}
function addTableHistograms(data) {
var tableName = data.TableName;
var keys = data.KeyNames;
if (data.SizeHistogram)
addHistogram(tableName, keys, 'Data size', data.SizeHistogram)
if (data.CountHistogram)
addHistogram(tableName, keys, 'Rows count', data.CountHistogram)
if (data.KeyAccessSample)
addHistogram(tableName, keys, 'Key access sample', data.KeyAccessSample)
}
function addHistogram(tableName, keys, histName, hist) {
var headCells = `<th data-sorter="false">${histName}</th>`;
for (var key of keys)
headCells += `<th data-sorter="false">${key}</th>`;
var bodyRows = '';
if (hist.Items) {
for (var item of hist.Items) {
var rowCells = `<td>${item.Value}</td>`;
for (var val of item.KeyValues)
rowCells += `<td>${val}</td>`;
bodyRows += `<tr>${rowCells}</tr>`;
}
}
var table = $(`
<table class="tablesorter">
<caption class="ds-info">${histName} histogram for ${tableName}</caption>
<thead>
<tr>${headCells}</tr>
</thead>
<tbody>${bodyRows}</tbody>
</table>
`);
table.appendTo($('#ds-hist-tables'));
table.tablesorter({
theme: 'blue',
sortList: [],
widgets : ['zebra'],
});
console.log(table);
}
function onHistogramFailed(data) {
HistogramState.loading = false;
if (data && data['Status'] && data['Status']['Issues'])
$('#ds-hist-error').html(JSON.stringify(data['Status']['Issues']));
else
$('#ds-hist-error').html("Cannot get data histograms");
scheduleLoadHistogram(HistogramState.retryInterval);
}
function loadHistogram() {
if (HistogramState.loading)
return;
if (!$('#ds-hist-link').hasClass('active'))
return;
HistogramState.loading = true;
var url = '../cms/api/datashard/json/getdatahist?tabletid=' + TabletId;
$.get(url).done(onHistogramLoaded).fail(onHistogramFailed);
}
function scheduledLoadHistogram() {
HistogramState.scheduledLoad = false;
loadHistogram();
}
function scheduleLoadHistogram(timeout) {
if (HistogramState.scheduledLoad)
return;
HistogramState.scheduledLoad = true;
setTimeout(scheduledLoadHistogram, timeout);
}
function initHistogramTab() {
$(document).on('shown.bs.tab', '', function(e) {
if (e.target.id == 'ds-hist-link') {
$('#ds-size-hist-table').tablesorter({
theme: 'blue',
sortList: [],
widgets : ['zebra'],
});
$('#ds-count-hist-table').tablesorter({
theme: 'blue',
sortList: [],
widgets : ['zebra'],
});
scheduleLoadHistogram(0);
}
});
loadHistogram();
}
|