Ngrinder two times development of monitoring machine performance data

Source: Internet
Author: User
Tags memory usage prev static class
1. Background

When doing performance testing, statistical performance data is divided into the data of the compressed system and the machine where the system is compressed, the data of the machine on which the system is being compressed mainly includes CPU utilization, memory utilization, network IO, disk IO and load Load;ngrinder By default only collects CPU, memories, Received byte/s, Sent Byte Per secode/s, supports custom data collection, previously covered: Ngrinder collects custom data and source code analysis for monitoring machines.

Show custom data to write files on a regular basis, it is more troublesome; This article will show you how to change the source code, directly showing the CPU utilization, memory utilization, network IO, disk IO and load loading of the 5 types of data. 2. Implement

Ngrinder is statistical machine performance data through the SIGAR API, SIGAR project home: Https://support.hyperic.com/display/SIGAR/Home, SIGAR api:http:// Cpansearch.perl.org/src/dougm/hyperic-sigar-1.6.3-src/docs/javadoc/org/hyperic/sigar/package-summary.html. 2-1. New data Types

Ngrinder-core Package:org.ngrinder.monitor.share.domain The SystemInfo class defines the type of data collected, adding load, read, Write and Memusedpercentage data fields:

/** * Modify by Hugang */public class SystemInfo extends Monitorinfo implements Serializable {private static final

    Long serialversionuid = -2995334644975166549l;
     /** * Header field of monitor status fields. *//Add load, disk IO and memory utilization public static final String HEADER = "ip,system,collecttime,freememory," + "tot

    Almemory,cpuusedpercentage,receivedpersec,sentpersec,load,read,write,memusedpercentage ";
    public Boolean isparsed () {return true;
     }/** * Enum for the system type, Linux or Windows.

    */public enum System {LINUX, WINDOW} private system system;

    Network IO protected BandWidth BandWidth;

    Private long Totalcpuvalue;

    Private long Idlecpuvalue;

    Private long freememory;

    Private long totalmemory;


    private float cpuusedpercentage;

    Load private double load;

    Disk read private long read;


    Disk write private long write; Memory Utilization Private DoUble Memusedpercentage; ... set (), get () method public void Parse (Compositedata CD) {//New this.load = getdouble (CD, "L
            Oad ");
            This.write = Getlong (CD, "write");
            This.read = Getlong (CD, "read"); 
    This.memusedpercentage = getdouble (CD, "Memusedpercentage");
        } public String torecordstring () {StringBuilder sb = new StringBuilder ();
        Sb.append (IP). Append (","). Append (System). Append (","); Sb.append (Dateutils.getcollecttimeinlong (New Date (Getcollecttime))). Append (","). Append (Freememory). Append (","

        );
        Sb.append (totalmemory). Append (","). Append (Cpuusedpercentage); if (bandWidth! = null) {Sb.append (","). Append (Bandwidth.getreceivedpersec ()). Append (","). Append (Bandwidth.get
        Sentpersec ()); }//new type load, read, write, memusedpercentage data stitching sb.append (","). Append (Load). Append (","). Append (Read). Append (","). Append (Write). Append (","). Append (memusedpercentAge);
        if (customvalues! = null) {Sb.append (","). Append (customvalues);
    } return sb.tostring (); } public static class Nullsysteminfo extends SystemInfo {private static final nullsysteminfo instance = new Null

        SystemInfo ();
        public static SystemInfo Getnullsysteminfo () {return instance;
         }/** * Return the empty record string.
         * * @return null filled record string. * @see #toRecordString () */@Override public String torecordstring () {StringBuilder
            SB = new StringBuilder ();
            Sb.append ("null"). Append (","). Append ("null"). Append (",");
            Sb.append ("null"). Append (","). Append ("null"). Append (",");
            Sb.append ("null"). Append (","). Append ("null");
            if (bandWidth! = null) {Sb.append (","). Append ("null"). Append (","). Append ("null");
           }//splicing new type data to "null" Sb.append (","). Append ("null"). Append (","). Append ("null"). Append (","). Append ("null");
                if (customvalues! = null) {int valuecount = stringutils.countmatches (Customvalues, ",") + 1;
                for (int i = 0; i < Valuecount; i++) {Sb.append (","). Append ("null");
        }} return sb.tostring ();
        } public boolean isparsed () {return false; }
    }



}
2-2. Collect new Data

