You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example shows to work with the query stats feature.
4
-
5
-
## Architecture
6
-
7
-
The example consists of a single canister called `query_stats`.
8
-
It exports the following candid interface:
3
+
This example shows to work with the query stats feature. It consists of a single canister called `query_stats`. It exports the following candid interface:
9
4
10
5
```candid
11
6
service : {
@@ -15,70 +10,22 @@ service : {
15
10
16
11
```
17
12
18
-
The `load` function just returns a timestamp.
19
-
It just exists such that there is a query endpoint to call.
20
-
The `get_query_stats` is the function that queries the status endpoint and returns the collected query statistics.
21
-
22
-
## Prerequisites
23
-
24
-
This example requires an installation of:
25
-
-[x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
26
-
-[x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
27
-
28
-
29
-
## Step 1: Setup project environment
30
-
31
-
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
32
-
33
-
```sh
34
-
cd examples/rust/query_stats
35
-
dfx start --clean
36
-
```
37
-
38
-
## Step 2: Compile and deploy `query_stats` canister
39
-
40
-
```sh
41
-
dfx deploy
42
-
```
43
-
44
-
## Step 3: Call the canister's load function a few times to generate query traffic
45
-
46
-
```
47
-
dfx canister call query_stats load
48
-
```
49
-
50
-
## Step 4: Observe the following result
51
-
52
-
```
53
-
dfx canister call query_stats get_query_stats
54
-
```
55
-
56
-
## Step 5: After a while, the values should become populated
57
-
58
-
```
59
-
"Number of calls: 19 - Number of instructions 414_083 - Request payload bytes: 114 - Response payload bytes: 270"
60
-
```
61
-
62
-
Alternatively, you can use the candid interface to make those calls.
63
-
64
-
### Troubleshooting
13
+
The `load` function just returns a timestamp. It just exists such that there is a query endpoint to call. The method `get_query_stats` queries the status endpoint and returns the collected query statistics.
65
14
66
-
On the local `dfx` replica, the aggregation epoch is set to 60 seconds.
67
-
So calling the load function a couple of times should result in values showing up a couple minutes later.
15
+
## Deploying from ICP Ninja
68
16
69
-
On mainnet, the aggregation epoch is 10 minutes, thus it will up to half an hour before the values appear on mainnet.
Query statistics are simple counters that increase.
74
-
Their raw values are not that useful, you may want to implement some sort of metering system.
21
+
### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)
75
22
76
-
One way to go from here is to get the query stats in a regular interval using a timer and compare to the last values, calculating rates.
23
+
### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/)
77
24
78
-
##Resources
25
+
### 3. Navigate into the project's directory.
79
26
80
-
-[ic-cdk](https://docs.rs/ic-cdk/latest/ic_cdk/).
27
+
### 4. Run `dfx start --background --clean && dfx deploy` to deploy the project to your local environment.
81
28
82
-
## Security considerations and security best practices
29
+
## Security considerations and best practices
83
30
84
-
If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on the Internet Computer. This example may not implement all the best practices.
31
+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.
0 commit comments