Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #1540 from CPAN-API/leo/fastly_stats
Create a /about/stats page that queries Fastly for our stats
- Loading branch information
Showing
9 changed files
with
276 additions
and
6 deletions.
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,80 @@ | ||
<% | ||
title = "MetaCPAN Network stats"; | ||
|
||
# tell wrapper to load js/css required | ||
stats_page = 1; | ||
|
||
USE Comma; | ||
%> | ||
<% PROCESS inc/about-bar.html %> | ||
|
||
<div class="content about epoch-theme-light"> | ||
|
||
<script> | ||
var monthNames = [ | ||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", | ||
"Aug", "Sep", "Oct", "Nov", "Dec" | ||
]; | ||
</script> | ||
|
||
<h2>Networks stats for the last 30 days</h2> | ||
|
||
<% UNLESS fastly_stats.keys %> | ||
This must be run on a box that has access to | ||
the fastly_api_key, production usually | ||
<% END %> | ||
|
||
<% | ||
# Define styles to use | ||
css_category_lookup = { | ||
requests => 'category10', | ||
bandwidth => 'category20b', | ||
hit_ratio => 'category20c', | ||
}; | ||
|
||
# Now loop the sites we have stats on | ||
FOREACH site IN fastly_stats.keys.sort; | ||
|
||
# Data for this site | ||
site_data = fastly_stats.$site; | ||
|
||
# A key for the div/data | ||
sitekey = site.replace(/\./,'_'); | ||
%> | ||
<h2><em><% site %></em></h2> | ||
|
||
<% FOREACH type IN [ 'requests', 'bandwidth' ] %> | ||
|
||
<h4><% type | ucfirst %>: <% site_data.totals.$type | comma %></h4> | ||
|
||
<div class="epoch <% css_category_lookup.$type %>" id="chart-<% sitekey %>-<% type %>" style="width: 100%; height: 200px"></div> | ||
|
||
<script> | ||
var chartData<% sitekey %><% type %> = [ | ||
{ | ||
label: "<% type %>", | ||
values: [ | ||
<% FOREACH data_point = site_data.$type %> | ||
{x: <% data_point.time %>, y: <% data_point.y %>}<%- ',' UNLESS loop.last -%> | ||
<% END %> | ||
] | ||
}<% ', ' UNLESS loop.last %> | ||
]; | ||
$('#chart-<% sitekey %>-<% type %>').epoch({ | ||
type: 'area', | ||
data: chartData<% sitekey %><% type %>, | ||
margins: { right: 10 }, | ||
ticks: { bottom: 5 }, | ||
tickFormats: { bottom: function(d) { | ||
var dt = new Date(0); // The 0 there is the key, which sets the date to the epoch | ||
dt.setUTCSeconds(d); | ||
return monthNames[dt.getMonth()] + ' ' + dt.getDate(); | ||
}} | ||
}); | ||
</script> | ||
<% END %> | ||
|
||
<% END %> | ||
|
||
</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
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.