The Execute () method in the Package:org.ngrinder.monitor.collector Systemdatacollector class in Ngrinder-core implements the collection of system data:

/** * Modify by Hugang */public synchronized SystemInfo execute () {SystemInfo SystemInfo = new SystemInfo ();
        Systeminfo.setcollecttime (System.currenttimemillis ());
            try {BandWidth networkusage = Getnetworkusage ();
            BandWidth BandWidth = Networkusage.adjust (Prev.getbandwidth ());
            Systeminfo.setbandwidth (BandWidth); Getcombined () represents the Sum of the User + Sys + nice + Wait systeminfo.setcpuusedpercentage ((float) Sigar.getcpuperc ().
            getcombined () * 100);
            CPU CPU = SIGAR.GETCPU ();
            Systeminfo.settotalcpuvalue (Cpu.gettotal ());
            Systeminfo.setidlecpuvalue (Cpu.getidle ());
            Mem mem = Sigar.getmem ();
            Systeminfo.settotalmemory (Mem.gettotal ()/1024L);

            Systeminfo.setfreememory (Mem.getactualfree ()/1024L);
            Added load, disk IO, and memory utilization//The system load averages for the past 1, 5, and minutes.
            Double load = 0;Long read = 0l;

            Long write = 0l;

            Load = sigar.getloadaverage () [0];

            Logger.info ("Monitor system load:{}", load);
            All file systems filesystem[] filesystems = Sigar.getfilesystemlist ();
            Get local file system list<string> Localdevnames = new arraylist<string> ();
                    for (FileSystem filesystem:filesystems) {if (filesystem.gettype () = = Filesystem.type_local_disk) {
                Localdevnames.add (Filesystem.getdevname ()); }} for (String localdevname:localdevnames) {Read + = Sigar.getdiskusage (Locald
                Evname). Getreadbytes ();
            Write + = Sigar.getdiskusage (localdevname). Getwritebytes ();

            }//logger.info ("Monitor system read:{}, write:{}", read, write);
            Systeminfo.setload (load);
            Systeminfo.setread (read/1024l);
  Systeminfo.setwrite (write/1024l);          Systeminfo.setmemusedpercentage (Mem.getusedpercent ()); Systeminfo.setsystem (Operatingsystem.is_win32?
            SystemInfo.System.WINDOW:SystemInfo.System.LINUX);
        Systeminfo.setcustomvalues (Getcustommonitordata ());
            } catch (Throwable e) {logger.error ("error while getting system perf data:{}", E.getmessage ());
        Logger.debug ("Error trace is", e);
        } prev = SystemInfo;
    return systemInfo;

 }
2-3. Front-end monitor template

Ngrinder-controller below SRC/MAIN/WEBAPP/WEB-INF/FTL/PERFTEST/DETAIL_REPORT/MONITOR.FTL defines the visualization of the system data, which is modified as follows:

< #setting number_format= "Computer" > < #import ". /.. /COMMON/SPRING.FTL "as spring/> <div class=" Page-header page-header ">  
3. Results show 

To package a project:

HUGANGDEMACBOOK-PRO:CPC hugang$ MVN clean-dmaven.test.skip=true Package

After the new war package is deployed and the service starts properly, the monitoring package needs to be re-downloaded because the dependent Ngrinder-core.jar package has changed and after restarting the monitoring service, perform the performance test task.

System Monitoring data file:/root/.ngrinder/perftest/0_999/${task Id}/report monitor_system_${ip}.data New load, read, Write and Memusedpercentage.

Front-end Display:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.