Example 2 Given the function $f(x)=\frac{m-2 \sin x}{\cos x}$ is monotonically decreasing on the interval $\left(0, \frac{\pi}{2}\right)$, try to find the range of the real number $m$.
Analyze We need to convert the expression into a trigonometric identity. Here, we will use the universal formula.
Solution Let $\tan \frac{x}{2}=t$, then $t \in(0,1)$. The original expression $=\frac{m-2 \cdot \frac{2 t}{1+t^{2}}}{\frac{1-t^{2}}{1+t^{2}}}=-m+\frac{2 m-4 t}{1-t^{2}}$
Assume $0\frac{m-2 t_{2}}{1-t_{2}^{2}}
$

Rearranging gives: $m2 \Leftrightarrow t_{1} t_{2}+1>t_{1}+t_{2} \Leftrightarrow\left(t_{1}-1\right)\left(t_{2}-1\right)>0
$

Since $t_{1}, t_{2} \in(0,1)$
The inequality holds. Therefore, the value of $\frac{2 t_{1} t_{2}+2}{t_{1}+t_{2}}$ is $(2,+\infty)$, so $m \leqslant 2$ is sufficient. Thus, the range of $m$ is $(-\infty, 2]$.