Find the minimum value of
\[f(x) = x + \frac{x}{x^2 + 1} + \frac{x(x + 4)}{x^2 + 2} + \frac{2(x + 2)}{x(x^2 + 2)}\]for $x > 0.$

Let's think step by step and output the final answer within \boxed{}.
user