[Docs] Adding ThresholdS documentation

This commit is contained in:
DanB
2020-02-21 17:13:45 +01:00
parent a242724377
commit 0a3da32c6b
9 changed files with 176 additions and 8 deletions

View File

@@ -43,6 +43,7 @@ nested_fields
process_runs
Limit the number of loops when processing an Event. The event loop is however clever enough to stop when the same processing occurs or no more additional profiles are matching, so higher numbers are ignored if not needed.
.. _AttributeProfile:
AttributeProfile
^^^^^^^^^^^^^^^^
@@ -71,9 +72,11 @@ Weight
Used in case of multiple profiles matching an event. The higher, the better (0 has lowest possible priority).
Attributes
List of [Attribute](#attribute) objects part of this profile
List of :ref:`Attribute` objects part of this profile.
.. _Attribute:
Attribute
^^^^^^^^^

View File

@@ -1,3 +1,5 @@
.. _CDRs:
CDRs
====

View File

@@ -11,6 +11,7 @@ In order to be used in event processing, a Filter profile will be attached insid
A subsystem can use a *Filter* via *FilterProfile* or in-line (ad-hock in the same place where subsystem profile is defined).
Filter profile
--------------

View File

@@ -1,3 +1,5 @@
.. _ResourceS:
ResourceS
=========

View File

@@ -1,3 +1,5 @@
.. _SessionS:
SessionS
========

View File

@@ -107,7 +107,7 @@ Following metrics are implemented:
\*asr
`Answer-seizure ratio <https://en.wikipedia.org/wiki/Answer-seizure_ratio>`_. Relies on *AnswerTime* field in the *Event*.
\*acd
`Average call duration <https://en.wikipedia.org/wiki/Average_call_duration>`. Uses *AnswerTime* and *Usage* fields in the *Event*.
`Average call duration <https://en.wikipedia.org/wiki/Average_call_duration>`_. Uses *AnswerTime* and *Usage* fields in the *Event*.
\*tcd
Total call duration. Uses *Usage* out of *Event*.

View File

@@ -1,3 +1,11 @@
.. _Asterisk: https://www.asterisk.org/
.. _FreeSWITCH: https://freeswitch.com/
.. _Kamailio: https://www.kamailio.org/w/
.. _OpenSIPS: https://opensips.org/
.. _Suppliers:
SupplierS
=========
@@ -5,18 +13,19 @@ SupplierS
**SupplierS** is a standalone subsystem within **CGRateS** responsible to compute a list of suppliers which can be used for a specific event received to process. It is accessed via :ref:`CGRateS RPC APIs<remote-management>`.
As most of the other subsystems, it is performance oriented, stored inside *DataDB* but cached inside the *cgr-engine* process.
Caching can be done dynamically/on-demand or at start-time/precached and it is configurable within *cache* section in the .json configuration file.
Caching can be done dynamically/on-demand or at start-time/precached and it is configurable within *cache* section in the :ref:`JSON configuration <configuration>`.
Processing logic
----------------
When a new *Event* is received, **SupplierS** will pass it to :ref:`FilterS` in order to find all *SupplierProfiles* matching the *Event*.
When a new *Event* is received, **SupplierS** will pass it to :ref:`FilterS` in order to find all :ref:`SupplierProfiles<SupplierProfile>` matching the *Event*.
As a result of the selection process we will get a single *SupplierProfile* matching the *Event* is active at the *EventTime* and has a higher priority than the other matching *SupplierProfiles*.
As a result of the selection process we will get a single :ref:`SupplierProfile` matching the *Event*, is active at the *EventTime* and has a higher priority than the other matching :ref:`SupplierProfiles<SupplierProfile>`.
Depending on the *Strategy* defined in the *SupplierProfile*, further steps will be taken (ie: query cost, stats, ordering) for each of the individual *SupplierIDs* defined within the *SupplierProfile*.
APIs logic
----------
@@ -73,6 +82,8 @@ default_ratio
Default ratio used in case of *load strategy
.. _SupplierProfile:
SupplierProfile
^^^^^^^^^^^^^^^
@@ -131,9 +142,11 @@ Weight
Priority in case of multiple *SupplierProfiles* matching an *Event*. Higher *Weight* will have more priority.
Suppliers
List of *Supplier* objects which are part of this *SupplierProfile*
List of :ref:`Supplier` objects which are part of this *SupplierProfile*
.. _Supplier:
Supplier
^^^^^^^^

View File

@@ -1,5 +1,150 @@
.. _ThresholdS:
ThresholdS
==========
TBD
**ThresholdS** is a standalone subsystem within **CGRateS** responsible to execute a list of *Actions* for a specific event received to process. It is accessed via :ref:`CGRateS RPC APIs<remote-management>`.
As most of the other subsystems, it is performance oriented, stored inside *DataDB* but cached inside the *cgr-engine* process.
Caching can be done dynamically/on-demand or at start-time/precached and it is configurable within *cache* section in the :ref:`JSON configuration <configuration>`.
Processing logic
----------------
When a new *Event* is received, **ThresholdS** will pass it to :ref:`FilterS` in order to find all *SupplierProfiles* matching the *Event*.
As a result of the selection process we will get a list of :ref:`Thresholds<Threshold>` matching the *Event* and are active at the *EventTime*.
APIs logic
----------
GetThresholdIDs
^^^^^^^^^^^^^^^
Returns a list of *ThresholdIDs* configured on a *Tenant*.
GetThresholdsForEvent
^^^^^^^^^^^^^^^^^^^^^
Returns a list of :ref:`Thresholds<Threshold>` matching the event.
GetThreshold
^^^^^^^^^^^^
Returns a specific :ref:`Threshold` based on it's *Tenant* and *ID*.
ProcessEvent
^^^^^^^^^^^^
Technically processes the *Event*, executing all the *Actions* configured within all the matching :ref:`Thresholds<Threshold>`.
Parameters
----------
ThresholdS
^^^^^^^^^^
**ThresholdS** is the **CGRateS** component responsible for handling the :ref:`Thresholds<Threshold>`.
It is configured within **thresholds** section from :ref:`JSON configuration <configuration>` via the following parameters:
enabled
Will enable starting of the service. Possible values: <true|false>.
store_interval
Time interval for backing up the thresholds into *DataDB*.
indexed_selects
Enable profile matching exclusively on indexes. If not enabled, the :ref:`Thresholds<Threshold>` are checked one by one which for a larger number can slow down the processing time. Possible values: <true|false>.
string_indexed_fields
Query string indexes based only on these fields for faster processing. If commented out, each field from the event will be checked against indexes. If defined as empty list, no fields will be checked.
prefix_indexed_fields
Query prefix indexes based only on these fields for faster processing. If defined as empty list, no fields will be checked.
nested_fields
Applied when all event fields are checked against indexes, and decides whether subfields are also checked.
.. _ThresholdProfile:
ThresholdProfile
^^^^^^^^^^^^^^^^
Contains the configuration to create a :ref:`Threshold`. Following fields can be defined:
Tenant
The tenant on the platform (one can see the tenant as partition ID).
ID
The profile identificator.
FilterIDs
List of *FilterProfileIDs* which should match in order to consider the profile matching the event.
ActivationInterval
The time interval when this profile becomes active. If undefined, the profile is always active. Other options are start time, end time or both.
MaxHits
Limit number of hits for this threshold. Once this is reached, the threshold is considered disabled.
MinHits
Only execute actions after this number is reached.
MinSleep
Disable the threshold for consecutive hits for the duration of *MinSleep*.
Blocker
Do not process thresholds who's *Weight* is lower.
Weight
Sorts the execution of multiple thresholds matching the event. The higher the *Weight* is, the higher the priority to be executed.
ActionIDs
List of *Actions* to execute for this threshold.
Async
If true, do not wait for actions to complete.
.. _Threshold:
Threshold
^^^^^^^^^
Represents one threshold, instantiated from a :ref:`ThresholdProfile`. It contains the following fields:
Tenant
The tenant on the platform (one can see the tenant as partition ID).
ID
The threshold identificator.
Hits
Number of hits so far.
Snooze
If initialized, it will contain the time when this threshold will become active again.
Use cases
---------
* Improve network transparency and automatic reaction to outages monitoring stats produced by :ref:`StatS`.
* Monitor active channels used by a supplier/customer/reseller/destination/weekends/etc out of :ref:`ResourceS` events.
* Monitor balance consumption out of *Account* events.
* Monitor calls out of :ref:`CDRs` events or :ref:`SessionS`.
* Fraud detection with automatic mitigation based of all events mentioned above.

View File

@@ -385,7 +385,7 @@ func (tS *ThresholdService) V1GetThresholdsForEvent(args *ArgsProcessEvent, repl
return
}
// V1GetQueueIDs returns list of queueIDs registered for a tenant
// V1GetQueueIDs returns list of thresholdIDs configured for a tenant
func (tS *ThresholdService) V1GetThresholdIDs(tenant string, tIDs *[]string) (err error) {
prfx := utils.ThresholdPrefix + tenant + ":"
keys, err := tS.dm.DataDB().GetKeysForPrefix(prfx)