How to save energy is a critical issue for the life time of sensor networks. Under continuously changing environments, sensor nodes have varying sampling rates. In this paper, we present an online algorithm to minimize the total energy consumption while satisfying sampling rate with guaranteed probability. We model the sampling rate as a random variable, which is estimated over a finite time window. An efficient algorithm, EOSP (Energy-aware Online algorithm to satisfy Sampling rates with guaranteed Probability), is proposed. Our approach can adapt the architecture accordingly to save energy. Experimental results demonstrate the effectiveness of our approach.