 Yep, cool radio my cloaking just waiting on a clicker, which will eventually get but first a public service announcement I And and M ops guy which means I look like this guy and I live in a server room But that is not something to be feared Now the other opinion of ops people it's this guy mr. Grumpy Well now why ops people Considered to be grumpy. Well The truth is we care a lot about your code and we want to make it run. Well and The best way to make your code run Well is to constantly talk with you guys and be in communication now We have a bit of a bad reputation in that we're considered Untouchable and just unapproachable There is a good solution to this and it is beer Ops people like beer we can be very easily bribed with beer and if you think that we Unapproachable unfriendly just come up and say hey need your advice Here's a beer. Let's just have a chat So on to the talk active support notifications and live status pages Cool, I'll switch back to the pulpit. Okay cool So to begin with let me tell you a story You're gonna like my slides it is a Monday morning and you're in the office early You decided yep, I'll just get in there start the week off well Get through all of your emails and you managed to do so You're on top of everything and It's awesome Sadly though things are about to conspire against you Because of this guy The boss is there and he just comes up to your desk and goes well I was showing this site to our investors and It seems that it was running a bit slow So I'm going to need you to stay back late all this week and Get it fixed This is how you respond Pretty much no information as to what he was trying to do and no leads whatsoever So how do you get this problem solved? You can start off by looking at things like New Relic skylight numerous Other things that will actually give you some insight, but you think yeah, there must be a better way to get this solved now Starting off we need to take a step back from all of the technology and look at how we're going to actually Get the data out that we need and what we need to do as far as an approach so Hands up if this is your response to doing any kind of data query Don't be shy. It's like you just love doing this stuff. I've got one guy down the front who does that's awesome For those that don't get the reference this is data and he's doing a search for life forms It is awesome So how do you actually search for good data? You need to ask good questions and what makes a good question it is something that is simple measurable achievable realistic and Timely I've completely plagiarized this from something in a different context, but it still applies The questions that you need to ask have to actually result in you getting The right data out. Otherwise, it is just completely useless Now when you start off you'll often get many situations whereby you just want to do this Just go screw it. We're starting over That's it So active support notifications now as With anything there are sort of two sides to it. The first is Instrumenters and the second is subscribers. So let's have a look at instrumenters Now in rails you've already got a lot of stuff which is instrumented for you by default You've got a notification of when a controller starts processing something When it processes an action of renders a partial it does some stuff with SQL and There's a lot more as well Now from this you should get a good idea of what is already Possible with notifications and how best to use them now If you want to know the full list the rails API docs have them the Rails guides as well give a really good introduction into how to use this stuff But you can also do this really cool thing of custom instrumentation So if you wrap your code in something like this you are able to see and Instrument what that particular bit of code is doing Now this is fairly powerful in that you've got a hash there Which is your search and params that gets Passed through to your subscriber and you can pass anything through to that Now this though comes with a big fat warning Because they'd be dragons You can do a lot of stuff with Notifications and some people think that it's a very simple way of doing a publish subscribe Notification system in that they will put a custom Instrumentation call around a bit of code and then try and Use that to say update the state of a model or something rather weird like that This isn't the best thing to do with instrumentation because it's designed to be gathering Statistics about what's going on? So let's have a look at subscribers This year is a subscriber You put this in an initializer and it will listen in this case for anything For the notification that gets sent when there is an active record SQL call It'll be past the name you get a start and finish time you get a unique ID and you get a payload and within that you Can do some rather awesome ruby stuff So that's a basic overview. Let's have a look at what it looks like in practice So by practice, I mean the other part of the talk title, which is doing a live status page First thing you need is you need your notifications You also need a time series database Because what we're doing is tracking metrics over time Having something like a time series database in there is pretty good a graphing library because everyone likes pretty graphs Action controller live is really useful because you don't want to be constantly polling your server for new data you want to be told has it updates and Having it all wrapped in a nice rails engine is also pretty good so Something like this is what will fit in your initializer. You've got a stack of Notification subscriptions all doing the one thing now what you can also do is Rejects matching so something like this will listen for anything that matches that particular Rejects now, this is pretty powerful if you want to make sure that your code isn't copied and pasted multiple times. It's just a great way of Doing using the dry principle pretty awesome The time series database now what are some examples of a time series database? Got graphite and carbon and which is developed by Etsy. That's pretty good Written in Python, but we won't hold it against them And it's a reasonable time series database helps people tend to use it fairly regularly for a lot of their metrics Got something like influx DB which I tend to like again the time series database, but has some SQL like Functionality to it which really helps for querying tempo DB Can use Redis, but you end up with the problem of it just being a never-growing Redis store You can also just use a Postgres which is pretty awesome because it's pretty powerful But it's a lot heavier than what you would really want You must choose the right DB When doing anything with data with statistics You need to not only think about what the data is going in But how it is that you will use it so if say you're sticking Jason objects everywhere It becomes fairly difficult to do things like averages max min and stuff like that which a Straight value store Will will allow you for so make sure you're going to be asking the right questions Think about how you will use the data Don't only go this is how I'm immediately going to use the data But rather think this is how I want to use the data down the track Reason I say that is over a couple of months You'll get a large amount of data and you then go well, okay, let's try and do some funky stuff with How this data is used if you're storing it in the wrong place if you're storing the wrong things then That data is pretty much worthless for you and you'll need to start again There is no one-size-fits-all You need to think seriously about how it is you're going to approach the problem In my particular case, I chose in flux DB It is a simple approach. There's a really good Ruby Ruby gem, and you've even got a rails gem which handles some notification type stuff as well It's got a query language. So you can do things like count average men max median mode whatever you want and Storing it is as simple as this You create a data hash which has a value and a time and you then just write it to your data database Retrieving the data is where it becomes really cool because you can use select queries So get all of the values between a particular time. You can limit it to some results as well You can do counts over time You can do a range of really awesome things graphing library This is all JavaScript and front-end stuff. I do quite often badmouth JavaScript, but it has its uses in this case, there's is really amazing library called D3 and There's also another library called rickshaw which sits on top of D3 and makes The calls to D3 a lot easier. So it's a convenience wrapper This is what it looks like to create a graph Just say new graph you provide it with the DOM element You set up the series so you can do multiple series in the one graph and then you call render This is a very Cut down and reduced Bit of code, but it gives the idea of how simple it is Action control alive. So First heard about this from Aaron a couple of years ago, and it is really amazing. So thank you, Aaron It is a way of doing server sent events whereby The server will send data through to your browser whenever it has updated information or Whatever you tell it to and There's no need for polling. So you don't constantly have the browser page refreshing itself or an Ajax call or something going off Rails engines so Everyone likes being able to sort of put their code into a nice convenient package and Rails engines allows this so for the in the example of a live status page Using a rails engine makes a lot of sense. You take your code and you put it as a self-contained unit and that is really good. So it allows for Reusability What you write for one app can then be taken and used again and again and again if it's all done, right? easy integration in that you just provide it as a gem and If you want to change the default mount point you can do that It's a single responsibility thing. So the gem Which is a rails engine has a single responsibility which is providing your live status page so what it looks like It's all up on github but It's got a semantic version of zero point zero point one Which means have a good look at it to see how it's done But don't expect Too much from it because I'm still working on it Yeah, not quite I'm Matt Dells That's made pretty much everywhere on the internet. I work for a group called re-interactive and Any questions? Well, if not, thank you