Geneos


The end of life (EOL) date for this module is on 31 January, 2020.

Write your own code

Step 1: Download and extract the client jar

If you have not already done so, download the Open Access Client zip file from our Downloads Page. Extract the downloaded file into a directory of your choice.

Step 2: Create a new Java class

In the directory to which you extracted the client, create a new java source file SimpleExample.java and edit it to contain the following:

Change url to point at your Open Access Cluster and path to point at a unique dataview in your gateway:

import com.itrsgroup.openaccess.Callback;
import com.itrsgroup.openaccess.Connection;
import com.itrsgroup.openaccess.ErrorCallback;
import com.itrsgroup.openaccess.OpenAccess;
import com.itrsgroup.openaccess.dataview.DataViewChange;
import com.itrsgroup.openaccess.dataview.DataViewQuery;

public final class SimpleExample {
    public static void main(String[] args) {
        // The url of you cluster node
        String url = "geneos.cluster://localhost:2551";
        // A path to a unique data view
        String path = "//dataview[@name='cpu']";
        // Connect to the Open Access cluster
        Connection conn = OpenAccess.connect(url);
        // Execute the query
        conn.execute(DataViewQuery.create(path),
            new Callback<DataViewChange>() {
                @Override
                public void callback(final DataViewChange data) {
                    // Print the changes
                    System.out.println(data.toString());
                }
            },
            new ErrorCallback() {
                @Override
                public void error(final Exception exception) {
                    // Uh oh! something went wrong!
                    exception.printStackTrace();
                }
            }
        );
    }
}

Step 3: Compile and run your code

Compile the code:

> javac -cp geneos-openaccess-client.jar SimpleExample.java

Run the code on Unix platforms:

> java -cp "geneos-openaccess-client.jar:logging:logging/*:." SimpleExample

Run the code on Windows:

> java -cp "geneos-openaccess-client.jar;logging;logging/*;." SimpleExample

The client uses a logging framework, see /client/logging.

If the code connects and executes successfully, you should see a series of DataViewChanges printed to stdout:

Change POPULATED
{
	col : 0
	data : 
		{
			id : /geneos/gateway[(@name="MyGateway")]/directory/probe[(@name="MyProbe")]/managedEntity[(@name="MyEntity")]/sampler[(@name="cpu")][(@type="")]/dataview[(@name="cpu")]
			sampleInterval : 1
			severity : UNDEFINED
		}
		[samplingStatus: OK]  [numOnlineCpus: 1]  [loadAverage1Min: 0.00]  [loadAverage5Min: 0.01]  [loadAverage15Min: 0.05]  [numPhysicalCpus: 1]
		
		+-------------+-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
		| cpu         | type                  | state              | clockSpeed         | percentUtilisation | percentUserTime    | percentKernelTime  | percentWaitTime    | percentIdle        |
		+-------------+-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
		| Average_cpu |                       |                    |                    | 1.00 %             | 0.00 %             | 1.00 %             | 0.00 %             | 99.00 %            |
		+-------------+-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
		| cpu_0       | GenuineIntel Intel(R) | on-line            | 2914.06 Mhz        | 1.00 %             | 0.00 %             | 1.00 %             | 0.00 %             | 99.00 %            |
		+-------------+-----------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
		
	sampleInterval : 1
	row : 0
}
Change CELL_UPDATE
{
	col : 4
	data : 
		{
			id : /geneos/gateway[(@name="MyGateway")]/directory/probe[(@name="MyProbe")]/managedEntity[(@name="MyEntity")]/sampler[(@name="cpu")][(@type="")]/dataview[(@name="cpu")]/rows/row[(@name="Average_cpu")]/cell[(@column="percentUserTime")]
			value : 1.00 %
			severity : UNDEFINED
		}
	row : 0
}
...