25.01.2015 Views

Caché Monitoring Guide - InterSystems Documentation

Caché Monitoring Guide - InterSystems Documentation

Caché Monitoring Guide - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using the <strong>Caché</strong> Monitor<br />

3.2.2.1 Generating Metrics<br />

The %Monitor.SampleAgent class is the class that does the actual sampling. It is this class that invokes the Initialize() and<br />

GetSample() methods of the metrics classes.<br />

The %Monitor.SampleAgent.%New(n) constructor takes one argument, the name of the metrics class it is to run. It creates<br />

an instance of that class, and invokes the Startup() method on that class. Then, each time the<br />

%Monitor.SampleAgent.Collect() method is invoked, the Sample Agent invokes the Initialize() method for the class,<br />

then repeatedly invokes the GetSample() method for the class. On each call to GetSample(), %Monitor.SampleAgent creates<br />

a sample class for the metrics class; the pseudocode for these operations is:<br />

Set sampler = ##class(%Monitor.SampleAgent).%New("MyMetrics.Freespace")<br />

/* at this point, the sampler has created an instance of MyMetrics.Freespace,<br />

and invoked its Startup method */<br />

for I=1:1:10 d sampler.Collect() h 10<br />

/* at each iteration, sampler calls MyMetrics.Freespace.Initialize(), then loops<br />

on GetSample(). Whenever GetSample() returns $$$OK, sampler creates a new<br />

MyMetrics.Sample.Freespace instance, with the sample data. When GetSample()<br />

returns an error value, no sample is created, and sampler.Collect() returns. */<br />

3.2.2.2 Viewing Metrics Data<br />

All metrics classes are CSP-enabled; the CSP code is generated automatically when the sample class is generated. Therefore,<br />

the simplest way to view metrics is using a web browser; for example, based on the example in Generating Metrics, the<br />

CSP URL is: http://localhost:57772/csp/user/MyMetrics.Sample.Freespace.cls, which displays output similar to:<br />

Monitor - Freespace c:\cache51\<br />

Name of dataset: c:\cache51\<br />

Current amount of Freespace: 8.2MB<br />

Monitor - Freespace c:\cache51\mgr\<br />

Name of dataset: c:\cache51\mgr\<br />

Current amount of Freespace: 6.4MB<br />

Alternatively, you can use the Display() method of the %Monitor.View class; for example:<br />

%SYS>s mclass="Monitor.Test.Freespace"<br />

%SYS>s col=##class(%Monitor.SampleAgent).%New(mclass)<br />

%SYS>w col.Collect()<br />

1<br />

%SYS>w ##class(%Monitor.View).Display(mclass)<br />

Monitor - Freespace c:\cache51\<br />

Name of dataset: c:\cache51\<br />

Current amount of Freespace: 8.2MB<br />

Monitor - Freespace c:\cache51\mgr\<br />

Name of dataset: c:\cache51\mgr\<br />

Current amount of Freespace: 6.4MB<br />

3.2.3 Writing User-defined Monitor Classes<br />

In addition to predefined classes for monitoring system metrics, you can write your own monitor classes to monitor user<br />

application data and counters.<br />

A monitor class is any class that inherits from the abstract Monitor class, %Monitor.Adaptor; the %Monitor.System classes<br />

are examples of Monitor classes. To create your own user-defined monitor classes:<br />

1. Write a class that inherits from %Monitor.Adaptor. The inheritance provides persistence, parameters, properties, code<br />

generation, and a projection that generates the monitor metadata from your class definition. See the %Monitor.Adaptor<br />

class documentation in the <strong>Caché</strong> Class Reference for full details on this class, as well as the code you must write.<br />

2. Compile your class. Compiling classes that inherit from %Monitor.Adaptor generates new classes in a subpackage of<br />

the users class called Sample. So, for example, if you compile A.B.MyMetric, a new class is generated in<br />

A.B.Sample.MyMetric. You do not need to do anything with the generated class.<br />

30 <strong>Caché</strong> <strong>Monitoring</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!