public NullableValue readMetricsValue(MetricsCondition condition, Duration duration) throws IOException {
        long defaultValue = ValueColumnMetadata.INSTANCE.getDefaultValue(condition.getName());
        if (!condition.senseScope() || !condition.getEntity().isValid()) {
            return new NullableValue(defaultValue, true);
        }
        MetricsValues metricsValues = readMetricsValues(condition, duration);
        if (!metricsValues.getValues().getValues().isEmpty()) {
           OptionalDouble avgValue = metricsValues.getValues().getValues().stream().filter(v -> !v.isEmptyValue()).mapToLong(
               KVInt::getValue).average();
           if (avgValue.isPresent()) {
               return new NullableValue((long) avgValue.getAsDouble(), false);
           }
        }

        return new NullableValue(defaultValue, true);
    }
Read metrics average value in the duration of required metrics
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/MetricsQueryService.java