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,26 @@ 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
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.
30
14
31
-
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
## Step 2: Compile and deploy `query_stats` canister
19
+
## Build and deploy from the command-line
39
20
40
-
```sh
41
-
dfx deploy
42
-
```
21
+
### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)
43
22
44
-
##Step 3: Call the canister's load function a few times to generate query traffic
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/)
45
24
46
-
```
47
-
dfx canister call query_stats load
48
-
```
25
+
### 3. Navigate into the project's directory.
49
26
50
-
##Step 4: Observe the following result
27
+
### 4. Deploy the project to your local environment:
51
28
52
29
```
53
-
dfx canister call query_stats get_query_stats
30
+
dfx start --background --clean && dfx deploy
54
31
```
55
32
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
65
-
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.
68
-
69
-
On mainnet, the aggregation epoch is 10 minutes, thus it will up to half an hour before the values appear on mainnet.
70
-
71
-
### Possible next steps
72
-
73
-
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.
75
-
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.
77
-
78
-
## Resources
79
-
80
-
-[ic-cdk](https://docs.rs/ic-cdk/latest/ic_cdk/).
81
-
82
-
## Security considerations and security best practices
33
+
## Security considerations and best practices
83
34
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.
35
+
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