0

Monitoring with New Relic

asked 2012-10-24 20:40:02 +0800

mrojas gravatar image mrojas
17 2

Hello.

I have an application built on ZK 5 and I'm trying to implement the Real User Monitor funcionality in New Relic to monitor application usage and performance. The user interface is implemented with Java clases instead of zul files so I'm looking for the best way to implement this. In the New Relic site there are samples for JSPs, Servlets, ColdFusion, Velocity ... nut they have nothing currently implemented for ZK. They say that for RUM a pair of JavaScripts should be included in the header and footer sections in some specific places, but I've not found a way to do this in for example a Window object. So if there is anybody who could give me some pointers or can share some tips, it would be greatly appreciated.

Best regards.

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2012-10-25 02:52:26 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi mrojas,

All of javascript of ZK are put in head, unless you use script component, if you you shall include a external javascript file,do not write the javascript in your zul file

link publish delete flag offensive edit

answered 2012-10-25 13:42:22 +0800

mrojas gravatar image mrojas
17 2

Thanks Jimmy.

We're not using ZUL files, all our using interface is built programmatically from Java classes, the only ZUL file is the index.zul that acts as the entry point. I tried to put the NewRelic code in that index.zul, but it didn't work as New Relic says that :

Insert the header Javascript at the beginning of the <head> tag, but after the <meta> tags. Insert the footer Javascript before the </body> tag. The footer includes timing metrics so it is important to call getBrowserTimingFooter near the end of request handling so the metrics will be accurate.

So there are very specific points where the JavaScript code needs to be injected.

My index.zul file is like:

<?xml version="1.0" encoding="UTF-8"?>
<?page style="height:100%" automaticTimeout="true" id="ecs"?>
<?link rel="shortcut icon" type="image/x-icon" href="/C16.ico"?>
<?link rel="icon" type="image/x-icon" href="/C16.ico"?>
<zk>
	<zscript>
		execution.setResponseHeader("Pragma", "no-cache,no-store");
		execution.setResponseHeader("Cache-Control","no-cache,no-store,must-revalidate,proxy-revalidate,max-age=0");
	</zscript>
	<style src="css/default.css.dsp"/>
	<window use="com.ecaresoft.web.ECareSoftWebUI"/>
</zk>

where ECareSoftWeuUI extends from org.zkoss.zul.Window.

Thanks in advance for any aditional pointers, and best regards.

link publish delete flag offensive edit

answered 2012-11-05 03:14:54 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi mrojas,

Can you provide the content of page source to me to investigate? please refer to the following video
http://screencast.com/t/nDvnTciU

link publish delete flag offensive edit

answered 2012-11-14 17:52:44 +0800

mrojas gravatar image mrojas
17 2

Sorry for the late reply, but I got busy in another project.

this is the ZK generated page content

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<title>eCS Inpatient EHR Client</title>

<link rel="stylesheet" type="text/css" href="/eCareSoftWeb/zkau/web/373c71ee/_zkiju-silvertail/zul/css/zk.wcs"/>

