开发者

How does New Relic work?

How can New Relic tap into my app with a simple install? How does it know all the methods, requests, etc?

It works for RoR, PHP, etc.

Can anyone ex开发者_如何学编程plain the technology behind it? I'm interested in tapping into my Rails app, but I want to do so smoothly like New Relic.

Thanks


First up, you will not manage to duplicate the functionality of NewRelic on your own. Ignoring the server-side, the rpm Gem is a pretty complex piece of software, doing a lot of stuff. Have a look at the source if you want to see how it hooks into the Rails system. The source is a worth a read, as it does some cool stuff in terms of threading and marshaling of the data before sending it back to their servers.

If you want a replacement because Newrelic is expensive (and rightly so, it's awesome at what it does), then have a look at the FreeRelic project on Github.


They are using ASPECT ORIENTED PROGRAMMING CONCEPTS AND Reflection heavily for Intercepting original method call and adding instrumentation around that.


In a general way, New Relic's gem inserts kinda middleware in your web framework, and collects data from your endpoint (think as a rails route) until it's response. After every "harvesting time" (defaults to 60 seconds), it sends a post request to NR services with this data. You can also tailor data you need with Custom Metrics, Custom Events. Is also possible to do queries with NRQL and build graphs with that (like you would do in Graphana). They have a customize service for Wordpress too, but is a bit messy in the start. Some options if you want to save some money is configure cloudwatch + datadog, but I would give a shot to their service if uptime is crucial for your app.


For a rails solution you could simply implement a more verbose logging level (development/debug level) and interrogate the production.log file for specific events, timings etc


For Java they are attaching a Java agent to JVM which intercepts method calls and monitor them. You can use AspectJ to replicate the same behaviour and log every method call to wherever you want, let's say create custom Cloudwatch metrics.


In case of Java it's bytecode ingestion. They "hacking" the key methods of your application server and add their code in it. Then they send relevant transaction info to their server, aggregating it and you can see the summary. It's really complicated process so I don't think one dev can implement it.


  • If you’re already familiar with New Relic’s application monitoring then you probably know about New Relic’s agents that run in-process on web apps collecting and reporting all sorts of details about whats happening in the app. RUM leverages the agents to dynamically inject JavaScript into pages as they are built. The injected JavaScript collects timing information in the browser and contains details that identify the specific app and web transaction processed on the backend as well as how time was spent in the app for each request. When a page completes loading in an end user’s browser, the information is sent back to New Relic asynchronously – so it doesn’t effect page load time.

    You can turn RUM on/off via your application settings in New Relic. As well, you can turn RUM on/off via the agent’s configuration file (newrelic.yml – a ‘browser_monitoring auto_instrument’ flag has been introduced).

    The agents have been enhanced to automatically inject JavaScript into the HTML pages so using RUM is as simple as checking the checkbox on the New Relic control panel. However, if you’d prefer more control, you can use New Relic’s Agent API to generate the JavaScript and thus control exactly when and where the header and footer scripts are included.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