How to get queue size periodically to calculate any statistical parameter like average,mean,median,variance?

I do not understand the phrase “When we have 2 links connected to a link”. If you can clarify what you mean by that phrase, I might understand the first question you tried to ask.

In your second question, you use the phrase “should this differentiation be done”. I am not sure what you mean by that, either. Are you wanting to compare the depths of queues for two different queues in a single switch to each other, for some reason? If yes, I am curious what reason you have for wanting to compare the depths of two different queues to each other?

If you do not want to compare the depths of two different queues to each other, then I do not understand the meaning of your last question at all.

In general, yes, the metadata built into v1model only lets you view queue depth information, during egress processing, for a single queue, the one queue that the packet just passed through.

If you want to read queue depths for other queues besides the one that the packet passed through, see my recent answer to another question for ideas where you can maintain the queue depths you want in a P4 register, either in ingress, or in egress, or a separate P4 register in each, if you wish. What is the queue management approach in P4? - #10 by andyfingerhut