Skip to content

Commit

Permalink
Added first bit of Motoko example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dfinity-skaestle committed Feb 27, 2024
1 parent 1438f1d commit 2c25735
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Empty file added motoko/query_stats/README.md
Empty file.
16 changes: 16 additions & 0 deletions motoko/query_stats/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"canisters": {
"query_stats": {
"main": "src/query_stats_backend/main.mo",
"type": "motoko"
}
},
"defaults": {
"build": {
"args": "",
"packtool": ""
}
},
"output_env_file": ".env",
"version": 1
}
28 changes: 28 additions & 0 deletions motoko/query_stats/src/query_stats_backend/main.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Nat "mo:base/Nat";
import Time "mo:base/Time";
import Principal "mo:base/Principal";

actor QueryStats {

let IC = actor "aaaaa-aa" : actor {
canister_status : { canister_id : Principal } -> async {
query_stats : {
num_calls_total : Nat;
num_instructions_total : Nat;
request_payload_bytes_total : Nat;
response_payload_bytes_total : Nat;
};
};
};

public query func load() : async Int {
return Time.now();
};

public func get_current_query_stats_as_string() : async Text {
let stats = await IC.canister_status({
canister_id = Principal.fromActor(QueryStats);
});
return "Number of calls: " # Nat.toText(stats.query_stats.num_calls_total) # " - Number of instructions: " # Nat.toText(stats.query_stats.num_instructions_total) # " - Request payload bytes: " # Nat.toText(stats.query_stats.request_payload_bytes_total) # " - Response payload bytes: " # Nat.toText(stats.query_stats.response_payload_bytes_total);
};
};
1 change: 0 additions & 1 deletion rust/query-stats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const TIMER_PERIOD_IN_SECS: u64 = 5;
const QUERY_STATS_PURGE_AFTER_SECS: u64 = 60 * 60 * 24; // 24h, has to be much larger than query stats epoch
const QUERY_STATS_RATE_FOR_LAST_SECS: u64 = 60 * 60; // 1h, has to be larger than query stats epoch

// Unfortunately, we need to redefine this type, since the members are not public.
#[derive(CandidType, Debug)]
pub struct QueryStatRates {
calls_rate: f32,
Expand Down

0 comments on commit 2c25735

Please sign in to comment.