For counting the calls in Asterisk , you can use the Group() dialplan function from Asterisk dialplan.
To add a call to the group function, use this dialplan application
Set(GROUP()=call_count)
To view the call count, use following dialplan application
Noop(${GROUP_COUNT(call_count)})
Below dialplan example shows you how to use the group function to limit the total call count to 10 in your asterisk box
exten => _X.,1,Set(GROUP()=call_count)
exten => _X.,n, Noop(Total number of calls : ${GROUP_COUNT(call_count)})
exten => _X.,n,GotoIf($[${GROUP_COUNT(call_count)} < 11]?continue:hang)
exten => _X.,n(continue),Noop()
Add your dialplan here to handle calls when the call count is below 11
exten => _X.,n(hang),Hangup