I've read quite a few books on writing comedy and stand up comedy and far and away the best for understanding the mechanics of it was What Are You Laughing At? A Comprehensive Guide to the Comedic Event by Dan O'Shannon.

Some basic golden rules:

Comedy is about surprise. Don't let them see the punchline coming.

Related to the above, make sure you've done enough setup so the audience can reach the punchline. An obvious connection to you might be not be so obvious to the audience. The punchline will flop if the gap between the setup and the punchline is too large for the audience to connect the dots.

Lie when you're meant to tell the truth. Tell the truth when you're meant to lie.

The funniest word or part of the joke needs to be at the end of the sentence.

Don't change your delivery for the punchline. Tell it straight and commit to it. Changing your delivery for the punchline is equivalent to putting a laugh track on a old style sitcom. If you have to prompt people to laugh, it's not funny.

Utilise the rule of three.[1]

Be as concise as possible.*

If you're telling a story, heighten the details even if that means lying about what actually happened. My friend has a story about a barfight in Thailand. The first time he told it, 5 people ran out of the bar to join him in the fight. The second time he told it 20 people ran out of the bar to join in the fight. The last time I heard it, everyone in the bar ran out and joined in the fight. The last one is inherently funnier because the chaos is heightened. Google Bert Kresicher's advice on telling stories for more info and examples, he's one of the best storytelling comedians around at the minute.

A related rule is, when telling a story based on a real life anecdote, recall the story and not the event. Unless you've got photographic recall, if you try and recall the event as you lived it, you're going to get trapped trying to remember precise details and you'll slow down the joke and people will zone out e.g:

"So there was me, Dave and John at the bar. No not John, Stan. And we were hitting up this bunch of girls and one of them was wearing this leopard print dress, no not leopard print, tiger print."

Never do this. Try and plan out how you're going to tell the story. Cut it down to the essentials and keep iterating on it.

If you've written a monologue, always practice speaking it out loud before performing and revise it accordingly. It needs to sound like you're speaking naturally in the moment and your written voice is normally more formal and stuffy than your spoken voice.

*The exception to this rule is if you're doing a shaggy dog story[2]. These are ramblings deliberately meant to lead the audience down the garden path with a punchline that didn't require about 90% of the surreal setup. The key to pulling these off well is to have mini punchlines or funny occurrences happen whilst you're telling the story and building the tension appropriately, otherwise the audience just zones out. The absolute master of these was Norm MacDonald, who in my opinion told the greatest one of all time, Dirty Johnny[3]. The other great one I've heard is "The Orange Head Joke"

[1] https://en.wikipedia.org/wiki/Rule_of_three_(writing)

[2] https://en.wikipedia.org/wiki/Shaggy_dog_story

[3] https://www.youtube.com/watch?v=GskNV_XRZvU