<script type="text/javascript" src="/eCareSoftWeb/zkau/web/373c71ee/js/zk.wpd" charset="UTF-8">
</script>
<script type="text/javascript" src="/eCareSoftWeb/zkau/web/373c71ee/js/zul.lang.wpd" charset="UTF-8">
</script>
<!-- ZK 5.0.11 2012032814 -->
<script type="text/javascript">zkopt({to:1860});</script><link rel="shortcut icon" type="image/x-icon" href="/eCareSoftWeb/C16.ico"/>
<link rel="icon" type="image/x-icon" href="/eCareSoftWeb/C16.ico"/>
</head>
<body>
<div id="wG0Q_" class="z-temp"><script src='/eCareSoftWeb/zkau/web/373c71ee/js/zul.silvertail.wpd'></script></div>
<script type="text/javascript">zk.pi=1;zkmx(
[0,'wG0Q_',{id:'ecs',dt:'z_eka',cu:'/eCareSoftWeb',uu:'/eCareSoftWeb/zkau',ru:'/index.zul',style:'height:100%'},[
['zul.utl.Style','wG0Q0',{visible:false,src:'css/default.css.dsp'},[]],
['zul.wnd.Window','wG0Q1',{visible:false,$$onSize:false,$$onMaximize:false,$$onOpen:false,$$onMinimize:false,$$onZIndex:false,$onClose:true,$onCancel:true,$$onMove:false,prolog:'\n\t'},[]],
['zul.layout.Borderlayout','wG0Q2',{},[
['zul.layout.Center','wG0Q3',{$$onOpen:false,$$onSize:false,border:'none',flex:true,autoscroll:true},[
['zul.box.Box','wG0Q4',{sclass:'login',align:'center',pack:'center'},[
['zul.wnd.Window','wG0Q7',{$onOK:true,$onClose:true},[
['zul.box.Box','wG0Q6',{id:'loginPanel',width:'510px',style:'background-color:#FFFFFF;'},[
['zul.wgt.Cell','wG0Q8',{width:'100%',align:null,valign:null},[
['zul.wgt.Image','wG0Q9',{src:'/eCareSoftWeb/images/Pleca_superior_azul.png'},[]]]],
['zul.wgt.Cell','wG0Qa',{width:'100%',align:null,valign:null},[
['zul.wgt.Image','wG0Qb',{src:'/eCareSoftWeb/Logo_eCareSoft_Small_2.png'},[]]]],
['zul.wgt.Cell','wG0Qc',{align:null,valign:null},[
['zul.grid.Grid','wG0Qd',{$$onRender:true,$$onDataLoading:true,$$onInnerWidth:false,$$onPageSize:true,$$onScrollPos:false,width:'100%',sclass:'no-highlight',style:'border: none;',oddRowSclass:'even',_topPad:0,emptyMessage:null,_totalSize:4,_offset:0},[
['zul.grid.Rows','wG0Qe',{_offset:0,visibleItemCount:4},[
['zul.grid.Row','wG0Qf',{style:'border: none'},[
['zul.wgt.Cell','wG0Qg',{width:'30%',align:null,valign:null},[
['zul.wgt.Div','wG0Qh',{style:'text-align: right'},[
['zul.wgt.Label','wG0Qi',{id:'lblUserId',value:'User ID'},[]]]]]],
['zul.wgt.Cell','wG0Qj',{width:'70%',align:null,valign:null},[
['zul.inp.Textbox','wG0Q5',{id:'txtUserId',$onBlur:true,$$onError:false,$$onChange:false,$onChange:true,$onFocus:true,width:'220px',maxlength:40,cols:25},[]]]]]],
['zul.grid.Row','wG0Qk',{style:'border: none'},[
['zul.wgt.Cell','wG0Ql',{width:'30%',align:null,valign:null},[
['zul.wgt.Div','wG0Qm',{style:'text-align: right'},[
['zul.wgt.Label','wG0Qn',{id:'lblPassword',value:'Password'},[]]]]]],
['zul.wgt.Cell','wG0Qo',{width:'70%',align:null,valign:null},[
['zul.inp.Textbox','wG0Qp',{id:'txtPassword',$onBlur:true,$onFocus:true,width:'220px',maxlength:40,cols:25,type:'password'},[]]]]]],
['zul.grid.Row','wG0Qq',{style:'border: none'},[
['zul.wgt.Cell','wG0Qr',{width:'30%',align:null,valign:null},[
['zul.wgt.Div','wG0Qs',{style:'text-align: right'},[
['zul.wgt.Label','wG0Qt',{id:'lblLanguage',value:'Language'},[]]]]]],
['zul.wgt.Cell','wG0Qu',{width:'70%',align:null,valign:null},[
['zul.inp.Combobox','wG0Qv',{id:'lstLanguage',$$onSelect:false,$onSelect:true,$$onError:false,$$onChange:false,width:'220px',_value:'English'},[
['zul.inp.Comboitem','wG0Qw',{label:'English'},[]],
['zul.inp.Comboitem','wG0Qx',{label:'Español México'},[]],
['zul.inp.Comboitem','wG0Qy',{label:'Italiano'},[]]]]]]]],
['zul.grid.Row','wG0Qz',{style:'border: none'},[
['zul.wgt.Cell','wG0Q_0',{width:'30%',align:null,valign:null},[
['zul.wgt.Space','wG0Q00',{orient:'vertical'},[]]]],
['zul.wgt.Cell','wG0Q10',{width:'70%',align:null,valign:null},[
['zul.wgt.Div','wG0Q20',{width:'220px',align:'right'},[
['zul.wgt.Checkbox','wG0Q30',{$$onCheck:false,label:'Remember my User ID'},[]]]]]]]]]]]]]],
['zul.wgt.Cell','wG0Q40',{align:null,valign:null},[
['zul.wgt.Div','wG0Q50',{width:'95%',align:'center'},[
['zul.wgt.Div','wG0Q60',{width:'100%',align:'right'},[
['zul.wgt.Button','wG0Q70',{id:'Ok',$onClick:true,tooltip:'OK',image:'/eCareSoftWeb/images/24x24/Ok_24.png'},[],'trendy']]]]]]],
['zul.wgt.Cell','wG0Q80',{width:'100%',colspan:2,align:null,valign:null},[
['zul.wgt.Toolbarbutton','wG0Q90',{id:'lblGetPassword',$onClick:true,style:'color: #00ADEF;',label:'Forgot Password?'},[]]]],
['zul.wgt.Cell','wG0Qa0',{width:'100%',align:null,valign:null},[
['zul.wgt.Image','wG0Qb0',{src:'/eCareSoftWeb/images/Pleca_inferior_negra.png'},[]]]]],'vertical']]]],'vertical']]]]]]],0,
['clientInfo','["z_eka"]',
'focus','["wG0Q5"]',
'script','["ecs.findUserToken(\'wG0Q6\', \'L3dvcmtfYXJlYS9EZXZlbG9wbWVudC9EZXBsb3ltZW50cy9SMTAvQ29tcGllcmUy\');"]']);
</script>
<noscript>
<div class="noscript"><p>Sorry, JavaScript must be enabled.<br/>Change your browser options, then <a href="">try again</a>.</p></div>
</noscript>

