private Monitor newMonitor(final Connection connection, String[] monitorTargets) {
    Monitor monitor;
    boolean useRegExp = conf.getBoolean(HBASE_CANARY_USE_REGEX, false);
    boolean regionServerAllRegions = conf.getBoolean(HBASE_CANARY_REGIONSERVER_ALL_REGIONS, false);
    boolean failOnError = conf.getBoolean(HBASE_CANARY_FAIL_ON_ERROR, true);
    int permittedFailures = conf.getInt(HBASE_CANARY_ZOOKEEPER_PERMITTED_FAILURES, 0);
    boolean writeSniffing = conf.getBoolean(HBASE_CANARY_REGION_WRITE_SNIFFING, false);
    String writeTableName =
      conf.get(HBASE_CANARY_REGION_WRITE_TABLE_NAME, DEFAULT_WRITE_TABLE_NAME.getNameAsString());
    long configuredWriteTableTimeout =
      conf.getLong(HBASE_CANARY_REGION_WRITE_TABLE_TIMEOUT, DEFAULT_TIMEOUT);

    if (this.regionServerMode) {
      monitor = new RegionServerMonitor(connection, monitorTargets, useRegExp,
        getSink(connection.getConfiguration(), RegionServerStdOutSink.class), this.executor,
        regionServerAllRegions, failOnError, permittedFailures);

    } else if (this.zookeeperMode) {
      monitor = new ZookeeperMonitor(connection, monitorTargets, useRegExp,
        getSink(connection.getConfiguration(), ZookeeperStdOutSink.class), this.executor,
        failOnError, permittedFailures);
    } else {
      monitor = new RegionMonitor(connection, monitorTargets, useRegExp,
        getSink(connection.getConfiguration(), RegionStdOutSink.class), this.executor,
        writeSniffing, TableName.valueOf(writeTableName), failOnError, configuredReadTableTimeouts,
        configuredWriteTableTimeout, permittedFailures);
    }
    return monitor;
  }
A Factory method for {@link Monitor}. Makes a RegionServerMonitor, or a ZooKeeperMonitor, or a
RegionMonitor.
@return a Monitor instance
hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java