Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Preparing for npm registration

  • Loading branch information...
commit a66727c5fad16e9496f7347f114c2109dce42f3e 1 parent d57af35
Mark Cahill authored
View
108 castor.js
@@ -0,0 +1,108 @@
+/**
+ * Castor - a cross site POSTing JavaScript logging library for Loggly
+ *
+ * Copyright (c) 2011 Loggly, Inc.
+ * All rights reserved.
+ *
+ * Author: Kord Campbell <kord@loggly.com>
+ * Date: May 2, 2011
+ *
+ * Uses methods from janky.post, copyright(c) 2011 Thomas Rampelberg <thomas@saunter.org>
+ *
+ * Sample usage (replace with your own Loggly HTTP input URL):
+
+ <script src="/js/loggly.js" type="text/javascript"></script>
+ <script type="text/javascript">
+ window.onload=function(){
+ castor = new loggly({ url: 'http://logs.loggly.com/inputs/a4e839e9-4227-49aa-9d28-e18e5ba5a818?rt=1', level: 'WARN'});
+ castor.log(object);
+ }
+ </script>
+
+ */
+
+(function() {
+ this.loggly = function(opts) {
+ this.user_agent = get_agent();
+ this.browser_size = get_size();
+ log_methods = {'error': 5, 'warn': 4, 'info': 3, 'debug': 2, 'log': 1};
+ if (!opts.url) throw new Error("Please include a Loggly HTTP URL.");
+ if (!opts.level) {
+ this.level = log_methods['info'];
+ } else {
+ this.level = log_methods[opts.level];
+ }
+ this.log = function(data) {
+ if (log_methods['log'] == this.level) {
+ opts.data = data;
+ janky(opts);
+ }
+ };
+ this.debug = function(data) {
+ if (log_methods['debug'] >= this.level) {
+ opts.data = data;
+ janky(opts);
+ }
+ };
+ this.info = function(data) {
+ if (log_methods['info'] >= this.level) {
+ opts.data = data;
+ janky(opts);
+ }
+ };
+ this.warn = function(data) {
+ if (log_methods['warn'] >= this.level) {
+ opts.data = data;
+ janky(opts);
+ }
+ };
+ this.error = function(data) {
+ if (log_methods['error'] >= this.level) {
+ opts.data = data;
+ janky(opts);
+ }
+ };
+ };
+ this.janky = function(opts) {
+ janky._form(function(iframe, form) {
+ form.setAttribute("action", opts.url);
+ form.setAttribute("method", "post");
+ janky._input(iframe, form, opts.data);
+ form.submit();
+ setTimeout(function(){
+ document.body.removeChild(iframe);
+ }, 2000);
+ });
+ };
+ this.janky._form = function(cb) {
+ var iframe = document.createElement("iframe");
+ document.body.appendChild(iframe);
+ iframe.style.display = "none";
+ setTimeout(function() {
+ var form = iframe.contentWindow.document.createElement("form");
+ iframe.contentWindow.document.body.appendChild(form);
+ cb(iframe, form);
+ }, 0);
+ };
+ this.janky._input = function(iframe, form, data) {
+ var inp = iframe.contentWindow.document.createElement("input");
+ inp.setAttribute("type", "hidden");
+ inp.setAttribute("name", "source");
+ inp.value = data;
+ form.appendChild(inp);
+ };
+ this.get_agent = function () {
+ return navigator.appCodeName + navigator.appName + navigator.appVersion;
+ };
+ this.get_size = function () {
+ var width = 0; var height = 0;
+ if( typeof( window.innerWidth ) == 'number' ) {
+ width = window.innerWidth; height = window.innerHeight;
+ } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
+ width = document.documentElement.clientWidth; height = document.documentElement.clientHeight;
+ } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
+ width = document.body.clientWidth; height = document.body.clientHeight;
+ }
+ return {'height': height, 'width': width};
+ };
+})();
View
1  listeners/couchdb.js
@@ -16,7 +16,6 @@ exports = module.exports = function(config) {
* Required method
*/
this.post = function(data) {
- console.log("DATA:", data);
this.db.insert(data, function(error, http_body, http_headers) {
if (error)
console.error(error);
View
17 package.json
@@ -0,0 +1,17 @@
+{
+ "name": "telemetry",
+ "description": "a simple telemetry server written in Node.js",
+ "version": "0.0.1",
+ "author": "Mark Cahill <mark+npm@thinkjson.com>",
+ "keywords": [ "Loggly", "log", "telemetry", "firebug", "firephp" ],
+ "repository": {
+ "type": "git",
+ "url": "https://thinkjson@github.com/thinkjson/node-telemetry.git"
+ },
+ "dependencies": {
+ "express": ">= 2.8.0",
+ "yaml": ">= 0.2.2",
+ "nano": ">= 0.8.5"
+ },
+ "bin": "./telemetry"
+}
View
25 readme.md
@@ -1,7 +1,6 @@
-The goal of node-telemtry is to make it really easy to deploy a scalable telemetry
+The goal of node-telemetry is to make it really easy to deploy a scalable telemetry
server for small projects. This can be used to capture errors, performance data,
-and more, and store it in a document store. Arbitrary inputs are supported by some
-backends, and of course any parameters may be attached to each document.
+and more, and store it in a document store or on the filesystem.
To install telemetry, run
@@ -11,4 +10,22 @@ then edit your config.yaml, and run telemetry:
telemetry
-For more information, visit [the wiki](https://github.com/thinkjson/node-telemetry/wiki).
+An example config.yaml is provided below:
+
+ errors:
+ -
+ type: couchdb
+ host: user.cloudant.com
+ username: user
+ password: password
+
+You may place this in the same directory as telemetry, or pass it via the
+TELEMETRY_CONFIG environment variables like so:
+
+ export TELEMETRY_CONFIG=~/.telemetry; telemetry
+
+If you are interested in creating additional backends for telemetry, or need
+general assistance, contact me using the e-mail address displayed when you do
+
+ npm author ls telemetry
+
View
6 server.js
@@ -2,7 +2,6 @@
var express = require('express');
var yaml = require('yaml');
var fs = require('fs');
-global._ = require('underscore')._;
// Load listeners
var listener_files = fs.readdirSync(__dirname + "/listeners");
@@ -13,7 +12,8 @@ for (var i = 0; i < listener_files.length; i++) {
}
// Load configuration and inputs
-var config = yaml.eval(fs.readFileSync(__dirname + "/config.yaml", 'utf8')); //FIXME - this is just for testing. the real file should be in home dir
+var config_loc = process.env.TELEMETRY_CONFIG || __dirname + "/config.yaml";
+var config = yaml.eval(fs.readFileSync(config_loc, 'utf8')); //FIXME - this is just for testing. the real file should be in home dir
global.telemetry = new (require(__dirname + '/telemetry'))(config);
// Create the telemetry server and assign inputs
@@ -28,7 +28,7 @@ app.post('/input/:input', function(req, res, next) {
}
// Send success
- var data = JSON.parse(req.body.source.replace('castor ', ''));
+ var data = JSON.parse(req.body.source);
for (var i = 0; i < telemetry.inputs[input].length; i++) {
telemetry.inputs[input][i].post(data);
}
View
3  telemetry
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require("./telemetry.js");
Please sign in to comment.
Something went wrong with that request. Please try again.