Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for stacked area in timeline graphs #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 47 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FnordMetric
===========

FnordMetric is a highly configurable (and pretty fast) realtime app/event
tracking thing based on ruby eventmachine and redis. You define your own
FnordMetric is a highly configurable (and pretty fast) realtime app/event
tracking thing based on ruby eventmachine and redis. You define your own
plotting and counting functions as ruby blocks!

[ ![Build status - Travis-ci](https://secure.travis-ci.org/paulasmuth/fnordmetric.png) ](http://travis-ci.org/paulasmuth/fnordmetric)
Expand All @@ -17,7 +17,7 @@ FnordMetric keeps track of your data and draws nice timeline plots.

[ ![Nice timeline plots][5] ][6]

FnordMetric gives you a live dashboard, that shows who is using your app in
FnordMetric gives you a live dashboard, that shows who is using your app in
realtime. You can select a single user and follow them step by step.

[ ![Live dashboard][7] ][8]
Expand All @@ -26,10 +26,10 @@ realtime. You can select a single user and follow them step by step.
Getting Started
---------------

Copy `doc/full_example.rb` (that's the configuration from the screenshots
Copy `doc/full_example.rb` (that's the configuration from the screenshots
and screencast) or the simple example from below to `my_stats_app.rb`.

Simple Example: this will listen for json-events with `type=unicorn_seen`
Simple Example: this will listen for json-events with `type=unicorn_seen`
and render a timeline-plot showing the number of received events per hour.

```ruby
Expand All @@ -38,21 +38,21 @@ require "fnordmetric"
FnordMetric.namespace :myapp do

# numeric (delta) gauge, 1-hour tick
gauge :unicorns_seen_per_hour,
:tick => 1.hour.to_i,
gauge :unicorns_seen_per_hour,
:tick => 1.hour.to_i,
:title => "Unicorns seenper Hour"

# on every event like { _type: 'unicorn_seen' }
event(:unicorn_seen) do
# increment the unicorns_seen_per_hour gauge by 1
incr :unicorns_seen_per_hour
incr :unicorns_seen_per_hour
end

# draw a timeline showing the gauges value, auto-refresh every 2s
widget 'Overview', {
:title => "Unicorn-Sightings per Hour",
:type => :timeline,
:gauges => :unicorns_seen_per_hour,
:gauges => :unicorns_seen_per_hour,
:include_current => true,
:autoupdate => 2
}
Expand Down Expand Up @@ -94,9 +94,9 @@ The slow way: HTTP-Post the json event to the fnordmetric webinterface.

POST http://localhost:2323/events _type=unicorn_seen

curl -X POST -d "_type=unicorn_seen" http://localhost:4242/events
curl -X POST -d "_type=unicorn_seen" http://localhost:4242/events

The easy way: Stream one ore more newline-seperated json encoded events
The easy way: Stream one ore more newline-seperated json encoded events
through a tcp connection.

echo "\{\"_type\": \"unicorn_seen\"\}\n" | nc localhost 2323
Expand Down Expand Up @@ -146,32 +146,33 @@ api.event({:_type => "unicorn_seen"})

Call these methods from the event-handler block

incr(gauge_name, value=1):
Increment the given (two-dimensional) gauge by value
incr(gauge_name, value=1):
Increment the given (two-dimensional) gauge by value
at the tick specified by event-time

incr_field(gauge_name, field_name, value=1):
Increment the given field on a three-dimensional gauge
incr_field(gauge_name, field_name, value=1):
Increment the given field on a three-dimensional gauge
by value at the tick specified by event-time

set_value(gauge_name, value)
Set the given (two-dimensional) to value at the tick
Set the given (two-dimensional) to value at the tick
specified by event-time (overwrite existing value)

set_field(gauge_name, field_name, value)
Set the given field on a three-dimensional gauge to
value at the tick specified by event-time (overwrite
Set the given field on a three-dimensional gauge to
value at the tick specified by event-time (overwrite
existing value)

----

### Options: Widgets ###

+ `[autoupdate]` auto-refresh the timeline every n secs (0 turns autoupdate off)
+ `[plot_options]` Options passed in straight to Highchart

TimelineWidget

+ `[plot_style]` one of: line, areaspline
+ `[plot_style]` one of: line, areaspline, area, spline
+ `[include_current]` show the current tick?
+ `[ticks]` number of ticks to show (defaults to 24/30)

Expand Down Expand Up @@ -209,56 +210,56 @@ FnordMetric.namespace :myapp do

# Set a custom namespace title, if you want one
# set_title "Emails sent"

# Hide the "Active Users" tab, if you want
# hide_active_users

# numeric (delta) gauge, 1-hour tick
gauge :messages_sent,
:tick => 1.hour.to_i,
gauge :messages_sent,
:tick => 1.hour.to_i,
:title => "Messages (sent) per Hour"

# numeric (delta) gauge, 1-hour tick
gauge :messages_read,
:tick => 1.hour.to_i,
gauge :messages_read,
:tick => 1.hour.to_i,
:title => "Messages (read) per Hour"

# numeric (progressive) gauge, 1-hour tick
gauge :events_total,
:tick => 1.day.to_i,
gauge :events_total,
:tick => 1.day.to_i,
:progressive => true,
:title => "Events (total)"

# numeric (delta) gauge, increments uniquely by session_key
gauge :pageviews_daily_unique,
:tick => 1.day.to_i,
:unique => true,
gauge :pageviews_daily_unique,
:tick => 1.day.to_i,
:unique => true,
:title => "Unique Visits (Daily)"

# numeric (delta) gauge, increments uniquely by session_key, returns average
gauge :avg_age_per_session,
:tick => 1.day.to_i,
gauge :avg_age_per_session,
:tick => 1.day.to_i,
:unique => true,
:average => true,
:title => "Avg. User Age"

# three-dimensional (delta) gauge (time->key->value)
gauge :pageviews_per_url_daily,
:tick => 1.day.to_i,
:title => "Daily Pageviews per URL",
gauge :pageviews_per_url_daily,
:tick => 1.day.to_i,
:title => "Daily Pageviews per URL",
:three_dimensional => true


# on every event like { "_type": "message_sent" }
event(:message_sent) do
# increment the messages_sent gauge by 1
incr :messages_sent
incr :messages_sent
end

# on every event like { "_type": "message_read" }
event(:message_read) do
event(:message_read) do
# increment the messages_read gauge by 1
incr :messages_read
incr :messages_read
end

# on _every_ event
Expand All @@ -270,18 +271,18 @@ FnordMetric.namespace :myapp do
# on every event like
# { "_type": "_pageview", "_session": "sbz7jset", "url": "/page2" }
event :_pageview do
# increment the daily_uniques gauge by 1 if session_key hasn't been seen
# increment the daily_uniques gauge by 1 if session_key hasn't been seen
# in this tick yet
incr :pageviews_daily_unique
# increment the pageviews_per_url_daily gauge by 1 where key = 'page2'
incr_field :pageviews_per_url_daily, data[:url]
end

# on every event like { "_type": "_my_set_age", "my_age_field": "23" }
event(:my_set_age) do
# add the value of my_set_age to the avg_age_per_session gauge if session_key
event(:my_set_age) do
# add the value of my_set_age to the avg_age_per_session gauge if session_key
# hasn't been seen in this tick yet
incr :avg_age_per_session, data[:my_age_field]
incr :avg_age_per_session, data[:my_age_field]
end

# draw a timeline showing the pageviews_daily_unique, auto-refresh every 30s
Expand All @@ -294,8 +295,8 @@ FnordMetric.namespace :myapp do
:autoupdate => 30
}

# draw the values of the messages_sent and messages_read gauge at the current
# tick, three ticks ago, and the sum of the last 10 ticks, auto-refresh every
# draw the values of the messages_sent and messages_read gauge at the current
# tick, three ticks ago, and the sum of the last 10 ticks, auto-refresh every
# 20s
widget 'Overview', {
:title => "Messages Sent / Read",
Expand All @@ -306,7 +307,7 @@ FnordMetric.namespace :myapp do
:gauges => [ :messages_sent, :messages_read ]
}

# draw a list of the most visited urls (url, visits + percentage),
# draw a list of the most visited urls (url, visits + percentage),
# auto-refresh every 20s
widget 'Overview', {
:title => "Top Pages",
Expand Down Expand Up @@ -352,7 +353,7 @@ Contributors
+ Ross Kaffenberger (http://github.com/rossta)
+ Kunal Modi (http://github.com/kunalmodi)

To contribute, please fork this repository, make your changes and run the
To contribute, please fork this repository, make your changes and run the
specs, commit them to your github repository and send me a pull request.
Need help, head on over to our [Google Groups][1] page to discuss any ideas
that you might have.
Expand All @@ -365,7 +366,7 @@ Copyright (c) 2011 Paul Asmuth

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to use, copy and modify copies of the Software, subject
"Software"), to use, copy and modify copies of the Software, subject
to the following conditions:

The above copyright notice and this permission notice shall be
Expand Down
3 changes: 1 addition & 2 deletions haml/widget.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
!!!
!!!
%html

%head
%script(type="text/javascript" src="/fnordmetric/fnordmetric.js")

%body
[email protected]

3 changes: 2 additions & 1 deletion lib/fnordmetric/timeline_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def data
:autoupdate => (@opts[:autoupdate] || 60),
:include_current => !!@opts[:include_current],
:plot_style => (@opts[:plot_style] || 'line'),
:plot_options => (@opts[:plot_options]) || {},
:tick => tick
)
end
Expand All @@ -27,4 +28,4 @@ def has_tick?
true
end

end
end
12 changes: 6 additions & 6 deletions lib/fnordmetric/widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def add_gauges(gauges)
else
@gauges = gauges
end

if (ticks = gauges.map{ |g| g.tick }).uniq.length == 1
@tick = ticks.first
elsif !!self.try(:has_tick?)
Expand Down Expand Up @@ -62,12 +62,12 @@ def default_range(now=Time.now)
def include_current?
!(@opts[:include_current] == false)
end

def data
{
:title => @opts[:title],
{
:title => @opts[:title],
:width => @opts[:width] || 100,
:klass => self.class.name.split("::").last
:klass => self.class.name.split("::").last
}
end

Expand All @@ -79,4 +79,4 @@ def ensure_has_tick!
error! "widget does not have_tick" unless has_tick?
end

end
end
Loading