Skip to Content
author's profile photo Former Member
Former Member

Server Start time from IMetrics

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());

}

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Dec 07, 2011 at 06:29 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.