Skip to content

Commit d276fea

Browse files
feat: ✨ add ecos get_appliance_realtime_stats function for direct realtime stats from appliance
update docstring in Orchestrator get_realtime_stats function to correspond to appliance equivalent function
1 parent 10506bc commit d276fea

3 files changed

Lines changed: 192 additions & 52 deletions

File tree

pyedgeconnect/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ def __init__(
14201420
)
14211421
from .ecos._sp_portal import register_sp_portal, register_sp_portal_status
14221422
from .ecos._statistics import (
1423+
get_appliance_realtime_stats,
14231424
get_appliance_stats_minute_file,
14241425
get_appliance_stats_minute_range,
14251426
)

pyedgeconnect/ecos/_statistics.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,117 @@ def get_appliance_stats_minute_file(
8484
f"/stats/minuteStats/{file}",
8585
return_type="full_response",
8686
)
87+
88+
89+
def get_appliance_realtime_stats(
90+
self,
91+
stat_type: str,
92+
stat_name: str,
93+
stat_filter: str = "",
94+
) -> dict:
95+
"""Get real time per second statistics. This endpoint returns
96+
varying responses based on the parameters specified in the body.
97+
98+
.. list-table::
99+
:header-rows: 1
100+
101+
* - Swagger Section
102+
- Method
103+
- Endpoint
104+
* - statistics
105+
- POST
106+
- /stats/realtimeStats
107+
108+
.. note::
109+
110+
Appliances store per second statistics for only 3 seconds. You
111+
must poll at a frequency faster than 3 seconds to not have gaps
112+
in the results when trying to collect continious values.
113+
114+
115+
* For **Tunnel stats**: Set ``stat_type`` to ``tunnel`` and set
116+
``stat_name`` to one of the tunnel names or ``pass-through`` or
117+
``pass-through-unshaped``. ``stat_filter`` is not used for tunnel
118+
statistics.
119+
120+
* For **TrafficType stats**: Set the ``stat_type`` to
121+
``trafficType`` to retrieve two aggregate real-time stats:
122+
optimized and all-traffic. For optimized, set ``stat_name`` to
123+
``0`` and for all-traffic, set ``stat_name`` to ``3``.
124+
``stat_filter`` is not used.
125+
126+
* For **Application stats**: Set ``stat_type`` to ``app``. Set
127+
``stat_name`` to application name. ``stat_filter`` is required.
128+
Accepted values are ``0`` for optimized traffic, ``1`` for
129+
passthrough shaped, ``2`` for passthrough unshaped, and ``3`` for
130+
all traffic.
131+
132+
* For **DSCP stats**: Set ``stat_type`` to ``dscp``, set
133+
``stat_name`` to one of DSCP values from ``0`` to ``63``.
134+
``stat_filter`` is required. Accepted values are ``0`` for
135+
optimized traffic, ``1`` for passthrough shaped, ``2`` for
136+
passthrough unshaped, and ``3`` for all traffic.
137+
138+
* For **Traffic Class Stats**: set ``stat_type`` to 'trafficClass',
139+
set ``stat_name`` to one of traffic classes from ``0`` to ``9``.
140+
``stat_filter`` is required. Accepted values are ``0`` for
141+
optimized traffic, ``1`` for passthrough shaped, ``2`` for
142+
passthrough unshaped, and ``3`` for all traffic.
143+
144+
* For **Flow stats**: set type to ``flow``, name to ``0`` for TCP
145+
accelerated, ``1`` for TCP unaccelerated and ``2`` for non-TCP
146+
flows. ``3`` for all traffic. ``stat_filter`` is required.
147+
Accepted values are ``0`` for optimized traffic, ``1`` for
148+
passthrough shaped, ``2`` for passthrough unshaped, and ``3``
149+
for all traffic.
150+
151+
* For **Shaper stats**: Set ``stat_type`` to ``shaper``. Set
152+
``stat_name`` to one of traffic classes from ``0`` to ``9``.
153+
``stat_filter`` to traffic direction, ``0`` for Outbound and ``1``
154+
for Inbound.
155+
156+
* For **Drops stats**: Set ``stat_type`` to ``drops``. Set
157+
``stat_name`` to empty string
158+
159+
* For **Interface stats**: set type to ``interface``, and
160+
``stat_name`` to interface name. Use ``stat_filter`` to filter
161+
traffic type, ``0`` for optimized traffic, ``1`` for
162+
passthrough shaped, ``2`` for passthrough unshaped, and ``3``
163+
for all traffic.
164+
165+
:param stat_type: Category/Type of statistics to retrieve, accepted
166+
values included ``tunnel``, ``trafficType``, ``app``, ``flow``,
167+
``dscp``, ``trafficClass``, ``shaper``, ``drops``, and
168+
``interface``
169+
:type stat_type: str
170+
:param stat_name: Name of value to retrieve, accepted values
171+
dependent on value of param ``stat_type``
172+
:type stat_name: str
173+
:param stat_filter: Required for certain stat types, accepted values
174+
are ``0``, ``1``, ``2``, ``3``, function of which is dependent
175+
on value of ``stat_type`` and ``stat_name``, defaults to ""
176+
:type stat_filter: str, optional
177+
:return: Dictionary of realtime stats for specified parameters \n
178+
* keyword **<name_of_stat>** (`list`): 3 second stat object,
179+
number of keys varies based on stat type queried \n
180+
* [`list`]: First second list of stat timestamp and value \n
181+
* [0] (`int`): Epoch timestamp in microseconds
182+
* [1] (`int`): Stat value, unit dependent on stat type
183+
* [`list`]: Second second list of stat timestamp and value \n
184+
* [0] (`int`): Epoch timestamp in microseconds
185+
* [1] (`int`): Stat value, unit dependent on stat type
186+
* [`list`]: Third second list of stat timestamp and value \n
187+
* [0] (`int`): Epoch timestamp in microseconds
188+
* [1] (`int`): Stat value, unit dependent on stat type
189+
:rtype: dict
190+
"""
191+
data = {
192+
"type": stat_type,
193+
"name": stat_name,
194+
"filter": stat_filter,
195+
}
196+
197+
return self._post(
198+
"/stats/realtimeStats",
199+
data=data,
200+
)

