code: public static <T> ToDoubleFunction<T> invokeMethod(final Method method) {
      method.setAccessible(true);
      return (obj) -> {
        try {
          final Number n = (Number) method.invoke(obj);
          return n.doubleValue();
        } catch (Exception e) {
          LOGGER.warn("exception from method registered as a gauge [" + method + "]", e);
          return Double.NaN;
        }
      };
    }
docs: Returns a function that invokes a method on the object via reflection. If an
  exception of any kind occurs then NaN will be returned and the exception will be logged.
  The method must have an empty parameter list and return a primitive number value or a
  subclass of {@link java.lang.Number}. The method will be set accessible so that private
  methods can be used.
  
  @param method
  Method to execute on the passed in object.
  @return
  Value returned by the method or NaN if an exception is thrown.