Why is David blessing Hashem?
Rashi: David had Nevu'ah that Keneses Yisrael will say so. Also I say so now, for He counseled me to chose life and go in His ways.
Radak: Refer to 16:5:2:3.
Malbim: Even though man has choice, Hashem does not abandon man so that the Yetzer ha'Ra and desire can make him stumble. Hashem stands by me like a counselor, lest I be drawn after the Yetzer ha'Ra's counsel. The ways of the Torah are counsel of Hashem, how to beware of the net and traps of lust.
What is the meaning of "Af Leilos Yisrenu Chilyosai"?
Rashi: [My kidneys chastise me] to fear Hashem and love Him.
Rashi citing Shocher Tov: This refers to Avraham. He learned Torah by himself, before it was given 1 .
Radak: The start was from Hashem; He counseled me and helped me to choose this portion for myself, and I myself, my kidneys chastise me not to abandon this path, and persist in it with all my strength. At night, a man is idle from worldly engagements, and his heart is free [to think]. The kidneys counsel and the heart understands, like it says in Brachos (61a).
Malbim: Hashem also planted in man's Nefesh the sense of Musar, to the point that his Nefesh itself chastises him from going in the evil way.
Rashi: However, we must resolve verses as they are written. (The Midrash does not fit the verses.)