cancel
Showing results for 
Search instead for 
Did you mean: 

Server Start time from IMetrics

Former Member
0 Kudos

Can you tell me how to parse back the time value i get form the metrics interface from a server?

I can see we have a Enum to tell me it is Date / Time, but the value i get back is a decimal:

sample output:

Metric Name:

ISPROP_GEN_STARTTIME

Metric Value:

40877.1362435995

it seems there should be some easy way to cast this into Date / Time, since it is displayed that way in the CMC.

IInfoObjects objects = infoStore.query("select * from CI_SYSTEMOBJECTS where SI_KIND = 'Server' ");

for (@SuppressWarnings("rawtypes")

Iterator iterator = objects.iterator(); iterator.hasNext();)

{

try {

IServer server = (IServer) iterator.next();

String metricDescriptionsQuery = "SELECT * FROM CI_SYSTEMOBJECTS WHERE SI_KIND='MetricDescriptions'";

//get the base collection

IServerMetrics baseMetrics = server.getMetrics();

IMetricDescriptions metricDescriptions;

metricDescriptions = (IMetricDescriptions) infoStore.query(metricDescriptionsQuery).get(0);

//get the set of metrics that has the server start time

IMetrics subMetrics = baseMetrics.getMetrics("ISGeneralAdmin");

Iterator serviceMetricsIter = subMetrics.iterator();

while(serviceMetricsIter.hasNext()) {

IMetric metric = (IMetric) serviceMetricsIter.next();

String metricName = metric.getName().trim();

System.out.println(metricName + ";");

// Get the localized metric name.

IMLDescriptions descriptions = metricDescriptions.getMetricDescriptions("ISGeneralAdmin");

IPropertyRenderTemplate propertyRenderTemplate = descriptions.getPropertyRenderTemplate(metricName);

if(metricName.contains("ISPROP_GEN_STARTTIME") )

{

System.out.println(metric.getValue().toString());

ValueFormat metricValFormat = propertyRenderTemplate.getValueFormat();

System.out.println(metricValFormat.toString());

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try this code to retrieve the server start time

<%@ page import = "com.crystaldecisions.sdk.framework.*"%>
<%@ page import = "com.crystaldecisions.sdk.exception.*"%>
<%@ page import = "com.crystaldecisions.sdk.occa.infostore.*"%>
<%@ page import = "com.crystaldecisions.sdk.plugin.desktop.server.*"%>
<%@ page import = "com.crystaldecisions.sdk.occa.infostore.CePropertyID"%>
<%@ page import = "com.crystaldecisions.sdk.occa.enadmin.*"%>
<%@ page import = "com.crystaldecisions.sdk.plugin.admin.cmsadmin.*"%>
<%@ page import = "com.crystaldecisions.sdk.plugin.desktop.common.*"%>
<%@ page import = "com.crystaldecisions.sdk.occa.security.*"%>

<html>
<head>
<title>Display Server Metrics</title>
</head>
<body>

<%
	// Set the logon information
    String boUser = "Administrator";
    String boPassword = "";
    String boCmsName = "localhost:6400";
    String boAuthType = "secEnterprise";

	// Declare Variables
    IInfoStore boInfoStore=null;
	IInfoObjects boInfoObjects=null;
	SDKException failure = null;
	IEnterpriseSession boEnterpriseSession = null;
	
	IServer currentServer = null; 
	ICMSAdmin cmsAdmin = null;
	IServerGeneralMetrics serverMetrics = null; 
	
   try{
   	    // Logon and obtain an Enterprise Session
    	boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon( boUser, boPassword, boCmsName, boAuthType);
        boInfoStore = (IInfoStore) boEnterpriseSession.getService("", "InfoStore");

	    boInfoObjects = boInfoStore.query("Select * From CI_SYSTEMOBJECTS Where SI_PROGID='CrystalEnterprise.Server'and SI_DESCRIPTION='Central Management Server'");
	for(int i=0;i<boInfoObjects.getResultSize();i++)
	{
    	currentServer = (IServer) boInfoObjects.get(i);

	
   
        out.println("Before Metrics");
        //Display the server information
        out.println ("Server: " + currentServer.getFriendlyName() + "<BR>");
        out.println ("Enabled: " + !currentServer.isDisabled() + "<BR>");
        out.println("Running: " + currentServer.isAlive());

        out.println ("<HR><B>General metrics</B><BR>");
        //retrieve and display Server metrics
        serverMetrics = currentServer.getServerGeneralAdmin();
        out.println ("CPU: " + serverMetrics.getCPU()+"<BR>");
        out.println ("CPU count: " + serverMetrics.getCPUCount()+"%<BR>");
        out.println ("Current time: " + serverMetrics.getCurrentTime()+"<BR>");
        out.println ("Server start time: " + serverMetrics.getStartTime()+"<BR>");
        out.println ("Available disk space: " + serverMetrics.getDiskSpaceAvailable()+"bytes<BR>");
        out.println ("Total disk space: " + serverMetrics.getDiskSpaceTotal()+"bytes<BR>");
        out.println ("Memory available: " + serverMetrics.getMemory()+"bytes<BR>");
        out.println ("Operating system: " + serverMetrics.getOperatingSystem()+"<BR>");
        out.println ("Server Version: " + serverMetrics.getVersion()+"<BR><BR>");

        }
     }
    catch(SDKException e)
    {
        out.println(e.getMessage());
        System.err.println("Unable to retrieve server metrics. Exception caught: " + e.getMessage());
    }
    finally
    {
	    boEnterpriseSession.logoff();
    }
%>

</body>
</html>

Hope this is useful to you.

Regards,

Prithvi

Answers (0)