pyedgeconnect/orch/_realtime_stats.py

Lines changed: 77 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_realtime_stats(
99
ne_pk: str,
1010
stat_type: str,
1111
stat_name: str,
12-
stat_filter: str,
12+
stat_filter: str = "",
1313
) -> dict:
1414
"""Get real time statistics from appliance based on query parameters
1515
@@ -23,65 +23,90 @@ def get_realtime_stats(
2323
- POST
2424
- /realtimeStats/{nePk}
2525
26-
* Tunnel stats: Set ``stat_type`` to ``tunnel``. Set ``stat_name``
27-
to one of the tunnel names or ``pass-through`` or
28-
``pass-through-unshaped``. ``stat_filter`` is not used for
29-
tunnel statistics.
30-
* TrafficType stats: Set the ``stat_type`` to ``trafficType`` to
31-
retrieve two aggregate real-time stats: optimized, all-traffic.
32-
For optimized, set ``stat_name`` to ``0`` and for all-traffic,
33-
set ``stat_name`` to ``3``. ``stat_filter`` is not used.
34-
* Application stats: Set ``stat_type`` to ``app``. Set ``stat_name``
35-
to application name. ``stat_filter`` is required.
36-
* DSCP stats: Set ``stat_type`` to ``dscp``, set name to one of DSCP
37-
values from ``0`` to ``63``. ``stat_filter`` is required.
38-
Possible ``stat_filter`` values are ``0`` for optimized_traffic,
39-
``1`` for pass_through_shaped, ``2`` for pass_through_unshaped,
40-
and ``3`` for all_traffic
41-
* MOS stats: Set ``stat_name`` to a tunnel id and set ``stat_type``
42-
to ``tunnel``
43-
* Traffic Class Stats: set ``stat_type`` to ``trafficClass``, set
44-
``stat_name`` to one of traffic classes from ``0`` to ``9``.
45-
``stat_filter`` is required.
46-
* Flow stats: set ``stat_type`` to ``flow``, ``stat_name`` to ``0``
47-
for TCP accelerated, ``1`` for TCP unaccelerated, and ``2`` for
48-
non-TCP flows. ``stat_filter`` is required. Accepted values for
49-
``stat_filter`` values are ``0`` for optimized_traffic, ``1`` for
50-
pass_through_shaped, ``2`` for pass_through_unshaped, and ``3``
51-
for all_traffic
52-
* Shaper stats: Set ``stat_type`` to ``shaper``. Set ``stat_name``
53-
to one of traffic classes from ``0`` to ``9``. Use ``stat_filter``
54-
to specify traffic direction: ``0`` for Outbound and ``1`` for
55-
Inbound)
56-
* Drops stats: Set ``stat_type`` to ``drops``. Set ``stat_name`` to
57-
empty string.
58-
* Interface stats: Set ``stat_type`` to ``interface``. Set
59-
``stat_name`` to interface name. Use ``stat_filter`` to filter
60-
traffic type: ``0`` for optimized_traffic, ``1`` for
61-
pass_through_shaped, ``2`` for pass_through_unshaped, and ``3``
62-
for all_traffic
6326
6427
.. note::
65-
Appliances store per second statistics for three seconds. You must
66-
poll at a frequency faster than three seconds to make sure to not
67-
have gaps in the results. The result format for all statistics
68-
looks like: ``{'nameofstat': [time, value], [time,value],...}``
69-
where you get statistics for last three seconds.
28+
29+
Appliances store per second statistics for only 3 seconds. You
30+
must poll at a frequency faster than 3 seconds to not have gaps
31+
in the results when trying to collect continious values.
32+
33+
34+
* For **Tunnel stats**: Set ``stat_type`` to ``tunnel`` and set
35+
``stat_name`` to one of the tunnel names or ``pass-through`` or
36+
``pass-through-unshaped``. ``stat_filter`` is not used for tunnel
37+
statistics.
38+
39+
* For **TrafficType stats**: Set the ``stat_type`` to
40+
``trafficType`` to retrieve two aggregate real-time stats:
41+
optimized and all-traffic. For optimized, set ``stat_name`` to
42+
``0`` and for all-traffic, set ``stat_name`` to ``3``.
43+
``stat_filter`` is not used.
44+
45+
* For **Application stats**: Set ``stat_type`` to ``app``. Set
46+
``stat_name`` to application name. ``stat_filter`` is required.
47+
Accepted values are ``0`` for optimized traffic, ``1`` for
48+
passthrough shaped, ``2`` for passthrough unshaped, and ``3`` for
49+
all traffic.
50+
51+
* For **DSCP stats**: Set ``stat_type`` to ``dscp``, set
52+
``stat_name`` to one of DSCP values from ``0`` to ``63``.
53+
``stat_filter`` is required. Accepted values are ``0`` for
54+
optimized traffic, ``1`` for passthrough shaped, ``2`` for
55+
passthrough unshaped, and ``3`` for all traffic.
56+
57+
* For **Traffic Class Stats**: set ``stat_type`` to 'trafficClass',
58+
set ``stat_name`` to one of traffic classes from ``0`` to ``9``.
59+
``stat_filter`` is required. Accepted values are ``0`` for
60+
optimized traffic, ``1`` for passthrough shaped, ``2`` for
61+
passthrough unshaped, and ``3`` for all traffic.
62+
63+
* For **Flow stats**: set type to ``flow``, name to ``0`` for TCP
64+
accelerated, ``1`` for TCP unaccelerated and ``2`` for non-TCP
65+
flows. ``3`` for all traffic. ``stat_filter`` is required.
66+
Accepted values are ``0`` for optimized traffic, ``1`` for
67+
passthrough shaped, ``2`` for passthrough unshaped, and ``3``
68+
for all traffic.
69+
70+
* For **Shaper stats**: Set ``stat_type`` to ``shaper``. Set
71+
``stat_name`` to one of traffic classes from ``0`` to ``9``.
72+
``stat_filter`` to traffic direction, ``0`` for Outbound and ``1``
73+
for Inbound.
74+
75+
* For **Drops stats**: Set ``stat_type`` to ``drops``. Set
76+
``stat_name`` to empty string
77+
78+
* For **Interface stats**: set type to ``interface``, and
79+
``stat_name`` to interface name. Use ``stat_filter`` to filter
80+
traffic type, ``0`` for optimized traffic, ``1`` for
81+
passthrough shaped, ``2`` for passthrough unshaped, and ``3``
82+
for all traffic.
7083
7184
:param ne_pk: Network Primary Key (nePk) of appliance, e.g. ``3.NE``
7285
:type ne_pk: str
73-
:param stat_type: Type of statistic to retreive, accepted values
74-
include ``tunnel``, ``trafficType``, ``app``, ``flow``,
75-
``dscp``, ``trafficClass``, ``shaper``, and ``drops``
86+
:param stat_type: Category/Type of statistics to retrieve, accepted
87+
values included ``tunnel``, ``trafficType``, ``app``, ``flow``,
88+
``dscp``, ``trafficClass``, ``shaper``, ``drops``, and
89+
``interface``
7690
:type stat_type: str
7791
:param stat_name: Name of value to retrieve, accepted values
78-
dependent on value of param ``type``
92+
dependent on value of param ``stat_type``
7993
:type stat_name: str
80-
:param stat_filter: Filter results, accepted values are ``0``,
81-
``1``, ``2``, ``3``, functions dependent on value of param
82-
``type`` and ``name``
83-
:type stat_filter: str
84-
:return: Returns nested dictionary
94+
:param stat_filter: Required for certain stat types, accepted values
95+
are ``0``, ``1``, ``2``, ``3``, function of which is dependent
96+
on value of ``stat_type`` and ``stat_name``, defaults to ""
97+
:type stat_filter: str, optional
98+
:return: Dictionary of realtime stats for specified parameters \n
99+
* keyword **<name_of_stat>** (`list`): 3 second stat object,
100+
number of keys varies based on stat type queried \n
101+
* [`list`]: First second list of stat timestamp and value \n
102+
* [0] (`int`): Epoch timestamp in microseconds
103+
* [1] (`int`): Stat value, unit dependent on stat type
104+
* [`list`]: Second second list of stat timestamp and value \n
105+
* [0] (`int`): Epoch timestamp in microseconds
106+
* [1] (`int`): Stat value, unit dependent on stat type
107+
* [`list`]: Third second list of stat timestamp and value \n
108+
* [0] (`int`): Epoch timestamp in microseconds
109+
* [1] (`int`): Stat value, unit dependent on stat type
85110
:rtype: dict
86111
"""
87112
data = {"type": stat_type, "name": stat_name, "filter": stat_filter}

0 commit comments

Comments
 (0)