Skip to content

thatisscary/Graphene

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Graphene

A highly saleable BI framwork writing in C#. Graphene can be used to track various Metrics. Graphene pre-aggregates the data and uses a document store (like MongoDB/RavenDB) to store the pre-aggregated data. Graphene also supports adding filters to a Metrics.

Getting Started

Initializing Graphene

Add the line below to your applications initialization event (e.g. ASP.Net: Application_Start event, Windows Service: OnStart)

Graphene.Configurator.Initialize(
                    new Configuration.Settings() { Persister = new Publishing.PersistToMongo("mongodb://localhost/Graphene") }
                );

Creating a Tracker

A tracker is something of business value that needs to be tracked over time. Examples are number of order placed on a commerce site, the performance in MS of a given API etc. during a given time interval.

To create a tracker implement Graphene.Tracking.ITrackable Interface

public class CustomerVisitTracker : ITrackable
{
	public string Name { get { return "Customer Visit Tracker"; } }

	public string Description { get { return "Counts the number of customer visits"; } }

	public Resolution MinResolution { get { return Resolution.Hour; } }

	public long KidsCount { get; set; }
    public long MiddleAgedCount { get; set; }
    public long ElderlyCount { get; set; }
}

The MinResolution set the minimum time interval that can be tracked. If the interval is set to Hour then one can generate reports of that metrics per hour and above (day/month etc.) but not below that.

The higher the resolution the better Graphene can pre-compute the data and better the queries will perform.

Incrementing a Tracker

Default Metrics

The line below increments the default tracker metric by 1

Tracking.Container<CustomerVisitTracker>.IncrementBy(1);

Named Metrics

The line below increments the named metric "MiddleAgedCount" by 1 and "ElderlyCount" by 2.

Tracking.Container<CustomerAgeTracker>
                        .Where<CustomerFilter>(
                            new CustomerFilter
                            {
                                State = "MN",
                                StoreID = "334",
                                Environment_ServerName = "Server2"
                            })
                        .Increment(e => e.MiddleAgedCount, 1)
                        .Increment(e => e.ElderlyCount, 2);

Adding filters

Filters can be added to allow the tracker data to be sliced and diced. For example number of orders placed from a given state or API performance on a given server.

First step to adding a filter is to define it as a struct.

public struct CustomerFilter
{
	public string State { get; set; }
	public string StoreID { get; set; }
	public string Gender { get; set; }
	public string Environment_ServerName { get; set; }
}

All properties must be string or a nullable type. For Graphene's pre-computation to be optimal the cardinality of the filter values should be low, i.e. the all combination of the filter values should be on the lower side for best performance.

To apply a filter while incrementing a tracker follow the following sample.

Graphene.Tracking.Container<CustomerVisitTracker>
	.Where<CustomerFilter>(
		new CustomerFilter
		{
			State = "CA",
			StoreID = "3234",
			Environment_ServerName = "Server1"
		}).IncrementBy(1);

Shutting down Graphene

Add the line below to your applications shut down event (e.g. ASP.Net: Application_End event, Windows Service: OnStop)

Graphene.Configurator.ShutDown();

Generating Reports

This functionality is yet built. Generating reports would requiring querying the underlying Graphene data store directly.

Below is how the generated data looks like when using MongoDB as the data store.

{
  "KeyFilter" : "ENVIRONMENT_SERVERNAME::SERVER2,STATE::MN,STOREID::334",
  "Measurement" : {
    "ElderlyCount" : NumberLong(76994),
    "MiddleAgedCount" : NumberLong(38497),
    "_Occurrence" : NumberLong(76994),
    "_Total" : NumberLong(0)
  },
  "Name" : "Customer Age Tracker",
  "SearchFilters" : ["STATE::MN,,STOREID::334", "ENVIRONMENT_SERVERNAME::SERVER2,,STOREID::334", "ENVIRONMENT_SERVERNAME::SERVER2,,STATE::MN", "STOREID::334", "ENVIRONMENT_SERVERNAME::SERVER2", "STATE::MN"],
  "TimeSlot" : ISODate("2014-01-21T02:00:00Z"),
  "TypeName" : "Graphene.Tests.CustomerAgeTracker",
  "_id" : "Graphene.Tests.CustomerAgeTracker1/21/20142:00:00AMENVIRONMENT_SERVERNAME::SERVER2,STATE::MN,STOREID::334"
}

So the above can be read as: The "Customer Age Tracker" was incremented Measurement.Occurrence times and the total sum Measurement.MiddleAgedCount for the TimeSlot of 2014-01-21, 02:00:00. There will be a document for every TimeSlot and if the MinResolution is 1 hour the next TimeSlot would be 2014-01-13, 04:00. Also there will be a document for every unique combination of the filters. Measurement.SearchFilters are the tags to for every possible combination of the filters delimited by ",,". To find all customer visits for the state of MN and store ID of 334 add the following to the query

{ SearchFilters: { $in: ['STATE::MN,,STOREID::334' ] } } 

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.8%
  • Classic ASP 0.2%