Is the difficulty in mining a function of how much total mining power there are in the ecosystem?
Difficulty is a function of the number of blocks and the time it took to produce them. In Bitcoin, the difficulty is calculated every 2016 blocks. At each recalculation, it calculates how long it took to mine the 2016 blocks using the block timestamps and then compares that to how long it should have taken to mine 2016 blocks (the target is 2016 blocks in 2 weeks). Then using simple proportions, it scales the difficulty accordingly.

Because the difficulty is based on the time it took to mine blocks, the difficulty is directly related to the amount of hash rate there is in the entire system. More hash rate means that blocks will be found more quickly, so the difficulty will increase. Less hash rate means blocks will be found more slowly, so the difficulty decreases.