Example:
Lets take a riff. For example:
D------------------------------------------5--7~
A---7--8--7---7---7---7--8--7--5--7---------
E-5---------8---7---5--------------------------
The notes are: A, B, C, D, E, F and G.
Lets search those notes in a scale identifier, such as http://www.scales-chords.com/scalefinder.php
The possible scales are C major (and its modes). The riff starts and ends with the note A, and the note A is sustained at the end (vibrato), so the riff is probably in A minor natural (=A aeolian).
Now we have to see what chords belong to A minor (A,B,C,D,E,F,G):
I(min)= Am, II(dim)= Bdim, III(maj)= C, IV(min)= Dm, V(min)= Em, VI(maj)= F, VII(maj)= G
If you are writing rock riffs, you should consider using power chords instead. All of those, except for the diminished, can be translated to power chords. The diminished cannot translate to a power chord because its 5th degree is half a step down. But if you're writing metal, which is what the riff sounds like, you can use an evil little chord called a diminished power chord, a tritone or a "chord of the devil".
You get a diminished power chord by taking a powerchord and moving the 2nd note a fret to the left:
A-8
E-7