The first lesson I ever taught was on Standard Deviation to a high school Intro to Engineering class. It went fabulously and I stuck to the lesson plan covering every point on my slide show and getting through every activity only having to shorten the pair and share activity due to time constraints. The students understood everything, responded to discussion well, and the observing teacher gave me a glorious review.
Then I had to present the same lesson to my Education class. Within the first five minutes, I realized that there was only a single person in the entire class with the background needed to understand the mathematics I was presenting. This made the warm-up exercise and discussion extremely one-sided. In that moment, I decided to abandon my lesson plan and launched into a discussion about crappy furniture. Every college student can understand crappy furniture even if none of them understood what variance had to do with it. By the end of the lesson, most of the students had a reasonably good grasp on the concept of standard deviation and how it relates to Ikea.
Any time you're speaking to an audience, you have to pay attention to their attitude and capture their attention. In my example it's a bit different than most teaching situations because I had prepared for a class that had the background to understand my content but the idea can carry over to any classroom. If either they don't get it or you are having an off teaching day. It could be time to switch gears and doing that midway through a lesson is not a terrible idea.
Making a habit of going off-topic is ill-advised. I've heard horror stories of professors who just go off on tangents for most of the lesson. This not only creates discontinuity in your teaching but is a waste of valuable instruction time. While this may be interesting every now and then, if it's your go-to teaching method, there is a problem.
If at all possible, have a plan B. When I prepared my lesson on Standard Deviation, I had weeks to work on the lesson plan and had a variety of topics to generate discussion in case the class decided to be sleepy and quiet that morning. So when my education class was not responsive, it wasn't hard to come up with something that they could relate to but still stay relatively on topic. When working on a lesson plan, considering the question 'What if this bombs?' is not a terrible one.
I don't believe there's an easy method of knowing if a class is bored or lost or hungover but I think the best way to tell if you should jump ship on your lesson plan is to know your students. Could you drop the lesson plan and just have a discussion on the topic? Would they be able to follow and participate in such a discussion? Is that something that would interest them? Would they get more out of a discussion than the lecture right now?