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());
    }
  }