Add bucky (client side metrics client).

This commit is contained in:
Arik Fraimovich 2014-05-07 17:25:43 +03:00
parent 37512b5fdd
commit 28224a0ba1
6 changed files with 37 additions and 1 deletions

View File

@ -114,6 +114,7 @@
<script src="/scripts/ng_highchart.js"></script>
<script src="/scripts/ng_smart_table.js"></script>
<script src="/scripts/ui-bootstrap-tpls-0.5.0.min.js"></script>
<script src="/bower_components/bucky/bucky.js"></script>
<!-- endbuild -->
<!-- build:js({.tmp,app}) /scripts/scripts.js -->
@ -139,6 +140,8 @@
<!-- endbuild -->
<script>
// TODO: move currentUser & features to be an Angular service
var featureFlags = {{ features|safe }};
var currentUser = {{ user|safe }};
currentUser.canEdit = function(object) {

View File

@ -17,6 +17,14 @@ angular.module('redash', [
'ngRoute'
]).config(['$routeProvider', '$locationProvider', '$compileProvider', 'growlProvider',
function ($routeProvider, $locationProvider, $compileProvider, growlProvider) {
if (featureFlags.clientSideMetrics) {
Bucky.setOptions({
host: '/api/metrics'
});
Bucky.requests.monitor('ajax_requsts');
Bucky.requests.transforms.enable('dashboards', /dashboard\/[\w-]+/ig, '/dashboard');
}
function getQuery(Query, $route) {
var query = Query.get({'id': $route.current.params.queryId });

View File

@ -111,6 +111,13 @@
}
var MainCtrl = function ($scope, Dashboard, notifications) {
if (featureFlags.clientSideMetrics) {
$scope.$on('$locationChangeSuccess', function(event, newLocation, oldLocation) {
// This will be called once per actual page load.
Bucky.sendPagePerformance();
});
}
$scope.dashboards = [];
$scope.reloadDashboards = function () {

View File

@ -22,7 +22,8 @@
"mousetrap": "~1.4.6",
"angular-ui-select2": "~0.0.5",
"underscore.string": "~2.3.3",
"marked": "~0.3.2"
"marked": "~0.3.2",
"bucky": "~0.2.6"
},
"devDependencies": {
"angular-mocks": "~1.0.7",

View File

@ -51,7 +51,12 @@ def index(**kwargs):
'permissions': current_user.permissions
}
features = {
'clientSideMetrics': settings.CLIENT_SIDE_METRICS
}
return render_template("index.html", user=json.dumps(user), name=settings.NAME,
features=json.dumps(features),
analytics=settings.ANALYTICS)
@ -145,6 +150,17 @@ class EventAPI(BaseResource):
api.add_resource(EventAPI, '/api/events', endpoint='events')
class MetricsAPI(BaseResource):
def post(self):
for stat_line in request.data.split():
stat, value = stat_line.split(':')
statsd_client._send_stat('client.{}'.format(stat), value, 1)
return "OK."
api.add_resource(MetricsAPI, '/api/metrics/v1/send', endpoint='metrics')
class DataSourceListAPI(BaseResource):
def get(self):
data_sources = [ds.to_dict() for ds in models.DataSource.select()]

View File

@ -68,4 +68,5 @@ COOKIE_SECRET = os.environ.get("REDASH_COOKIE_SECRET", "c292a0a3aa32397cdb050e23
LOG_LEVEL = os.environ.get("REDASH_LOG_LEVEL", "INFO")
EVENTS_LOG_PATH = os.environ.get("REDASH_EVENTS_LOG_PATH", "")
EVENTS_CONSOLE_OUTPUT = parse_boolean(os.environ.get("REDASH_EVENTS_CONSOLE_OUTPUT", "false"))
CLIENT_SIDE_METRICS = parse_boolean(os.environ.get("REDASH_CLIENT_SIDE_METRICS", "false"))
ANALYTICS = os.environ.get("REDASH_ANALYTICS", "")