Call the
CasCrawler.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:
CasCrawler.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
CAS Server API Reference (Javadoc) for the list of
MetricId enumerations.
The
CRAWL_STOP_CAUSE
MetricId has one of the following values:
If a crawl fails, the
CRAWL_FAILURE_REASON
MetricId provides a message from the CAS Server
explaining the failure.
Your application can print out all or some of the metric values.
To get the metrics of a crawl:
Make sure that you have created a connection to the CAS Server. (A
CasCrawlerobject namedcrawleris used in this example.)Set the name for the crawl by first instantiating a
CrawlIdobject and then setting its Id.For example:
// Create a new crawl Id with the name set to Demo. CrawlId crawlId = new CrawlId("Demo");Call the
CasCrawler.getMetrics()method with the crawl ID.For example:
List<Metric> metricList = crawler.getMetrics(crawlId);
Print the metrics by retrieving the values from the
Metricobjects. 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.getMetric()) { MetricId id = metric.getMetricId(); if (id.equals(MetricId.TOTAL_RECORDS)) { System.out.println("Total records: " + metric.getValue()); } } }
The
CasCrawler.getMetrics() method throws a
CrawlNotFoundException if the specified crawl (the
crawlId parameter) does not exist or is
otherwise not found.

