If I understand it correctly you want to detect rising sewage in your outlet pipe due to a blocked communal sewage pipe (or extreme floods that stresses the systems capacity )
The rises is vertical and 4 inch ? You have only access through the small threaded plug?
that means that given normal household sewage flows, the pipe will never fill up with outflow (you need thousands of gallons/min flow for that)
But given the fouling properties (no pun intended) of household sewage I would not consideder optical or sonic sensors, as they will be dirty after some service time and needs repetitive cleaning and this might affect their capacity to detect.
I see two options for sensing level in the riser pipe
1) Dip tube with air bubble through it (my recommendtation)
http://automationwiki.com/index.php?title=Bubbler_Level_MeasurementThis is very common in the industry when you have fouling liquids. Use any normal aquarium air pump that can push downt to say 50 cm depth or so, and a low pressure sensor. Use a thin stainless tube inserted to desired early warning depth. You might have to rinse it once in a while , but any fouling will cause false alarm
Can be built with easily obtainable items like aquarium tubing, pvc/stainless steel pipe , air pump , simple pressure sensors from you local electronics etc etc.
Protective tube surrounding it would be a good idea, also not inserting the bubble tube at the very bottom, but putting it some distance from normal liquid level in the riser pipe reduces fouling.
2) A mechanical level switch inserted through the thread. Suggestion is mechanical floater with vertical action, not a horisontal lever arm.
Or a conductive sensor, two dip sensors. But to prevent fouling I recommend using a protective tube surrounding it, with a closed top to prevent fouling entering from above. It is less sensitive to fouling meaning cleaning is less frequent. If possible place it oppostie side of the inlet to the riser pipe.
More meccano work I presume.
regards
Rickard ( chemical engineer with 15 years of experience and frequent electronic hobbyist...)