Skip to end of metadata
Go to start of metadata

Author: Michael Nicholls

Submitted: July 2009
Description

The available.log file in an instance's work directory shows the availability of an instance. This component reads the details....

package com.sap.anz;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.StringTokenizer;

import com.sapportals.portal.prt.component.AbstractPortalComponent;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;

public class UpTime extends AbstractPortalComponent
{
    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
    {
    	String SID = System.getProperty("SAPSYSTEMNAME").toString();
    	SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    	File dir = new File("/usr/sap/"+SID);
		String[] files = dir.list();
		for (int i=0; (files!=null && i<files.length);i++) {
			String dirname = files[i];
			if (dirname.length()<3) return;
			if (dirname.startsWith("DVEBMGS") ||
				dirname.startsWith("D") ||
				dirname.startsWith("JC") ||
				dirname.startsWith("J")) {
			String inst = dirname.substring(dirname.length()-2);
			response.write("<br>Instance:"+inst);
			long avail = 0;
			long unavail = 0;
			String workdir = "/usr/sap/"+SID+"/"+dirname+"/work";
			String available = "available.log";
			File f = new File(workdir+"/available.log");
			try {
				BufferedReader i1 = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF8"));
				String line = "";
				int lineNum = 0;
				while ((line = i1.readLine())!=null) {
					StringTokenizer st = new StringTokenizer(line," ");
					if (st.countTokens()==6) {
						String s = st.nextToken();
						String From = st.nextToken() + " "+st.nextToken();
						Date from = sdf.parse(From);
						st.nextToken();
						String To = st.nextToken() + " "+st.nextToken();
						Date to = sdf.parse(To);
						long diff = (to.getTime()-from.getTime())/1000;
						if (s.equalsIgnoreCase("unavailable"))
							unavail = unavail + diff;
						if (s.equalsIgnoreCase("available"))
							avail = avail + diff;
					}
				};
				response.write("<br>Available  :"+avail+"(seconds)");
				response.write("<br>Unavailable:"+unavail+"(seconds)");
			} catch (Exception e) {
				response.write("Error opening available.log "+e.getLocalizedMessage());	
			}
			}
		};
    }
}