Skip to content
This repository has been archived by the owner on Nov 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #976 from dneuman64/dev
Browse files Browse the repository at this point in the history
Updated scripted dashboards to use continuous queries
  • Loading branch information
Dewayne Richardson committed Jan 25, 2016
2 parents 5bd31cd + 03e3b5f commit af36270
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 102 deletions.
84 changes: 60 additions & 24 deletions traffic_ops/app/lib/Extensions/TrafficStats/API/CacheStats.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,78 @@ sub get_stat {
return $summary_content->{results}[0]{series}[0]{values}[0][1];
}

return "err";
return "";
}

sub current_bandwidth {
sub current_stats {
my $self = shift;
my $cdn = $self->param('cdnName');
my $query = "SELECT sum(value)/6 FROM \"bandwidth\" WHERE time < now() - 60s and time > now() - 120s";
if ($cdn) {
$query = "SELECT sum(value)/6 FROM \"bandwidth\" WHERE time < now() - 60s and time > now() - 120s and cdn = \'$cdn\'";
my @stats;
my $current_bw = $self->get_current_bandwidth();
my $conns = $self->get_current_connections();
my $capacity = $self->get_current_capacity();
my $rs = $self->db->resultset('Cdn');
while ( my $cdn = $rs->next ) {
my $cdn_name = $cdn->name;
my $bw = $current_bw->{$cdn_name};
my $conn = $conns->{$cdn_name};
my $cap = $capacity->{$cdn_name};
push(@stats, ({cdn => $cdn_name, bandwidth => $bw, connections => $conn, capacity => $cap}));
}
my $bandwidth = $self->get_stat("cache_stats", $query);
return $self->success({"bandwidth" => $bandwidth/1000000});
push(@stats, ({cdn => "total", bandwidth => $current_bw->{"total"}, connections => $conns->{"total"}}));
return $self->success({"currentStats" => \@stats});
}

sub current_connections {
sub get_current_bandwidth {
my $self = shift;
my $cdn = $self->param('cdnName');
my $query = "select sum(value)/6 from \"ats.proxy.process.http.current_client_connections\" where time > now() - 120s and time < now() - 60s";
if ($cdn) {
$query = "select sum(value)/6 from \"ats.proxy.process.http.current_client_connections\" where time > now() - 120s and time < now() - 60s and cdn = \'$cdn\'";
my $bw;
my $total_bw = 0;
my $rs = $self->db->resultset('Cdn');
while ( my $cdn = $rs->next ) {
my $cdn_name = $cdn->name;
my $query = "SELECT last(value) FROM \"monthly\".\"bandwidth.cdn.1min\" WHERE cdn = \'$cdn_name\'";
my $bandwidth = $self->get_stat("cache_stats", $query);
if ($bandwidth) {
$bw->{$cdn_name} = $bandwidth/1000000;
$total_bw += $bandwidth;
}
}
my $connections = $self->get_stat("cache_stats", $query);
return $self->success({"connections" => $connections});
$bw->{"total"} = $total_bw/1000000;
return $bw;
}

sub current_capacity {
sub get_current_connections {
my $self = shift;
my $cdn = $self->param('cdnName');
my $query = "select sum(value)/6 from \"maxKbps\" where time > now() - 120s and time < now() - 60s";
if ($cdn) {
$query = "select sum(value)/6 from \"maxKbps\" where time > now() - 120s and time < now() - 60s and cdn = \'$cdn\'";
my $conn;
my $total_conn = 0;
my $rs = $self->db->resultset('Cdn');
while ( my $cdn = $rs->next ) {
my $cdn_name = $cdn->name;
my $query = "select last(value) from \"monthly\".\"connections.cdn.1min\" where cdn = \'$cdn_name\'";
my $connections = $self->get_stat("cache_stats", $query);
if ($connections) {
$conn->{$cdn_name} = $connections;
$total_conn += $connections;
}
}
$conn->{"total"} = $total_conn;
return $conn;
}

sub get_current_capacity {
my $self = shift;
my $cap;
my $rs = $self->db->resultset('Cdn');
while ( my $cdn = $rs->next ) {
my $cdn_name = $cdn->name;
my $query = "select sum(value)/6 from \"maxKbps\" where time > now() - 120s and time < now() - 60s and cdn = \'$cdn_name\'";
my $capacity = $self->get_stat("cache_stats", $query);
if ($capacity) {
$capacity = $capacity/1000000; #convert to Gbps
$capacity = $capacity * 0.85; # need a better way to figure out percentage of max besides hard-coding
$cap->{$cdn_name} = $capacity;
}
}
my $capacity = $self->get_stat("cache_stats", $query);
$capacity = $capacity/1000000; #convert to Gbps
$capacity = $capacity * 0.85; # need a better way to figure out percentage of max besides hard-coding
return $self->success({"capacity" => $capacity});
return $cap;
}

sub daily_summary {
Expand Down
4 changes: 1 addition & 3 deletions traffic_ops/app/lib/TrafficOpsRoutes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,8 @@ sub traffic_stats_routes {
$r->get( "/api/$version/deliveryservice_stats" => [ format => [qw(json)] ] )->over( authenticated => 1 )
->to( 'DeliveryServiceStats#index', namespace => $namespace );
$r->get( "/api/$version/cache_stats" => [ format => [qw(json)] ] )->over( authenticated => 1 )->to( 'CacheStats#index', namespace => $namespace );
$r->get( "internal/api/$version/current_bandwidth" => [ format => [qw(json)] ] )->to( 'CacheStats#current_bandwidth', namespace => $namespace );
$r->get( "internal/api/$version/current_connections" => [ format => [qw(json)] ] )->to( 'CacheStats#current_connections', namespace => $namespace );
$r->get( "internal/api/$version/current_capacity" => [ format => [qw(json)] ] )->to( 'CacheStats#current_capacity', namespace => $namespace );
$r->get( "internal/api/$version/daily_summary" => [ format => [qw(json)] ] )->to( 'CacheStats#daily_summary', namespace => $namespace );
$r->get( "internal/api/$version/current_stats" => [ format => [qw(json)] ] )->to( 'CacheStats#current_stats', namespace => $namespace );
}

sub catch_all {
Expand Down
83 changes: 26 additions & 57 deletions traffic_ops/app/templates/visual_status/graphs.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,36 @@ $(function () {
</script>
<script>

function refreshStats()
{
% foreach my $cdn_name (sort @{ $cdn_names } ) {
getCurrentBandwidth("<%= $cdn_name %>");
getCurrentConnections("<%= $cdn_name %>");
% }
getCurrentBandwidth();
getCurrentConnections();

}

function getCurrentBandwidth(cdn_name) {
var bwUrl = "/internal/api/1.2/current_bandwidth.json";
if (cdn_name != null) {
var bandwidth = 0;
// get bandwidth
$.getJSON( bwUrl + "?cdnName=" + cdn_name, function() {})
.done(function(data) {
bandwidth = data.response.bandwidth.toFixed(2);
$('#' + cdn_name + '_gbps_val').text(bandwidth);
// get capacity
var capacityUrl = "/internal/api/1.2/current_capacity.json";
$.getJSON( capacityUrl + "?cdnName=" + cdn_name, function() {})
.done(function(data) {
var capacity = Math.round(data.response.capacity);
var percentage = Math.round(bandwidth/capacity * 100);
setProgress(cdn_name + "_percent_indicator", percentage);
setText(cdn_name + "_percent_indicator", "avail: " + capacity + ", used: " + percentage);
$('#' + cdn_name + '_gbps_val').text(bandwidth);
});
});

}
else {
$.getJSON( bwUrl, function() {})
.done(function(data) {
$('#total_gbps_val').text(data.response.bandwidth.toFixed(2));
});
}
}

function getCurrentConnections(cdn_name) {
var url = "/internal/api/1.2/current_connections.json";
if (cdn_name != null) {
$.getJSON( url + "?cdnName=" + cdn_name, function() {})
.done(function(data) {
var connections = Math.round(data.response.connections).toString();
$('#' + cdn_name + '_conn_val').text(connections.replace(/\B(?=(\d{3})+(?!\d))/g, ",")); //toLocaleString doesnt work across browsers, this regex does.
});
}
else {
$.getJSON( url, function() {})
.done(function(data) {
var connections = Math.round(data.response.connections).toString();
function getCurrentStats() {
var bwURL = "/internal/api/1.2/current_stats.json";
$.getJSON( bwURL, function() {})
.done(function(data) {
$.each( data.response.currentStats, function( i, item ) {
% foreach my $cdn_name (sort @{ $cdn_names } ) {
var cdn_name = "<%= $cdn_name %>";
if (item.cdn == cdn_name) {
var bandwidth = item.bandwidth.toFixed(2);
$('#' + cdn_name + '_gbps_val').text(bandwidth);
var connections = Math.round(item.connections).toString();
$('#' + cdn_name + '_conn_val').text(connections.replace(/\B(?=(\d{3})+(?!\d))/g, ",")); //toLocaleString doesnt work across browsers, this regex does.
var capacity = Math.round(item.capacity);
var percentage = Math.round(bandwidth/capacity * 100);
setProgress(cdn_name + "_percent_indicator", percentage);
setText(cdn_name + "_percent_indicator", "avail: " + capacity + ", used: " + percentage);
}
if (item.cdn == "total") {
var bandwidth = item.bandwidth.toFixed(2);
$('#total_gbps_val').text(item.bandwidth.toFixed(2));
var connections = Math.round(item.connections).toString();
$('#total_conn_val').text(connections.replace(/\B(?=(\d{3})+(?!\d))/g, ",")); //toLocaleString doesnt work across browsers, this regex does.
});
}
}
% }
});
});
}

//refresh every 30 seconds
setInterval('refreshStats()', 30000);
setInterval('getCurrentStats()', 30000);

</script>
<script type="text/javascript" src="/js/percentagebar.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion traffic_stats/grafana/traffic_ops_cachegroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ dashboard.title = which;
"targets": [
{
"rawQuery": true,
"query": "SELECT sum(value)*1000/6 FROM \"bandwidth\" WHERE cachegroup='" + which + "' and $timeFilter GROUP BY time(60s), hostname",
"query": "SELECT sum(value)*1000 FROM \"monthly\".\"bandwidth.1min\" WHERE cachegroup='" + which + "' and $timeFilter GROUP BY time(60s), hostname",
"alias": "$tag_hostname"
}
],
Expand Down
12 changes: 6 additions & 6 deletions traffic_stats/grafana/traffic_ops_deliveryservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ dashboard.title = which;
"targets": [
{
"measurement": "bw",
"query": "SELECT mean(value)*1000 FROM \"kbps\" WHERE deliveryservice='" + which + "' and cachegroup = 'total' and $timeFilter GROUP BY time(60s), deliveryservice ORDER BY asc",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"kbps.ds.1min\" WHERE deliveryservice='" + which + "' and cachegroup = 'total' and $timeFilter GROUP BY time(60s), deliveryservice ORDER BY asc",
"rawQuery": true,
"tags": {
"deliveryservice": which
Expand Down Expand Up @@ -198,24 +198,24 @@ dashboard.title = which;
"tags": {
"deliveryservice": which
},
"query": "SELECT mean(value) FROM \"tps_2xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc",
"query": "SELECT mean(value) FROM \"monthly\".\"tps_2xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc",
"hide": false,
"rawQuery": true
},
{
"target": "",
"rawQuery": true,
"query": "SELECT mean(value) FROM \"tps_3xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc"
"query": "SELECT mean(value) FROM \"monthly\".\"tps_3xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc"
},
{
"target": "",
"rawQuery": true,
"query": "SELECT mean(value) FROM \"tps_4xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc"
"query": "SELECT mean(value) FROM \"monthly\".\"tps_4xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc"
},
{
"target": "",
"rawQuery": true,
"query": "SELECT mean(value) FROM \"tps_5xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc"
"query": "SELECT mean(value) FROM \"monthly\".\"tps_5xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc"
}
],
"aliasColors": {},
Expand Down Expand Up @@ -273,7 +273,7 @@ dashboard.title = which;
"steppedLine": false,
"targets": [
{
"query": "SELECT sum(value)*1000/6 FROM \"kbps\" WHERE deliveryservice='" + which + "' and cachegroup != 'total' and $timeFilter GROUP BY time(60s), cachegroup",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"kbps.ds.1min\" WHERE deliveryservice='" + which + "' and cachegroup != 'total' and $timeFilter GROUP BY time(60s), cachegroup",
"rawQuery": true,
"alias": "$tag_cachegroup"
}
Expand Down
18 changes: 9 additions & 9 deletions traffic_stats/grafana/traffic_ops_scripted.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ if (type == "deliveryservice") {
"targets": [
{
"measurement": "bw",
"query": "SELECT mean(value)*1000 FROM \"kbps\" WHERE deliveryservice='" + which + "' and cachegroup = 'total' and $timeFilter GROUP BY time(60s), deliveryservice ORDER BY asc",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"kbps.ds.1min\" WHERE deliveryservice='" + which + "' and cachegroup = 'total' and $timeFilter GROUP BY time(60s), deliveryservice ORDER BY asc",
"rawQuery": true,
"tags": {
"deliveryservice": which
Expand Down Expand Up @@ -201,24 +201,24 @@ if (type == "deliveryservice") {
"tags": {
"deliveryservice": which
},
"query": "SELECT mean(value) FROM \"tps_2xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc",
"query": "SELECT mean(value) FROM \"monthly\".\"tps_2xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc",
"hide": false,
"rawQuery": true
},
{
"target": "",
"rawQuery": true,
"query": "SELECT mean(value) FROM \"tps_3xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc"
"query": "SELECT mean(value) FROM \"monthly\".\"tps_3xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc"
},
{
"target": "",
"rawQuery": true,
"query": "SELECT mean(value) FROM \"tps_4xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc"
"query": "SELECT mean(value) FROM \"monthly\".\"tps_4xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc"
},
{
"target": "",
"rawQuery": true,
"query": "SELECT mean(value) FROM \"tps_5xx\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time($interval) ORDER BY asc"
"query": "SELECT mean(value) FROM \"monthly\".\"tps_5xx.ds.1min\" WHERE $timeFilter AND deliveryservice='" + which + "' GROUP BY time(60s) ORDER BY asc"
}
],
"aliasColors": {},
Expand Down Expand Up @@ -276,7 +276,7 @@ if (type == "deliveryservice") {
"steppedLine": false,
"targets": [
{
"query": "SELECT sum(value)*1000/6 FROM \"kbps\" WHERE deliveryservice='" + which + "' and cachegroup != 'total' and $timeFilter GROUP BY time(60s), cachegroup",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"kbps.ds.1min\" WHERE deliveryservice='" + which + "' and cachegroup != 'total' and $timeFilter GROUP BY time(60s), cachegroup",
"rawQuery": true
}
],
Expand Down Expand Up @@ -359,7 +359,7 @@ else if ( type == "cachegroup" ) {
"targets": [
{
"rawQuery": true,
"query": "SELECT sum(value)*1000/6 FROM \"bandwidth\" WHERE cachegroup='" + which + "' and $timeFilter GROUP BY time(60s), hostname"
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"bandwidth.1min\" WHERE cachegroup='" + which + "' and $timeFilter GROUP BY time(60s), hostname"
}
],
"aliasColors": {},
Expand Down Expand Up @@ -434,7 +434,7 @@ else if ( type == "server" ) {
{
"measurement": "bandwidth",
"tags": {},
"query": "SELECT sum(value)*1000/6 FROM \"bandwidth\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"bandwidth.1min\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"rawQuery": true
}
],
Expand Down Expand Up @@ -506,7 +506,7 @@ else if ( type == "server" ) {
{
"measurement": "bandwidth",
"tags": {},
"query": "SELECT sum(value)*1000/6 FROM \"ats.proxy.process.http.current_client_connections\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"connections.1min\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"rawQuery": true
}
],
Expand Down
4 changes: 2 additions & 2 deletions traffic_stats/grafana/traffic_ops_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ dashboard.title = which;
{
"measurement": "bandwidth",
"tags": {},
"query": "SELECT sum(value)*1000/6 FROM \"bandwidth\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"bandwidth.1min\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"rawQuery": true
}
],
Expand Down Expand Up @@ -190,7 +190,7 @@ dashboard.title = which;
{
"measurement": "bandwidth",
"tags": {},
"query": "SELECT sum(value)*1000/6 FROM \"ats.proxy.process.http.current_client_connections\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"query": "SELECT mean(value)*1000 FROM \"monthly\".\"connections.1min\" WHERE hostname='" + which + "' and $timeFilter GROUP BY time(60s)",
"rawQuery": true
}
],
Expand Down

0 comments on commit af36270

Please sign in to comment.