The rate at which energy is converted into organic matter by photosynthesis and chemosynthesis in ecosystems.