|
| 1 | +# MIT License |
| 2 | +# (C) Copyright 2022 Hewlett Packard Enterprise Development LP. |
| 3 | +# |
| 4 | +# statistics : Get statistics related information |
| 5 | + |
| 6 | + |
| 7 | +def get_appliance_stats_minute_range(self) -> dict: |
| 8 | + """Get the oldest minute and latest minute for which per minute |
| 9 | + statistics are available |
| 10 | +
|
| 11 | + .. list-table:: |
| 12 | + :header-rows: 1 |
| 13 | +
|
| 14 | + * - Swagger Section |
| 15 | + - Method |
| 16 | + - Endpoint |
| 17 | + * - statistics |
| 18 | + - GET |
| 19 | + - /stats/minuteRange |
| 20 | +
|
| 21 | + Appliance stores statistics for each minute into a file of the |
| 22 | + format: st2-{minute}.tgz. Time is the minute boundary expressed in |
| 23 | + seconds since Jan 1, 1970. This API returns the newest and oldest |
| 24 | + minute timestamps and users can call /stats/minuteStats/:file API to |
| 25 | + retrieve the actual stats. For example: |
| 26 | + GET /stats/minuteStats/st2-1428356220.tgz |
| 27 | +
|
| 28 | + :return: Dictionary of newest and oldest minute stat times \n |
| 29 | + * keyword **newest** (`int`): Epoch seconds timestamp of latest |
| 30 | + available appliance minute data |
| 31 | + * keyword **oldest** (`int`): Epoch seconds timestamp of oldest |
| 32 | + available appliance minute data |
| 33 | + :rtype: dict |
| 34 | + """ |
| 35 | + return self._get("/stats/minuteRange") |
| 36 | + |
| 37 | + |
| 38 | +def get_appliance_stats_minute_file( |
| 39 | + self, |
| 40 | + file: str, |
| 41 | +) -> dict: |
| 42 | + """Get specific minute statistics file |
| 43 | +
|
| 44 | + .. list-table:: |
| 45 | + :header-rows: 1 |
| 46 | +
|
| 47 | + * - Swagger Section |
| 48 | + - Method |
| 49 | + - Endpoint |
| 50 | + * - statistics |
| 51 | + - GET |
| 52 | + - /stats/minuteRange |
| 53 | +
|
| 54 | + Appliance stores statistics for each minute into a file of the |
| 55 | + format: st2-{minute}.tgz. Time is the minute boundary expressed in |
| 56 | + seconds since Jan 1, 1970. For example: |
| 57 | + GET /stats/minuteStats/st2-1428356220.tgz |
| 58 | + Each file is tar and gzip archive of a number of csv files. Each csv |
| 59 | + file has a header which describes the statistics contained in the |
| 60 | + file. |
| 61 | +
|
| 62 | + .. code:: python |
| 63 | + import tarfile |
| 64 | + from pyedgeconnect import EdgeConnect |
| 65 | + ec = EdgeConnect(ec_ip) |
| 66 | + ec.login(ec_user,ec_pw) |
| 67 | + stat = ec.get_appliance_stats_minute_file(st2-1428356220.tgz) |
| 68 | + ec.logout() |
| 69 | + if stat.status_code==200: |
| 70 | + with open("stats.tgz",'wb') as stat_file: |
| 71 | + for chunk in stat: |
| 72 | + stat_file.write(chunk) |
| 73 | + tar = tarfile.open("stats.tgz") |
| 74 | + tar.extractall() |
| 75 | +
|
| 76 | + :param file: Filename of statistics file to download from applinace |
| 77 | + :type file: str |
| 78 | + :return: Download tgz file as part of full response data \n |
| 79 | + :rtype: `requests.Response` object |
| 80 | + """ |
| 81 | + return self._get( |
| 82 | + f"/stats/minuteStats/{file}", |
| 83 | + return_type="full_response", |
| 84 | + ) |
0 commit comments