Ultrasensitively weighing nanoparticle masses is at the heart of modern measurement techniques. The traditional electrical mass measurement techniques, which are supported by external circuits, have been well known since the previous decade. In the present article, based on the all-optical technique, we propose a scheme of an optical sensor to weigh the masses of nanoparticles via a doubly clamped suspended carbon nanotube resonator. By measuring the resonance frequency shift of the nanotube in the probe absorption spectrum, we can easily determine the masses of external particles landing onto the surface of nanotube. This mass sensor may lead to a novel ultrasensitive measurement technique in nanoscience.