Optimal monitoring and mitigation of systemic risk in lending networks