Skip to content

Instantly share code, notes, and snippets.

Server.prototype.checkThreshold = function(metric, template, data) {
var t = metric.threshold;
if (t) {
var last = this.lastValues[metric._id]
, v = parseFloat(data[template.primary]);
if (!isNaN(v))
this.lastValues[metric._id] = v;
if (last >= t && t > v)
We couldn’t find that file to show.
  1. Hi, I'm Visnu. I'm a co-founder of Fortnight Labs, a data consultancy. This is a product we've been working on mostly for ourselves and as a future platform.

  2. http://monitaur.net

    • monitaur is monitoring itself
    • this is real time
    • start focused with the server metrics vertical, but
    • we just added custom metrics (# people using the site)
  3. sign up as a new user

  • show threshold alert
@visnup
visnup / application.rb
Created January 28, 2011 17:48
leverage rails' built-in rescue stuff
# throw this bad boy at the end of your application.rb.
# rails will then treat these exceptions like it does
# ActiveRecord::RecordNotFound and others by showing you a nice backtrace
# on localhost and the static error pages in production.
ActionDispatch::ShowExceptions.rescue_responses.update({
'Mongoid::Errors::DocumentNotFound' => :not_found,
'BSON::InvalidObjectId' => :not_found,
'SecurityError' => :unauthorized
require "rubygems"
require "spec/spec_helper"
class Coffee
include Mongoid::Document
field :beany
references_many :beans #, :validate => false works
end
@visnup
visnup / mongoid_hacks.rb
Created January 29, 2011 01:35
be passive aggressive about mongoid relation validations
class Mongoid::Relations::Metadata
# @return [ true, false ] False unless explictly set to true.
def validate?
self[:validate]
end
end
require 'rubygems'
require 'spec/spec_helper'
class Coffee
include Mongoid::Document
references_and_referenced_in_many :beans #, :inverse_of => nil
end
class Bean
include Mongoid::Document
@visnup
visnup / Screen shot 2011-02-07 at 4.37.04 PM.png
Created February 8, 2011 00:37
# trippy mongodb colorized logging by statement type
Screen shot 2011-02-07 at 4.37.04 PM.png
require 'rubygems'
require 'benchmark'
require './spec/spec_helper'
p = Person.create
Benchmark.bm do |x|
x.report("new") { 10_000.times do Person.new end }
x.report("reload") { 10_000.times do p.reload end }
x.report("find") { 10_000.times do Person.find(p.id) end }
require "spec_helper"
class ValInheritanceParent
include Mongoid::Document
field :parent_value
embeds_many :val_inheritance_embed
references_many :val_inheritance_ref