<commit_before>package kg.apc.jmeter.perfmon.agent;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.NetInterfaceStat;

import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.SigarProxy;
import org.hyperic.sigar.SigarProxyCache;
import org.hyperic.sigar.Swap;

/**
 * This class will do the Sigar calls. It is a singleton and will be shared
 * with all ConnectionThreads.
 * This class is based on Sigar API: http://www.hyperic.com/products/sigar
 * @author <NAME>
 */
public class MetricsGetter implements AgentCommandsInterface
{
   /*
    * The unic instance
    */
   private static MetricsGetter instance = new MetricsGetter();
   /*
    * The hostName where the server is run (retrieved by Sigar)
    */
   private String hostName = null;
   /*
    * We need to use the Sigar proxy to ensure high AgentConnector demands can be handled
    */
   private SigarProxy sigarProxy = null;

   /*
    * contains the list of drives for I/O metrics
    */
   private FileSystem[] fileSystems = null;
   private String[] networkInterfaces = null;

   /**
    * The constructor which instanciates the Sigar service
    */
   private MetricsGetter()
   {
      try
      {
         hostName = InetAddress.getLocalHost().getHostName();
         sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
         initFileSystems();
         initNetworkInterfaces();
      }
      catch (UnknownHostException e)
      {
         ServerAgent.logMessage(e.getMessage());
      }
   }

   /**
    * The only way to retrieve the object
    * @return the MetricsGetter instance
    */
   public static MetricsGetter getInstance()
   {
      return instance;
   }

   public final void initNetworkInterfaces()
   {
      try
      {
         networkInterfaces = sigarProxy.getNetInterfaceList();
      }
      catch (SigarException ex)
      {
         networkInterfaces = new String[0];
         ServerAgent.logMessage("Error while getting network interfaces: " + ex.getMessage());
      }
   }

   /**
    * Get list of FileSystems for I/O monitoring
    */
   public final void initFileSystems()
   {
      try
      {
         ArrayList tmp = new ArrayList();
         FileSystem[] fs = sigarProxy.getFileSystemList();
         for (int i = 0; i < fs.length; i++)
         {
            FileSystem fileSystem = fs[i];
            if (fileSystem.getType() == FileSystem.TYPE_LOCAL_DISK)
            {
               tmp.add(fileSystem);
            }
         }

         fileSystems = new FileSystem[tmp.size()];

         for (int i = 0; i < tmp.size(); i++)
         {
            fileSystems[i] = (FileSystem) tmp.get(i);
         }

      }
      catch (SigarException ex)
      {
         fileSystems = new FileSystem[0];
         ServerAgent.logMessage("Error while getting disks: " + ex.getMessage());
      }
   }

   /**
    * Get the current cpu load in percent
    * @return the cpu load, or -1 if a problem occurred
    */
   private double getCpuUsage()
   {
      try
      {
         return sigarProxy.getCpuPerc().getCombined();
      }<commit_msg>Added init info on agent startup<commit_after>package kg.apc.jmeter.perfmon.agent;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.NetInterfaceStat;

import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.SigarProxy;
import org.hyperic.sigar.SigarProxyCache;
import org.hyperic.sigar.Swap;

/**
 * This class will do the Sigar calls. It is a singleton and will be shared
 * with all ConnectionThreads.
 * This class is based on Sigar API: http://www.hyperic.com/products/sigar
 * @author <NAME>
 */
public class MetricsGetter implements AgentCommandsInterface
{
   /*
    * The unic instance
    */
   private static MetricsGetter instance = new MetricsGetter();
   /*
    * The hostName where the server is run (retrieved by Sigar)
    */
   private String hostName = null;
   /*
    * We need to use the Sigar proxy to ensure high AgentConnector demands can be handled
    */
   private SigarProxy sigarProxy = null;

   /*
    * contains the list of drives for I/O metrics
    */
   private FileSystem[] fileSystems = null;
   private String[] networkInterfaces = null;

   /**
    * The constructor which instanciates the Sigar service
    */
   private MetricsGetter()
   {
      try
      {
         hostName = InetAddress.getLocalHost().getHostName();
         sigarProxy = SigarProxyCache.newInstance(new Sigar(), 500);
         initFileSystems();
         initNetworkInterfaces();
      }
      catch (UnknownHostException e)
      {
         ServerAgent.logMessage(e.getMessage());
      }
   }

   /**
    * The only way to retrieve the object
    * @return the MetricsGetter instance
    */
   public static MetricsGetter getInstance()
   {
      return instance;
   }

   public final void initNetworkInterfaces()
   {
      try
      {
         networkInterfaces = sigarProxy.getNetInterfaceList();
         ServerAgent.logMessage("--- Network Interfaces init: ---");
         for(int i=0; i<networkInterfaces.length; i++)
         {
             ServerAgent.logMessage("Network interface detected: " + networkInterfaces[i]);
         }
         ServerAgent.logMessage("--------------------------------");
      }
      catch (SigarException ex)
      {
         networkInterfaces = new String[0];
         ServerAgent.logMessage("Error while getting network interfaces: " + ex.getMessage());
      }
   }

   /**
    * Get list of FileSystems for I/O monitoring
    */
   public final void initFileSystems()
   {
      try
      {
         ArrayList tmp = new ArrayList();
         FileSystem[] fs = sigarProxy.getFileSystemList();
         for (int i = 0; i < fs.length; i++)
         {
            FileSystem fileSystem = fs[i];
            if (fileSystem.getType() == FileSystem.TYPE_LOCAL_DISK)
            {
               tmp.add(fileSystem);
            }
         }

         fileSystems = new FileSystem[tmp.size()];

         for (int i = 0; i < tmp.size(); i++)
         {
            fileSystems[i] = (FileSystem) tmp.get(i);
         }
         ServerAgent.logMessage("------ File Systems init: ------");
         for(int i=0; i<fileSystems.length; i++)
         {
            ServerAgent.logMessage("File System detected: " + fileSystems[i].getDevName());
         }

         ServerAgent.logMessage("--------------------------------");

      }
      catch (SigarException ex)
      {
         fileSystems = new FileSystem[0];
         ServerAgent.logMessage("Error while getting disks: " + ex.getMessage());
      }
   }

   /**
    * Get the current cpu load in percent
    * @return the cpu load, or -1 if a problem occurred
    */
   private double getCpuUsage()
   {
      try
      {
         return sigarProxy.getCpuPerc().getCombined();
      }
{'fraction_non_alphanumeric': 0.11184395172607353, 'fraction_numerical': 0.0025259612685938817, 'mean_word_length': 2.2321995464852606, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '409518', 'n_tokens_mistral': 2069, 'n_tokens_neox': 2053, 'n_words': 537}