</body>
</html>

The New Relic documentation is located at: https://newrelic.com/docs/java/real-user-monitoring-in-java
It says that when there are no JSPs involved, then we should insert the monitoring code in some specific poits, but I have been unable to do it using ZK.

Best regards.

link publish delete flag offensive edit

answered 2013-01-14 07:12:00 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi
I have created a ZK Initiator to append the javascript

zul

<?init class="org.zkoss.test.TestInitiator"?>

java

package org.zkoss.test;

import java.util.Map;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.impl.PageImpl;
import org.zkoss.zk.ui.util.Initiator;
import org.zkoss.zk.ui.util.InitiatorExt;
import org.zkoss.zul.Html;

public class TestInitiator implements Initiator, InitiatorExt {

	private static final String INIT_NewRelic = TestInitiator.class.getName() + "_NewRelic";
	private String header;
	private String footer;

	public void doInit(Page page, Map<String, Object> args) throws Exception {
		header = com.newrelic.api.agent.NewRelic.getBrowserTimingHeader();
		footer = com.newrelic.api.agent.NewRelic.getBrowserTimingFooter();
	}


	public void doAfterCompose(Page page, Component[] comps) throws Exception {
		
		Desktop desktop = page.getDesktop();
		boolean inited = Boolean.TRUE.equals(desktop.getAttribute(INIT_NewRelic));
		if (!inited) {
			desktop.setAttribute(INIT_NewRelic, Boolean.TRUE);
			PageImpl pageImpl = (PageImpl)page;
			pageImpl.addAfterHeadTags(header);
		}
		new Html(footer).setPage(page);
	}

	public boolean doCatch(Throwable ex) throws Exception {
		return false;
	}

	public void doFinally() throws Exception {
		
	}


}

link publish delete flag offensive edit

answered 2015-03-31 15:30:17 +0800

xeridia gravatar image xeridia
47 1

updated 2015-03-31 15:31:43 +0800

Hi! I am developing an application whose strategy when using ZK (7.0.1), is to use JSP as layout (header, content and footer) where the content section is the only one to be refreshed on a request (zkau). I would like to integrate RUM monitoring with the latest version of NewRelic agent, but the use of the Initiator does not work. So if there is anybody who has integrated ZK and NewRelic with this strategy, and can share his solution, it would be appreciated.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-10-24 20:40:02 +0800

Seen: 151 times

Last updated: Mar 31 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More