Getting crawl metrics

Call the IasCrawler.getMetrics() method to return the metrics of a crawl. Metrics can be returned for a running crawl or (if the crawl is not running) for the last complete crawl.

The syntax of the method is:
IasCrawler.getMetrics(CrawlId crawlId)

The crawlId parameter is a CrawlId object that contains the name of the crawl for which metrics are to be returned.

The method returns a List<Metric> object, which (if not empty) will have one or more Metric objects. A Metric is a key-value pair that holds the value of a particular metric. The keys are the metric's ID (a MetricId enum class). See the IAS Server API Reference (Javadoc) for the list of MetricId enumerations.

The CRAWL_STOP_CAUSE MetricId has one of the following values:
  • COMPLETED
  • FAILED
  • ABORTED
If a crawl fails, the CRAWL_FAILURE_REASON MetricId provides a message from the IAS Server explaining the failure.

Your application can print out all or some of the metric values.

To get the metrics of a crawl:

  1. Make sure that you have created a connection to the IAS Server. (An IasCrawler object named crawler is used in this example.)
  2. Set the name for the crawl by first instantiating a CrawlId object and then setting its ID.
    For example:
    // Create a new crawl ID with the name set to Demo.
    CrawlId crawlId = new CrawlId("Demo");
  3. Call the IasCrawler.getMetrics() method with the crawl ID.
    For example:
    List<Metric> metricList = crawler.getMetrics(crawlId);
  4. Print the metrics by retrieving the values from the Metric objects. For example, if you want to print the number of records that have been processed so far by a running crawl, the code would be:
    if (crawler.getStatus(demoCrawlId).getState().equals(CrawlerState.RUNNING)) {
        List<Metric> metricList = crawler.getMetrics(crawlId);
        for (Metric metric : metricList) {
            MetricId id = metric.getMetricId();
            if (id.equals(MetricId.TOTAL_RECORDS)) {
                System.out.println("Total records: " + metric.toString());
            }
        }
    }

The IasCrawler.getMetrics() method throws a CrawlNotFoundException if the specified crawl (the crawlId parameter) does not exist or is otherwise not found.