-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /app/efficiency reporting cache hit rate
- Loading branch information
1 parent
bff930e
commit fa72b46
Showing
11 changed files
with
322 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (C) 2024 SUSE LLC | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, see <http://www.gnu.org/licenses/>. | ||
|
||
package MirrorCache::WebAPI::Controller::App::Efficiency; | ||
use Mojo::Base 'MirrorCache::WebAPI::Controller::App::Table'; | ||
|
||
sub index { | ||
my $c = shift; | ||
|
||
$c->render('app/efficiency/index'); | ||
} | ||
|
||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (C) 2021 SUSE LLC | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, see <http://www.gnu.org/licenses/>. | ||
|
||
package MirrorCache::WebAPI::Controller::Rest::Efficiency; | ||
use Mojo::Base 'Mojolicious::Controller'; | ||
use Mojo::Promise; | ||
use Data::Dumper; | ||
|
||
sub list { | ||
my ($self) = @_; | ||
|
||
my $period = $self->param('period') // 'hour'; | ||
my $limit = 30; | ||
|
||
my $tx = $self->render_later->tx; | ||
|
||
my $rendered; | ||
my $handle_error = sub { | ||
return if $rendered; | ||
$rendered = 1; | ||
my @reason = @_; | ||
my $reason = scalar(@reason)? Dumper(@reason) : 'unknown'; | ||
$self->render(json => {error => $reason}, status => 500) ; | ||
}; | ||
|
||
my $res; | ||
my $p = Mojo::Promise->new->timeout(5); | ||
$p->then(sub { | ||
my $rs = $self->schema->resultset('Stat'); | ||
$res = $rs->select_efficiency($period, $limit); | ||
})->catch($handle_error)->then(sub { | ||
$self->render(json => $res); | ||
})->catch($handle_error); | ||
|
||
$p->resolve; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
% layout 'bootstrap'; | ||
% title 'Efficiency'; | ||
|
||
% content_for 'head' => begin | ||
<script> | ||
|
||
function updateHistoryChart(period) { | ||
var period1 = period + 'ly'; | ||
if (period === 'day') { | ||
period1 = 'daily'; | ||
} | ||
$.ajax({ | ||
url: '/rest/efficiency', | ||
method: 'GET', | ||
data: { | ||
period: period, | ||
}, | ||
success: function(response) { | ||
layout = { | ||
title: {text: 'Cache Efficiency ' + period1}, | ||
yaxis: { | ||
title: { | ||
text: "Count" | ||
} | ||
}, | ||
yaxis2: { | ||
title: { | ||
text: "Hit Rate", | ||
font: {color: "#0000FF"} | ||
}, | ||
overlaying: 'y', | ||
range: [0, 100], | ||
fixedrange: true, | ||
side: 'right' | ||
}, | ||
}; | ||
|
||
|
||
data = [ | ||
{name: 'hits', type: 'scatter', x: [], y: [], line: { color: "#00FF00", dash: 'solid', width: 2 }}, // hit | ||
{name: 'misses', type: 'scatter', x: [], y: [], line: { color: "#FF0000", dash: 'solid', width: 2 }}, // miss | ||
{name: 'passes', type: 'scatter', x: [], y: [], line: { color: "#FFFF00", dash: 'solid', width: 1 }}, // pass | ||
{name: 'bot', type: 'scatter', x: [], y: [], line: { color: "#A52A2A", dash: 'dashdot', width: 1 }}, // bot | ||
{name: 'geo', type: 'scatter', x: [], y: [], line: { color: "#220031", dash: 'dot', width: 1 }}, // geo | ||
{name: 'efficiency', type: 'scatter', x: [], y: [], line: { color: "#0000FF", dash: 'solid', width: 3 }, yaxis: 'y2'}, // hitrate | ||
]; | ||
|
||
response.forEach((element, index, array) => { | ||
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch | ||
d.setUTCSeconds(element.dt); | ||
data.forEach((e, i, a) => { | ||
data[i].x.push(d); | ||
}); | ||
data[0].y.push(element.hit); | ||
data[1].y.push(element.miss); | ||
data[2].y.push(element.pass); | ||
data[3].y.push(element.bot); | ||
data[4].y.push(element.geo); | ||
if (element.hit + element.miss > 0) { | ||
var rate = 100 * (element.hit / (eval(element.hit) + eval(element.miss))); | ||
rate = Math.round(rate); | ||
data[5].y.push(rate); | ||
} | ||
}); | ||
|
||
// Plotly.react('efficiency-chart', data, layout); | ||
Plotly.newPlot('efficiency-chart', data, layout); | ||
} | ||
}); | ||
} | ||
|
||
</script> | ||
% end | ||
|
||
|
||
% content_for 'ready_function' => begin | ||
document.getElementsByClassName('tablinks')[1].click() | ||
|
||
// updateHistoryChart(); | ||
% end | ||
|
||
|
||
<div class="tab"> | ||
<button class="tablinks" onclick="updateHistoryChart('hour')">Hourly</button> | ||
<button class="tablinks" onclick="updateHistoryChart('day')">Daily</button> | ||
<!-- button class="tablinks" onclick="updateHistoryChart('month')">Monthly</button --> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div id="efficiency-chart"></div> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters