ibm-midrangejt400

Get CPU utilization of all jobs with JT400


I need to get the CPU utilization % of all jobs using JT400. But I can't manage to get a list of jobs at once since loadStatistics() is only available at job level not on the list (more time efficient).

With below code snipped I can get the CPU% per job one by one but it takes way to long:

AS400 as400 = new AS400("hostname", "username", "password");

//Reading SystemStatus like CPU usage and hdd usage
SystemStatus systemStatus = new SystemStatus(as400);
JobList list = new JobList(as400);
 list.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_ACTIVE, Boolean.TRUE);
 list.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_JOBQ, Boolean.FALSE);
 list.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_OUTQ, Boolean.FALSE);
 list.addJobAttributeToRetrieve(Job.CPU_TIME_USED);
 list.addJobAttributeToRetrieve(Job.SUBSYSTEM);
 list.addJobAttributeToRetrieve(Job.JOB_NAME);
 list.addJobAttributeToRetrieve(Job.JOB_NUMBER);
 list.addJobAttributeToRetrieve(Job.USER_NAME);
 //list.addJobAttributeToRetrieve(Job.ELAPSED_CPU_PERCENT_USED);


 Enumeration jobs = list.getJobs();

while (jobs.hasMoreElements())  {
    Job  j= (Job) jobs.nextElement();
    j.loadStatistics();
    //TimeUnit.SECONDS.sleep(10);
    System.out.println("Name " + j.getName() + " | Job NO : " + j.getNumber() + " | User : " + j.getUser() + " | CPU USED : " + j.getCPUUsed()+ " |  CPU% : " + j.getValue(Job.ELAPSED_CPU_PERCENT_USED));
    j.resetStatistics();
    }

Is there any way to get CPU% (Job.ELAPSED_CPU_PERCENT_USED) for all jobs at once?


Solution

  • I solved this back then using com.ibm.jtopenlite.components

    JobInfo [] jobs = lstJobs.getJobs(connection, false);
    
            List<Point> pointList = new ArrayList<Point>();
            
            for (JobInfo job : jobs) {
                log.debug("getCPUPercent: " + job.getCPUPercent());
                log.debug("getCurrentUser: " + job.getCurrentUser());
                log.debug("getJobName: " + job.getJobName());
                log.debug("getJobType: " + job.getJobType());
                log.debug("getSubsystem: " + job.getSubsystem());
                log.debug("getTotalCPUUsed: " + job.getTotalCPUUsed());
                log.debug("getUserName: " + job.getUserName());
                log.debug("getCPUPercentInTenths: " + job.getCPUPercentInTenths());
                                
            }