public MetricValue getValue(Metric metric)
      throws PluginException, MetricNotFoundException, MetricUnreachableException {
    AgentDaemon agent;

    if ((agent = AgentDaemon.getMainInstance()) == null) {
      throw new PluginException(
          "Agent.getValue() called " + "when plugin not running " + "from within the Agent");
    }

    if (metric.toString().equals(AVAIL_TMPL)) {
      return new MetricValue(Metric.AVAIL_UP);
    }

    if (metric.getDomainName().equals("camAgent")) {
      return this.getAgentValue(agent, metric);
    } else if (metric.getDomainName().equals("sigar")) {
      return this.getSigarValue(metric);
    } else {
      throw new MetricInvalidException("Invalid JMX domain '" + metric.getDomainName() + "'");
    }
  }
  private MetricValue getAgentValue(AgentDaemon agent, Metric metric) throws PluginException {
    AgentMonitorValue mVal;
    String monitorName, monitorVal;

    monitorName = metric.getObjectProperty("Monitor");
    monitorVal = metric.getAttributeName();

    if (monitorName == null || monitorVal == null) {
      throw new MetricInvalidException(
          "Metric invalid -- no Monitor " + "key, or no attribute: " + metric);
    }

    mVal = agent.getMonitorValues(monitorName, new String[] {monitorVal})[0];

    if (mVal.isErr()) {
      switch (mVal.getErrCode()) {
        case AgentMonitorValue.ERR_INCALCULABLE:
          getLog().debug("Unable to calculate " + metric);
          return new MetricValue(Double.NaN);
        case AgentMonitorValue.ERR_BADKEY:
          throw new MetricInvalidException(
              "Agent monitor '" + monitorName + "' does not have " + "a " + monitorVal + " value");
        case AgentMonitorValue.ERR_BADMONITOR:
          throw new MetricInvalidException("Agent monitor '" + monitorName + "' unknown");
        case AgentMonitorValue.ERR_INTERNAL:
        default:
          throw new PluginException(
              "Internal error fetching" + " '" + monitorName + ":" + monitorVal + "'");
      }
    } else {
      if (mVal.getType() != AgentMonitorValue.TYPE_DOUBLE) {
        throw new MetricInvalidException(
            "Agent Metric '" + metric + "' " + "does not return a double");
      }

      return new MetricValue(mVal.getDoubleValue());
    }
  }