Optical magnetic field sensing based on metamaterial nanomechanics