Despite the Dragons' Rhys Jones twice missing penalties, the Welsh region charged down Matawalu and Ross Wardle was able to put his team in front with 10 minutes left.
Finn Russell then had the chance to put Glasgow back on track with just six minutes to go but his penalty was short and the Dragons were able to hang on.
That was the first victory in four for the hosts and it left Townsend to rue opportunities missed by his side who slip to fifth, outside the RaboDirect PRO12 play-off places.
"The first thing in rugby you have to do to win matches is have outstanding defence and the second thing is to make sure you don't beat yourself and put yourself under pressure to give the opposition easy opportunities," Townsend told the club website.
"Some of the rugby we played when we had the ball was good, but I would have liked to have seen more from them when we didn't have the ball.
"I thought Niko played well. He was at the heart of all our positive play and although he got the kick charged down for the third try, we could have organised our positioning much better so we didn't leave him on his own with four Dragon players on top of him."
And Townsend admitted that it would take a much-improved performance to beat reigning champions Leinster on Saturday.
"We pride ourselves on having a really strong defence but at times it wasn't good enough," he added.
"The Dragons are very good in the contact area and although we defended better at the beginning of the second-half, it was loose play at the end which cost us the win."
Follow us on Facebook, join the conversation onTwitter,sign up to our YouTube channel for extensive match highlights and sign up to our newsletter for regular updates on the RaboDirect PRO12