<commit_before>var Graphite = require('graphite');
var Measured = require('measured');
var blocked = require('blocked');

var reportInterval = 5000;
var graphiteHost = process.env.GRAPHITE_HOST || null;
var graphitePort = process.env.GRAPHITE_PORT || 2003;
var envName = process.env.NODE_ENV || "unknown";
var processIdentifier = process.env.DYNO ? 'dyno-' + process.env.DYNO.replace('.', '') : 'pid-' + process.pid;

var timer = null;
var graphite = null;
var data = Measured.createCollection('origami.polyfill.' + envName + '.' + processIdentifier);

var failures = data.counter('graphiteReportingFailures');

if (graphiteHost) {
	graphite = Graphite.createClient('plaintext://'+graphiteHost+':'+graphitePort);
	timer = setInterval(function() {
		graphite.write(data.toJSON(), function(err) {
			if (err) {

				// Ignore timeouts
				if (err.code === 'ETIMEDOUT' || err.code === 'EPIPE') {
					failures.inc();
					return;
				}

				console.error(err, err.stack);
				console.warn('Disabling graphite reporting due to error');
				clearInterval(timer);
			}
		});
	}, reportInterval);
	timer.unref();
} else {
	console.warn('Graphite reporting is disabled.  To enable, set GRAPHITE_HOST');
}

data.gauge('memory', function() {
	return process.memoryUsage().rss;
});

blocked(function(ms) {
	if (ms < 100) return;
	console.warn('Event loop blocked for '+ms+'ms');
	data.counter('eventloopdelay').inc(ms);
});


module.exports = data;<commit_msg>Only measure metrics if we are going to report them<commit_after>var Graphite = require('graphite');
var Measured = require('measured');
var blocked = require('blocked');

var reportInterval = 5000;
var graphiteHost = process.env.GRAPHITE_HOST || null;
var graphitePort = process.env.GRAPHITE_PORT || 2003;
var envName = process.env.NODE_ENV || "unknown";
var processIdentifier = process.env.DYNO ? 'dyno-' + process.env.DYNO.replace('.', '') : 'pid-' + process.pid;

var timer = null;
var graphite = null;
var data = Measured.createCollection('origami.polyfill.' + envName + '.' + processIdentifier);

var failures = data.counter('graphiteReportingFailures');

if (graphiteHost) {

	data.gauge('memory', function() {
		return process.memoryUsage().rss;
	});

	blocked(function(ms) {
		if (ms < 100) return;
		console.warn('Event loop blocked for '+ms+'ms');
		data.counter('eventloopdelay').inc(ms);
	});

	graphite = Graphite.createClient('plaintext://'+graphiteHost+':'+graphitePort);
	timer = setInterval(function() {
		graphite.write(data.toJSON(), function(err) {
			if (err) {

				// Ignore timeouts
				if (err.code === 'ETIMEDOUT' || err.code === 'EPIPE') {
					failures.inc();
					return;
				}

				console.error(err, err.stack);
				console.warn('Disabling graphite reporting due to error');
				clearInterval(timer);
			}
		});
	}, reportInterval);
	timer.unref();
} else {
	console.warn('Graphite reporting is disabled.  To enable, set GRAPHITE_HOST');
}


module.exports = data;
{'fraction_non_alphanumeric': 0.16502546689303904, 'fraction_numerical': 0.007470288624787776, 'mean_word_length': 4.568998109640832, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '612635', 'n_tokens_mistral': 1069, 'n_tokens_neox': 934, 'n_words': 210}