From d5c5c7ccace07f0631b273277e630d6d21c20386 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 19 Feb 2023 16:19:30 +0100 Subject: [PATCH 1/6] docker compose for grafana --- docker/docker-compose.yml | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docker/docker-compose.yml diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..728f768 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,49 @@ +version: '3' + +services: + influxdb: + image: influxdb + container_name: influxdb + restart: always + ports: + - "8086:8086" + environment: + - INFLUXDB_DB=grafana + - INFLUXDB_ADMIN_USER=admin + - INFLUXDB_ADMIN_PASSWORD=admin + - INFLUXDB_USER=grafana + - INFLUXDB_USER_PASSWORD=grafana + - DOCKER_INFLUXDB_INIT_MODE=setup + - DOCKER_INFLUXDB_INIT_USERNAME=admin + - DOCKER_INFLUXDB_INIT_PASSWORD=adminadminadmin + - DOCKER_INFLUXDB_INIT_ORG=noorg + - DOCKER_INFLUXDB_INIT_BUCKET=grafana + volumes: + - influxdb:/var/lib/influxdb + networks: + - grafana-net + + grafana: + image: grafana/grafana + container_name: grafana + restart: always + ports: + - "3000:3000" + depends_on: + - influxdb + environment: + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=admin + - GF_AUTH_ANONYMOUS_ENABLED=false + volumes: + - grafana:/var/lib/grafana + networks: + - grafana-net + +volumes: + influxdb: {} + grafana: {} + +networks: + grafana-net: + driver: bridge From e5b04f16d86f7689fc7c081e6007b283cd9c1df1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 19 Feb 2023 16:23:09 +0100 Subject: [PATCH 2/6] metriki core for dropwizard like metrics --- Cargo.lock | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 186 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3c30543..992f16c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,12 +14,46 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "crossbeam-utils" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "dashmap" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +dependencies = [ + "cfg-if", + "hashbrown", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "getrandom" version = "0.2.7" @@ -31,12 +65,34 @@ dependencies = [ "wasi", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hdrhistogram" +version = "7.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8" +dependencies = [ + "byteorder", + "num-traits", +] + [[package]] name = "itoa" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.135" @@ -49,6 +105,28 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "metriki-core" +version = "1.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da8e786efae612db7a2c6f61d0675ea5077e344f91dd1ebc0d9bf397ba815f4d" +dependencies = [ + "crossbeam-utils", + "dashmap", + "hdrhistogram", + "lazy_static", +] + [[package]] name = "num-format" version = "0.4.3" @@ -69,6 +147,25 @@ dependencies = [ "libm", ] +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "parking_lot_core" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -115,10 +212,32 @@ dependencies = [ "rand", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + [[package]] name = "system-design-model-rust" version = "0.1.0" dependencies = [ + "metriki-core", "num-format", "rand", "rand_distr", @@ -129,3 +248,69 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" diff --git a/Cargo.toml b/Cargo.toml index e3a2a91..3afa28e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" rand = "0.8.5" rand_distr = "0.4.3" num-format = "0.4.3" +metriki-core = "1.7.4" From f1f545fa3d52a73062f30e1bea3a2167fd8b5b26 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 19 Feb 2023 17:33:07 +0100 Subject: [PATCH 3/6] worldmember.add requires name. counters and gauges require name to be set before use. --- Cargo.lock | 908 ++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 + src/main.rs | 13 +- src/objects.rs | 12 +- src/systems.rs | 115 ++++--- src/traits.rs | 2 +- src/utils.rs | 10 +- 7 files changed, 996 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 992f16c..6208ac6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + [[package]] name = "arrayvec" version = "0.7.2" @@ -14,24 +23,59 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" + [[package]] name = "byteorder" version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "num-integer", + "num-traits", + "serde", +] + [[package]] name = "crossbeam-utils" version = "0.8.14" @@ -41,6 +85,41 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "darling" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "dashmap" version = "5.4.0" @@ -54,6 +133,113 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "derive_builder" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_macro" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" +dependencies = [ + "derive_builder_core", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" + +[[package]] +name = "futures-macro" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" + +[[package]] +name = "futures-task" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" + +[[package]] +name = "futures-util" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +dependencies = [ + "futures-core", + "futures-macro", + "futures-task", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "getrandom" version = "0.2.7" @@ -65,6 +251,25 @@ dependencies = [ "wasi", ] +[[package]] +name = "h2" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -81,12 +286,141 @@ dependencies = [ "num-traits", ] +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +dependencies = [ + "http", + "hyper", + "rustls", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "influxdb" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39023407f0546c3b30607950f8b600c7db4ef7621fbaa0159de733d73e68b23f" +dependencies = [ + "chrono", + "futures-util", + "http", + "lazy_static", + "regex", + "reqwest", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "ipnet" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" + [[package]] name = "itoa" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -115,6 +449,21 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + [[package]] name = "metriki-core" version = "1.7.4" @@ -127,6 +476,24 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.45.0", +] + [[package]] name = "num-format" version = "0.4.3" @@ -137,6 +504,16 @@ dependencies = [ "itoa", ] +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -163,15 +540,51 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "ppv-lite86" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "proc-macro2" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + [[package]] name = "rand" version = "0.8.5" @@ -221,26 +634,378 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "reqwest" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +dependencies = [ + "base64", +] + +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "system-design-model-rust" version = "0.1.0" dependencies = [ + "derive_builder", + "influxdb", "metriki-core", "num-format", "rand", "rand_distr", + "tokio", +] + +[[package]] +name = "thiserror" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.42.0", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", +] + +[[package]] +name = "tokio-util" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + +[[package]] +name = "unicode-bidi" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", ] [[package]] @@ -249,6 +1014,138 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "web-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -314,3 +1211,12 @@ name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml index 3afa28e..844205e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,6 @@ rand = "0.8.5" rand_distr = "0.4.3" num-format = "0.4.3" metriki-core = "1.7.4" +derive_builder = "0.12.0" +influxdb = "0.5.2" +tokio = { version = "1.0", default-features = false, features = ["net", "time"] } diff --git a/src/main.rs b/src/main.rs index e3ed2f8..00e2462 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,10 @@ pub mod utils; pub mod systems; pub mod objects; pub mod traits; +pub mod influxdbreporter; +#[macro_use] +extern crate derive_builder; extern crate rand; use crate::objects::{World, Scheduler}; @@ -17,21 +20,21 @@ fn main() { let mut world = World::new(); let endsink = EndSink::new(); - let endsink_ref = world.add(System::EndSink(endsink)); + let endsink_ref = world.add(System::EndSink(endsink), "endsink".to_string()); let up_to_nano = 1_000_000_000; let server1 = Server::new(Poisson::::new(20_000.0).unwrap(), endsink_ref); - let server1_ref = world.add(System::Server(server1)); + let server1_ref = world.add(System::Server(server1), "server1".to_string()); let server2 = Server::new(Poisson::::new(20_000.0).unwrap(), endsink_ref); - let server2_ref = world.add(System::Server(server2)); + let server2_ref = world.add(System::Server(server2), "server2".to_string()); let load_balancer = LoadBalancer::new(vec![server1_ref, server2_ref]); - let load_balancer_ref = world.add(System::LoadBalancer(load_balancer)); + let load_balancer_ref = world.add(System::LoadBalancer(load_balancer), "load_balancer".to_string()); let ar = ArrivalSource::new( Poisson::::new(1_000.0).unwrap(), load_balancer_ref); - let ar_ref = world.add(System::ArrivalSource(ar)); + let ar_ref = world.add(System::ArrivalSource(ar), "incomming".to_string()); let mut scheduler = Scheduler::new(); diff --git a/src/objects.rs b/src/objects.rs index 5e731c8..e7bdc3f 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -1,6 +1,8 @@ use crate::traits::{SystemRef, StatEmitter, WorldMember, HasQueue}; use crate::systems::System; +use crate::influxdbreporter::InfluxDbReporter; + pub struct World { systems: Vec, } @@ -9,15 +11,15 @@ impl World { pub fn new() -> Self { World { systems: Vec::new()} } - pub fn add(&mut self, system: System) -> SystemRef { + pub fn add(&mut self, system: System, name: String) -> SystemRef { let sr = self.systems.len(); self.systems.push(system); self.with_system(sr, |system, _world|{ - system.add(sr) + system.add(sr, name) }); sr } - pub fn with_system R>(&mut self, system_ref: SystemRef, mut f:F) -> R { + pub fn with_system R>(&mut self, system_ref: SystemRef, f:F) -> R { let (mut s, mut nw) = self.split(system_ref); let r = f(&mut s, &mut nw); std::mem::swap(self, &mut nw); @@ -131,6 +133,10 @@ impl Scheduler { pub fn get_cur_t(&self) -> i64 { self.cur_t } + + fn reportmetrics(&self) { + + } } impl StatEmitter for Scheduler { diff --git a/src/systems.rs b/src/systems.rs index 1a18215..0649251 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -15,20 +15,20 @@ pub struct ArrivalSource { impl ArrivalSource { pub fn new(distribution: Poisson, sink: SystemRef) -> Self { - ArrivalSource { distribution, sink, meter: Meter::new(), sr: None } + ArrivalSource { distribution, sink, meter: Meter::new(), sr: None} } } pub struct EndSink { - ticks: u32, + ticks: Counter, sr: Option, } impl EndSink { pub fn new() -> Self { - EndSink {ticks: 0, sr: None} + EndSink {ticks: Counter::new(), sr: None} } } @@ -42,7 +42,8 @@ impl StatEmitter for ArrivalSource { } impl WorldMember for ArrivalSource { - fn add(&mut self, system_ref: SystemRef) { + fn add(&mut self, system_ref: SystemRef, name: String) { + self.meter.name = Some(name + "_meter"); self.sr = Some(system_ref) } @@ -67,13 +68,14 @@ impl<'a> Emmitter for ArrivalSource { impl StatEmitter for EndSink { fn stats(&self) -> String { - tostring(self.ticks) + format!("processed {}", self.ticks.stats()) } } impl WorldMember for EndSink { - fn add(&mut self, system_ref: SystemRef) { - self.sr = Some(system_ref); + fn add(&mut self, system_ref: SystemRef, name: String) { + self.ticks.name = Some(name + "_ticks"); + self.sr = Some(system_ref) } fn getref(&self) -> Option { @@ -84,47 +86,7 @@ impl WorldMember for EndSink { impl Sink for EndSink { fn next(&mut self, _world: &mut World, _scheduler: &mut Scheduler) { - self.ticks += 1; - } -} - - -impl WorldMember for Server { - fn add(&mut self, system_ref: SystemRef) { - self.sr = Some(system_ref); - } - - fn getref(&self) -> Option { - self.sr - } -} - -impl<'a> Emmitter for Server { - - fn tick(&mut self, world: &mut World, scheduler: &mut Scheduler) -> Option { - let _ob = self.queue.front().cloned(); - self.queue.pop_front(); - world.with_system(self.sink, |system, world|{system.next(world, scheduler)}); - let _nb = self.queue.front(); - self.queue.front().cloned() - } -} - -impl Sink for Server { - fn next(&mut self, _world: &mut World, scheduler: &mut Scheduler) { - let next_time = (self.distribution.sample(&mut rand::thread_rng())) as i64; - if self.queue.is_empty() { - let nt = scheduler.get_cur_t() + next_time; - self.queue.push_back(nt); - - scheduler.schedule_at(nt, self.getref().unwrap()); - } else { - let top = self.queue.back(); - let nt = top.unwrap() + next_time; - self.queue.push_back(nt); - } - self.meter.inc(next_time); - self.counter.inc(); + self.ticks.inc() } } @@ -145,8 +107,9 @@ impl LoadBalancer { } impl WorldMember for LoadBalancer { - fn add(&mut self, system_ref: SystemRef) { - self.sr = Some(system_ref); + fn add(&mut self, system_ref: SystemRef, name: String) { + self.counter.name = Some(name + "_counter"); + self.sr = Some(system_ref) } fn getref(&self) -> Option { @@ -195,6 +158,25 @@ impl Server { } } } + +impl Sink for Server { + fn next(&mut self, _world: &mut World, scheduler: &mut Scheduler) { + let next_time = (self.distribution.sample(&mut rand::thread_rng())) as i64; + if self.queue.is_empty() { + let nt = scheduler.get_cur_t() + next_time; + self.queue.push_back(nt); + + scheduler.schedule_at(nt, self.getref().unwrap()); + } else { + let top = self.queue.back(); + let nt = top.unwrap() + next_time; + self.queue.push_back(nt); + } + self.meter.inc(next_time); + self.counter.inc(); + } +} + impl StatEmitter for Server { fn stats(&self) -> String { format!("meter {} queue {} counter {}", self.meter.stats(), @@ -209,6 +191,29 @@ impl HasQueue for Server { } +impl WorldMember for Server { + fn add(&mut self, system_ref: SystemRef, name: String) { + self.meter.name = Some(name + "_meter"); + self.sr = Some(system_ref); + } + + fn getref(&self) -> Option { + self.sr + } +} + +impl<'a> Emmitter for Server { + + fn tick(&mut self, world: &mut World, scheduler: &mut Scheduler) -> Option { + let _ob = self.queue.front().cloned(); + self.queue.pop_front(); + world.with_system(self.sink, |system, world|{system.next(world, scheduler)}); + let _nb = self.queue.front(); + self.queue.front().cloned() + } +} + + pub enum System { Unset, EndSink(EndSink), @@ -262,13 +267,13 @@ impl StatEmitter for System { } impl WorldMember for System { - fn add(&mut self, system_ref: SystemRef) { + fn add(&mut self, system_ref: SystemRef, name: String) { match self { - System::EndSink(endsink) => endsink.add(system_ref), - System::Server(sv) => sv.add(system_ref), - System::ArrivalSource(arrival_source) => arrival_source.add(system_ref), + System::EndSink(endsink) => endsink.add(system_ref, name), + System::Server(sv) => sv.add(system_ref, name), + System::ArrivalSource(arrival_source) => arrival_source.add(system_ref, name), System::Unset => unimplemented!(), - System::LoadBalancer(lb) => lb.add(system_ref), + System::LoadBalancer(lb) => lb.add(system_ref, name), } } diff --git a/src/traits.rs b/src/traits.rs index f629ec6..46d3f5f 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -5,7 +5,7 @@ use crate::objects::World; pub trait WorldMember { - fn add(&mut self, system_ref: SystemRef); + fn add(&mut self, system_ref: SystemRef, name: String); fn getref(&self) -> Option; } diff --git a/src/utils.rs b/src/utils.rs index 0d443e7..60b0656 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,19 +11,23 @@ pub fn tostringfloat(arg: f64) -> String { format!("{}{}", tostring(f as i64), rst[1..].to_string()) } +use metriki_core::global::global_registry; + pub struct Meter { sm: i64, co: i64, + pub name: Option, } impl Meter { pub fn new() -> Self { - Meter { sm: 0, co: 0 } + Meter { sm: 0, co: 0, name: None } } pub fn inc(&mut self, d: i64) { self.co += 1; self.sm += d; + self.name.as_ref().map(|name|{ global_registry().meter(name.as_str()).mark() }); } pub fn stats(&self) -> String { @@ -37,15 +41,17 @@ impl Meter { pub struct Counter { co: i64, + pub name: Option, } impl Counter { pub fn new() -> Self { - Counter { co: 0 } + Counter { co: 0, name: None } } pub fn inc(&mut self) { self.co += 1; + self.name.as_ref().map(|name|{ global_registry().counter(name.as_str()).inc(1) }); } pub fn stats(&self) -> String { From 45c6e5de2966c24c659f84a7976ca9c51ec670d0 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 20 Feb 2023 21:33:30 +0100 Subject: [PATCH 4/6] influx db reporter. does reporting --- Cargo.lock | 246 +++++++++++++++++++++++++++++++++++++++- Cargo.toml | 4 +- src/influxdbreporter.rs | 196 ++++++++++++++++++++++++++++++++ src/objects.rs | 13 ++- 4 files changed, 455 insertions(+), 4 deletions(-) create mode 100644 src/influxdbreporter.rs diff --git a/Cargo.lock b/Cargo.lock index 6208ac6..4692d07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,6 +76,22 @@ dependencies = [ "serde", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "crossbeam-utils" version = "0.8.14" @@ -173,12 +189,36 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -188,6 +228,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.26" @@ -195,6 +250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -203,6 +259,23 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +[[package]] +name = "futures-executor" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" + [[package]] name = "futures-macro" version = "0.3.26" @@ -232,9 +305,13 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -357,6 +434,19 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -386,8 +476,6 @@ dependencies = [ [[package]] name = "influxdb" version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39023407f0546c3b30607950f8b600c7db4ef7621fbaa0159de733d73e68b23f" dependencies = [ "chrono", "futures-util", @@ -400,6 +488,15 @@ dependencies = [ "thiserror", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "ipnet" version = "2.7.1" @@ -494,6 +591,24 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "num-format" version = "0.4.3" @@ -530,6 +645,51 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "openssl" +version = "0.10.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parking_lot_core" version = "0.9.7" @@ -561,6 +721,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -651,6 +817,15 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + [[package]] name = "reqwest" version = "0.11.14" @@ -667,10 +842,12 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", + "hyper-tls", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -680,6 +857,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "tokio", + "tokio-native-tls", "tokio-rustls", "tower-service", "url", @@ -732,6 +910,15 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -748,6 +935,29 @@ dependencies = [ "untrusted", ] +[[package]] +name = "security-framework" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c4437699b6d34972de58652c68b98cb5b53a4199ab126db8e20ec8ded29a721" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.152" @@ -844,14 +1054,30 @@ name = "system-design-model-rust" version = "0.1.0" dependencies = [ "derive_builder", + "futures", "influxdb", "metriki-core", "num-format", "rand", "rand_distr", + "reqwest", "tokio", ] +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "thiserror" version = "1.0.38" @@ -903,6 +1129,16 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.23.4" @@ -998,6 +1234,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "want" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 844205e..da74bcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,7 @@ rand_distr = "0.4.3" num-format = "0.4.3" metriki-core = "1.7.4" derive_builder = "0.12.0" -influxdb = "0.5.2" +influxdb = {version="0.5.2", features=["reqwest"], path="../../influxdb-rust/influxdb"} tokio = { version = "1.0", default-features = false, features = ["net", "time"] } +futures = "0.3.26" +reqwest= "0.11.14" diff --git a/src/influxdbreporter.rs b/src/influxdbreporter.rs new file mode 100644 index 0000000..3fc0d2d --- /dev/null +++ b/src/influxdbreporter.rs @@ -0,0 +1,196 @@ +use std::collections::HashMap; +use std::convert::TryInto; +use std::sync::Arc; +use std::time::{SystemTime, UNIX_EPOCH}; + +use influxdb::{Client, InfluxDbWriteable, Timestamp, WriteQuery}; + +//use log::warn; +use metriki_core::metrics::*; +use metriki_core::MetricsRegistry; +use tokio::sync::mpsc; +use tokio::time::{Duration}; + +use metriki_core::global::global_registry; +use std::env; + +/* +this is almost a copy of +https://github.com/sunng87/metriki/blob/master/metriki-influxdb-reporter/src/lib.rs +*/ + + +#[derive(Debug)] +pub struct SimulationReachedTimeEvent { + pub time: i64 +} + +#[derive(Debug)] +pub struct InfluxDbReporter { + registry: Arc, + url: String, + interval_secs: u64, + database: String, + username: Option, + password: Option, + auth_token: Option, + measurement_prefix: String, + tags: HashMap, + batch_size: usize, + event_rx: mpsc::Receiver, + last_send_time: i64, + test_start_time: SystemTime, +} + + +impl InfluxDbReporter { + + pub fn new(event_rx: mpsc::Receiver) -> Self { + use std::ops::Sub; + let half_day_secs = 60*12; + InfluxDbReporter { + registry: global_registry(), + url: "http://localhost:8086".to_string(), + interval_secs: 30, + database: "grafana".to_string(), + username: None, + password: None, + auth_token: env::var("AUTH_TOKEN").ok(), + measurement_prefix: "sdm".to_string(), + tags: HashMap::new(), + batch_size: 60, + event_rx: event_rx, + last_send_time: -100, + test_start_time: SystemTime::now().sub(Duration::from_secs(half_day_secs)) + } + } + + fn new_client(&self) -> Client { + let client = Client::new(&self.url, &self.database); + if let (Some(username), Some(password)) = (self.username.as_ref(), self.password.as_ref()) { + client.with_auth(username, password) + } else if let Some(auth_token) = &self.auth_token { + client.with_auth_token(auth_token) + } else { + client + } + } + + pub fn start(mut self) { + let looper = move || { + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("can not create tokio runtime"); + runtime.block_on(async { + loop { + while let Some(event) = self.event_rx.recv().await { + // TODO: fix, check if interval from last reporting is larger than send interval + let metrics = self.registry.snapshots(); + let client = self.new_client(); + let queries: Vec = metrics + .iter() + .map(|(key, metric)| match metric { + Metric::Counter(c) => self.report_counter(key, c.as_ref(), event.time), + Metric::Gauge(g) => self.report_gauge(key, g.as_ref(), event.time), + Metric::Timer(t) => self.report_timer(key, t.as_ref(), event.time), + Metric::Meter(m) => self.report_meter(key, m.as_ref(), event.time), + Metric::Histogram(h) => self.report_histogram(key, &h.snapshot(), event.time), + }) + .collect(); + + if !queries.is_empty() { + self.do_query(&client, queries).await; + } + } + } + }) + }; + std::thread::spawn(looper); + } + + #[inline] + fn measurement(&self, name: &str) -> String { + format!("{}{}", self.measurement_prefix, name) + } + + #[inline] + fn with_query(&self, name: &str, since_start:i64) -> WriteQuery { + let mut query = + Timestamp::Milliseconds(self.system_time_millis(since_start)) + .into_query(self.measurement(name)); + + for (k, v) in self.tags.iter() { + query = query.add_tag(k, v.clone()); + } + + query + } + + #[inline] + async fn do_query(&self, client: &Client, query: Vec) { + // send query by chunk to avoid influxdb max request entity + // error + let chunks = query.chunks(self.batch_size); + for ch in chunks { + let batch = ch.to_owned(); + if let Err(e) = client.query(batch).await { + panic!("Failed to write influxdb, {}", e) + } + } + } + + fn report_meter(&self, name: &str, meter: &Meter, since_start: i64) -> WriteQuery { + self.with_query(name, since_start) + .add_field("m1", meter.m1_rate()) + .add_field("m5", meter.m5_rate()) + .add_field("m15", meter.m15_rate()) + } + + fn report_gauge(&self, name: &str, gauge: &Gauge, since_start: i64) -> WriteQuery { + let value = gauge.value(); + self.with_query(name, since_start).add_field("value", value) + } + + fn report_histogram(&self, name: &str, snapshot: &HistogramSnapshot, since_start: i64) -> WriteQuery { + self.with_query(name, since_start) + .add_field("p50", snapshot.quantile(0.5)) + .add_field("p75", snapshot.quantile(0.75)) + .add_field("p90", snapshot.quantile(0.90)) + .add_field("p99", snapshot.quantile(0.99)) + .add_field("p999", snapshot.quantile(0.999)) + .add_field("min", snapshot.min()) + .add_field("max", snapshot.max()) + .add_field("mean", snapshot.mean()) + } + + fn report_counter(&self, name: &str, c: &Counter, since_start: i64) -> WriteQuery { + self.with_query(name, since_start).add_field("value", c.value()) + } + + fn report_timer(&self, name: &str, t: &Timer, since_start: i64) -> WriteQuery { + let rate = t.rate(); + let latency = t.latency(); + + self.with_query(name, since_start) + .add_field("p50", latency.quantile(0.5)) + .add_field("p75", latency.quantile(0.75)) + .add_field("p90", latency.quantile(0.90)) + .add_field("p99", latency.quantile(0.99)) + .add_field("p999", latency.quantile(0.999)) + .add_field("min", latency.min()) + .add_field("max", latency.max()) + .add_field("mean", latency.mean()) + .add_field("m1", rate.m1_rate()) + .add_field("m5", rate.m5_rate()) + .add_field("m15", rate.m15_rate()) + } + + fn system_time_millis(&self, since_start:i64) -> u128 { + use std::ops::{Add}; + let timestamp = self.test_start_time.add(std::time::Duration::from_micros(since_start.try_into().unwrap())).duration_since(UNIX_EPOCH); + timestamp + .expect("System time earlier than UNIX_EPOCH") + .as_millis() + } +} diff --git a/src/objects.rs b/src/objects.rs index e7bdc3f..acf169c 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -73,20 +73,27 @@ fn cmp(&self, o: &Self) -> std::cmp::Ordering { self.t.cmp(&o.t).reverse()} use std::collections::BinaryHeap; use crate::utils::Counter; +use tokio::sync::mpsc; +use crate::influxdbreporter::SimulationReachedTimeEvent; pub struct Scheduler { heap: BinaryHeap, cur_t: i64, executed: Counter, + event_tx: mpsc::Sender, } impl Scheduler { pub fn new() -> Self { let binary_heap = BinaryHeap::::new(); + let (tx, rx) = mpsc::channel::(1000); + let reporter = InfluxDbReporter::new(rx); + reporter.start(); Scheduler { heap: binary_heap, cur_t: 0, executed: Counter::new(), + event_tx: tx, } } @@ -112,6 +119,7 @@ impl Scheduler { if self.cur_t > up_to_nano { false } else { + self.reportmetrics(); let nt = world.with_system(ee.aref, |system, world| -> Option { system.tick(self, world) }); @@ -135,7 +143,10 @@ impl Scheduler { } fn reportmetrics(&self) { - + futures::executor::block_on( + self.event_tx.send(SimulationReachedTimeEvent { + time: self.cur_t + })).unwrap(); } } From 6f23877f37f434ec4caeacf2f1660bb53371005e Mon Sep 17 00:00:00 2001 From: Vladimir Shakhov Date: Fri, 3 Mar 2023 21:58:53 +0100 Subject: [PATCH 5/6] using forked influxdb-rust until upstream merges a feature --- Cargo.lock | 1 + Cargo.toml | 2 +- docker/docker-compose.yml | 1 + src/influxdbreporter.rs | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4692d07..f778954 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,6 +476,7 @@ dependencies = [ [[package]] name = "influxdb" version = "0.5.2" +source = "git+https://github.com/bogdad/influxdb-rust?branch=main#d0c8de15ab06f209c52e4881f52d80b30e7ea898" dependencies = [ "chrono", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index da74bcd..621b1be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ rand_distr = "0.4.3" num-format = "0.4.3" metriki-core = "1.7.4" derive_builder = "0.12.0" -influxdb = {version="0.5.2", features=["reqwest"], path="../../influxdb-rust/influxdb"} +influxdb = { git = 'https://github.com/bogdad/influxdb-rust', branch = 'main' } tokio = { version = "1.0", default-features = false, features = ["net", "time"] } futures = "0.3.26" reqwest= "0.11.14" diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 728f768..2ec4c6f 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -18,6 +18,7 @@ services: - DOCKER_INFLUXDB_INIT_PASSWORD=adminadminadmin - DOCKER_INFLUXDB_INIT_ORG=noorg - DOCKER_INFLUXDB_INIT_BUCKET=grafana + - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=secrettokentoken volumes: - influxdb:/var/lib/influxdb networks: diff --git a/src/influxdbreporter.rs b/src/influxdbreporter.rs index 3fc0d2d..ef7c2f9 100644 --- a/src/influxdbreporter.rs +++ b/src/influxdbreporter.rs @@ -56,7 +56,7 @@ impl InfluxDbReporter { username: None, password: None, auth_token: env::var("AUTH_TOKEN").ok(), - measurement_prefix: "sdm".to_string(), + measurement_prefix: "sdm_".to_string(), tags: HashMap::new(), batch_size: 60, event_rx: event_rx, @@ -70,7 +70,7 @@ impl InfluxDbReporter { if let (Some(username), Some(password)) = (self.username.as_ref(), self.password.as_ref()) { client.with_auth(username, password) } else if let Some(auth_token) = &self.auth_token { - client.with_auth_token(auth_token) + client.with_token(auth_token) } else { client } From 7faa1c3bd3fdd45facf1481258f2075be7f84f52 Mon Sep 17 00:00:00 2001 From: Vladimir Shakhov Date: Sun, 5 Mar 2023 14:08:08 +0100 Subject: [PATCH 6/6] format + fixes to influxdbreporter --- src/influxdbreporter.rs | 128 +++++++++++++++++++++++++++++----------- src/main.rs | 60 ++++++++++++------- src/objects.rs | 80 +++++++++++++------------ src/systems.rs | 68 +++++++++++---------- src/traits.rs | 1 - src/utils.rs | 17 ++++-- 6 files changed, 222 insertions(+), 132 deletions(-) diff --git a/src/influxdbreporter.rs b/src/influxdbreporter.rs index ef7c2f9..6ebc8e1 100644 --- a/src/influxdbreporter.rs +++ b/src/influxdbreporter.rs @@ -9,7 +9,7 @@ use influxdb::{Client, InfluxDbWriteable, Timestamp, WriteQuery}; use metriki_core::metrics::*; use metriki_core::MetricsRegistry; use tokio::sync::mpsc; -use tokio::time::{Duration}; +use tokio::time::Duration; use metriki_core::global::global_registry; use std::env; @@ -19,17 +19,16 @@ this is almost a copy of https://github.com/sunng87/metriki/blob/master/metriki-influxdb-reporter/src/lib.rs */ - #[derive(Debug)] pub struct SimulationReachedTimeEvent { - pub time: i64 + pub time_ns: i64, + pub stop: bool, } #[derive(Debug)] pub struct InfluxDbReporter { registry: Arc, url: String, - interval_secs: u64, database: String, username: Option, password: Option, @@ -38,30 +37,39 @@ pub struct InfluxDbReporter { tags: HashMap, batch_size: usize, event_rx: mpsc::Receiver, - last_send_time: i64, + last_send_time_ns: Option, test_start_time: SystemTime, + send_interval_ns: i64, } - impl InfluxDbReporter { - pub fn new(event_rx: mpsc::Receiver) -> Self { use std::ops::Sub; - let half_day_secs = 60*12; + let hour_secs = 60 * 60; + let interval_secs = 1; + let mut tags = HashMap::new(); + let test_start_time = SystemTime::now().sub(Duration::from_secs(hour_secs)); + let test_start_time_string: String = test_start_time + .duration_since(UNIX_EPOCH) + .ok() + .unwrap() + .as_secs() + .to_string(); + tags.insert("test_start_time".to_string(), test_start_time_string); InfluxDbReporter { registry: global_registry(), url: "http://localhost:8086".to_string(), - interval_secs: 30, database: "grafana".to_string(), username: None, password: None, auth_token: env::var("AUTH_TOKEN").ok(), measurement_prefix: "sdm_".to_string(), - tags: HashMap::new(), + tags: tags, batch_size: 60, event_rx: event_rx, - last_send_time: -100, - test_start_time: SystemTime::now().sub(Duration::from_secs(half_day_secs)) + last_send_time_ns: None, + test_start_time: test_start_time, + send_interval_ns: interval_secs * 1_000_000_000, } } @@ -77,33 +85,71 @@ impl InfluxDbReporter { } pub fn start(mut self) { + let test_start_time_string: String = self.test_start_time + .duration_since(UNIX_EPOCH) + .ok() + .unwrap() + .as_secs() + .to_string(); + println!( + "influxdb: test_start_time {}", test_start_time_string + ); let looper = move || { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() .expect("can not create tokio runtime"); runtime.block_on(async { - loop { + let mut need_stop = false; + while !need_stop { while let Some(event) = self.event_rx.recv().await { + if event.stop { + need_stop = true; + } // TODO: fix, check if interval from last reporting is larger than send interval - let metrics = self.registry.snapshots(); - let client = self.new_client(); - let queries: Vec = metrics - .iter() - .map(|(key, metric)| match metric { - Metric::Counter(c) => self.report_counter(key, c.as_ref(), event.time), - Metric::Gauge(g) => self.report_gauge(key, g.as_ref(), event.time), - Metric::Timer(t) => self.report_timer(key, t.as_ref(), event.time), - Metric::Meter(m) => self.report_meter(key, m.as_ref(), event.time), - Metric::Histogram(h) => self.report_histogram(key, &h.snapshot(), event.time), - }) - .collect(); - - if !queries.is_empty() { - self.do_query(&client, queries).await; + if self.last_send_time_ns.is_none() + || self.last_send_time_ns.unwrap() + self.send_interval_ns + <= event.time_ns + { + let metrics = self.registry.snapshots(); + let client = self.new_client(); + let queries: Vec = metrics + .iter() + .map(|(key, metric)| match metric { + Metric::Counter(c) => { + self.report_counter(key, c.as_ref(), event.time_ns) + } + Metric::Gauge(g) => { + self.report_gauge(key, g.as_ref(), event.time_ns) + } + Metric::Timer(t) => { + self.report_timer(key, t.as_ref(), event.time_ns) + } + Metric::Meter(m) => { + self.report_meter(key, m.as_ref(), event.time_ns) + } + Metric::Histogram(h) => { + self.report_histogram(key, &h.snapshot(), event.time_ns) + } + }) + .collect(); + + if !queries.is_empty() { + self.do_query(&client, queries).await; + } + self.last_send_time_ns = Some(event.time_ns); } } } + let test_start_time_string: String = self.test_start_time + .duration_since(UNIX_EPOCH) + .ok() + .unwrap() + .as_secs() + .to_string(); + println!( + "influxdb: test_start_time {}", test_start_time_string + ); }) }; std::thread::spawn(looper); @@ -115,9 +161,8 @@ impl InfluxDbReporter { } #[inline] - fn with_query(&self, name: &str, since_start:i64) -> WriteQuery { - let mut query = - Timestamp::Milliseconds(self.system_time_millis(since_start)) + fn with_query(&self, name: &str, since_start: i64) -> WriteQuery { + let mut query = Timestamp::Milliseconds(self.system_time_millis(since_start)) .into_query(self.measurement(name)); for (k, v) in self.tags.iter() { @@ -152,7 +197,12 @@ impl InfluxDbReporter { self.with_query(name, since_start).add_field("value", value) } - fn report_histogram(&self, name: &str, snapshot: &HistogramSnapshot, since_start: i64) -> WriteQuery { + fn report_histogram( + &self, + name: &str, + snapshot: &HistogramSnapshot, + since_start: i64, + ) -> WriteQuery { self.with_query(name, since_start) .add_field("p50", snapshot.quantile(0.5)) .add_field("p75", snapshot.quantile(0.75)) @@ -165,7 +215,8 @@ impl InfluxDbReporter { } fn report_counter(&self, name: &str, c: &Counter, since_start: i64) -> WriteQuery { - self.with_query(name, since_start).add_field("value", c.value()) + self.with_query(name, since_start) + .add_field("value", c.value()) } fn report_timer(&self, name: &str, t: &Timer, since_start: i64) -> WriteQuery { @@ -186,9 +237,14 @@ impl InfluxDbReporter { .add_field("m15", rate.m15_rate()) } - fn system_time_millis(&self, since_start:i64) -> u128 { - use std::ops::{Add}; - let timestamp = self.test_start_time.add(std::time::Duration::from_micros(since_start.try_into().unwrap())).duration_since(UNIX_EPOCH); + fn system_time_millis(&self, since_start: i64) -> u128 { + use std::ops::Add; + let timestamp = self + .test_start_time + .add(std::time::Duration::from_nanos( + since_start.try_into().unwrap(), + )) + .duration_since(UNIX_EPOCH); timestamp .expect("System time earlier than UNIX_EPOCH") .as_millis() diff --git a/src/main.rs b/src/main.rs index 00e2462..aca6282 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,29 +1,30 @@ -pub mod utils; -pub mod systems; +pub mod influxdbreporter; pub mod objects; +pub mod systems; pub mod traits; -pub mod influxdbreporter; +pub mod utils; -#[macro_use] extern crate derive_builder; extern crate rand; -use crate::objects::{World, Scheduler}; -use crate::systems::{ArrivalSource, Server, EndSink, LoadBalancer, System}; -use crate::traits::{StatEmitter, HasQueue}; +use crate::objects::{Scheduler, World}; +use crate::systems::{ArrivalSource, EndSink, LoadBalancer, Server, System}; +use crate::traits::{HasQueue, StatEmitter}; use crate::utils::tostring; use rand_distr::Poisson; fn main() { - let mut world = World::new(); let endsink = EndSink::new(); let endsink_ref = world.add(System::EndSink(endsink), "endsink".to_string()); - let up_to_nano = 1_000_000_000; - + // 1 000 ns = 1 microsecond + // 1 000 000 = 1 millisecond + // 1 000 000 000 = 1 second + let up_to_nano = 60 * 1_000_000_000; + let server1 = Server::new(Poisson::::new(20_000.0).unwrap(), endsink_ref); let server1_ref = world.add(System::Server(server1), "server1".to_string()); @@ -31,26 +32,43 @@ fn main() { let server2_ref = world.add(System::Server(server2), "server2".to_string()); let load_balancer = LoadBalancer::new(vec![server1_ref, server2_ref]); - let load_balancer_ref = world.add(System::LoadBalancer(load_balancer), "load_balancer".to_string()); + let load_balancer_ref = world.add( + System::LoadBalancer(load_balancer), + "load_balancer".to_string(), + ); - let ar = ArrivalSource::new( Poisson::::new(1_000.0).unwrap(), load_balancer_ref); + // 1_000 -> every microsecond a request arives, 1m rps + let ar = ArrivalSource::new(Poisson::::new(1_000.0).unwrap(), load_balancer_ref); let ar_ref = world.add(System::ArrivalSource(ar), "incomming".to_string()); - + let mut scheduler = Scheduler::new(); scheduler.schedule(&mut world, ar_ref); + let mut pt_ns = 0; while scheduler.execute_next(&mut world, up_to_nano) { - + if scheduler.get_cur_t() > pt_ns + 1_000_000_000 { + println!("second passed {}", tostring(scheduler.get_cur_t())); + pt_ns = scheduler.get_cur_t(); + } } println!("executed {}", scheduler.stats()); - - - world.with_system(ar_ref, |ar, _w|{println!("ar {}", ar.stats());}); - world.with_system(server1_ref, |server, _w| println!("server1 {}", server.stats()) ); - world.with_system(server2_ref, |server, _w| println!("server2 {}", server.stats()) ); - world.with_system(load_balancer_ref, |load_balancer, _w| println!("load balaner {}", load_balancer.stats()) ); - world.with_system(endsink_ref, |endsink, _w| println!("endsink {}", endsink.stats()) ); + + world.with_system(ar_ref, |ar, _w| { + println!("ar {}", ar.stats()); + }); + world.with_system(server1_ref, |server, _w| { + println!("server1 {}", server.stats()) + }); + world.with_system(server2_ref, |server, _w| { + println!("server2 {}", server.stats()) + }); + world.with_system(load_balancer_ref, |load_balancer, _w| { + println!("load balaner {}", load_balancer.stats()) + }); + world.with_system(endsink_ref, |endsink, _w| { + println!("endsink {}", endsink.stats()) + }); println!("requests in the system {}", tostring(world.queue_size())); } diff --git a/src/objects.rs b/src/objects.rs index acf169c..683a06e 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -1,5 +1,5 @@ -use crate::traits::{SystemRef, StatEmitter, WorldMember, HasQueue}; use crate::systems::System; +use crate::traits::{HasQueue, StatEmitter, SystemRef, WorldMember}; use crate::influxdbreporter::InfluxDbReporter; @@ -9,17 +9,21 @@ pub struct World { impl World { pub fn new() -> Self { - World { systems: Vec::new()} + World { + systems: Vec::new(), + } } pub fn add(&mut self, system: System, name: String) -> SystemRef { let sr = self.systems.len(); self.systems.push(system); - self.with_system(sr, |system, _world|{ - system.add(sr, name) - }); + self.with_system(sr, |system, _world| system.add(sr, name)); sr } - pub fn with_system R>(&mut self, system_ref: SystemRef, f:F) -> R { + pub fn with_system R>( + &mut self, + system_ref: SystemRef, + f: F, + ) -> R { let (mut s, mut nw) = self.split(system_ref); let r = f(&mut s, &mut nw); std::mem::swap(self, &mut nw); @@ -32,9 +36,7 @@ impl World { std::mem::swap(&mut unset, self.systems.get_mut(system_ref).unwrap()); let mut nsystems = vec![]; std::mem::swap(&mut nsystems, &mut self.systems); - let nw = World { - systems: nsystems - }; + let nw = World { systems: nsystems }; (unset, nw) } } @@ -49,7 +51,6 @@ impl HasQueue for World { } } - struct EmitterRef { aref: SystemRef, } @@ -59,46 +60,49 @@ struct SchedulerElement { e: EmitterRef, } impl PartialEq for SchedulerElement { -fn eq(&self, o: &Self) -> bool { self.t == o.t } -} -impl Eq for SchedulerElement { + fn eq(&self, o: &Self) -> bool { + self.t == o.t + } } +impl Eq for SchedulerElement {} impl PartialOrd for SchedulerElement { -fn partial_cmp(&self, o: &Self) -> Option { self.t.partial_cmp(&o.t).map(|e|{e.reverse()})} + fn partial_cmp(&self, o: &Self) -> Option { + self.t.partial_cmp(&o.t).map(|e| e.reverse()) + } } impl Ord for SchedulerElement { - -fn cmp(&self, o: &Self) -> std::cmp::Ordering { self.t.cmp(&o.t).reverse()} + fn cmp(&self, o: &Self) -> std::cmp::Ordering { + self.t.cmp(&o.t).reverse() + } } -use std::collections::BinaryHeap; +use crate::influxdbreporter::SimulationReachedTimeEvent; use crate::utils::Counter; +use std::collections::BinaryHeap; use tokio::sync::mpsc; -use crate::influxdbreporter::SimulationReachedTimeEvent; pub struct Scheduler { heap: BinaryHeap, - cur_t: i64, + cur_t_ns: i64, executed: Counter, event_tx: mpsc::Sender, } impl Scheduler { - pub fn new() -> Self { let binary_heap = BinaryHeap::::new(); - let (tx, rx) = mpsc::channel::(1000); + let (tx, rx) = mpsc::channel::(1_000_000); let reporter = InfluxDbReporter::new(rx); reporter.start(); Scheduler { heap: binary_heap, - cur_t: 0, + cur_t_ns: 0, executed: Counter::new(), event_tx: tx, } } pub fn schedule(&mut self, world: &mut World, emitter: SystemRef) { - world.with_system(emitter, |system, world|{ + world.with_system(emitter, |system, world| { let nt = system.tick(self, world); if let Some(nt) = nt { self.schedule_at(nt, emitter); @@ -107,7 +111,10 @@ impl Scheduler { } pub fn schedule_at(&mut self, t: i64, emitter: SystemRef) { - self.heap.push(SchedulerElement { t, e: EmitterRef{aref: emitter}}); + self.heap.push(SchedulerElement { + t, + e: EmitterRef { aref: emitter }, + }); } pub fn execute_next(&mut self, world: &mut World, up_to_nano: i64) -> bool { @@ -115,19 +122,17 @@ impl Scheduler { if let Some(top) = top { self.executed.inc(); let ee = top.e; - self.cur_t = top.t; - if self.cur_t > up_to_nano { + self.cur_t_ns = top.t; + if self.cur_t_ns >= up_to_nano { + self.reportmetrics(true); false } else { - self.reportmetrics(); + self.reportmetrics(false); let nt = world.with_system(ee.aref, |system, world| -> Option { system.tick(self, world) }); if let Some(nt) = nt { - self.heap.push(SchedulerElement { - t: nt, - e: ee - }); + self.heap.push(SchedulerElement { t: nt, e: ee }); true } else { self.heap.len() > 0 @@ -139,14 +144,15 @@ impl Scheduler { } pub fn get_cur_t(&self) -> i64 { - self.cur_t + self.cur_t_ns } - fn reportmetrics(&self) { - futures::executor::block_on( - self.event_tx.send(SimulationReachedTimeEvent { - time: self.cur_t - })).unwrap(); + fn reportmetrics(&self, stop: bool) { + futures::executor::block_on(self.event_tx.send(SimulationReachedTimeEvent { + time_ns: self.cur_t_ns, + stop: stop, + })) + .unwrap(); } } diff --git a/src/systems.rs b/src/systems.rs index 0649251..fd41ff8 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -1,7 +1,6 @@ - use crate::objects::{Scheduler, World}; -use crate::traits::{SystemRef, StatEmitter, Emmitter, WorldMember, Sink, HasQueue}; -use crate::utils::{Counter, Meter, tostring}; +use crate::traits::{Emmitter, HasQueue, Sink, StatEmitter, SystemRef, WorldMember}; +use crate::utils::{tostring, Counter, Meter}; use rand_distr::Distribution; use rand_distr::Poisson; @@ -15,12 +14,15 @@ pub struct ArrivalSource { impl ArrivalSource { pub fn new(distribution: Poisson, sink: SystemRef) -> Self { - ArrivalSource { distribution, sink, meter: Meter::new(), sr: None} + ArrivalSource { + distribution, + sink, + meter: Meter::new(), + sr: None, + } } - } - pub struct EndSink { ticks: Counter, sr: Option, @@ -28,13 +30,13 @@ pub struct EndSink { impl EndSink { pub fn new() -> Self { - EndSink {ticks: Counter::new(), sr: None} + EndSink { + ticks: Counter::new(), + sr: None, + } } } - - - impl StatEmitter for ArrivalSource { fn stats(&self) -> String { format!("as {}", self.meter.stats()) @@ -53,13 +55,12 @@ impl WorldMember for ArrivalSource { } impl<'a> Emmitter for ArrivalSource { - fn tick(&mut self, world: &mut World, scheduler: &mut Scheduler) -> Option { - let diff = (self.distribution.sample(&mut rand::thread_rng()) ) as i64; - let next_time = scheduler.get_cur_t() + diff; + let diff = (self.distribution.sample(&mut rand::thread_rng())) as i64; + let next_time = scheduler.get_cur_t() + diff; self.meter.inc(diff); - world.with_system(self.sink, |system, world|{ + world.with_system(self.sink, |system, world| { system.next(world, scheduler); }); Some(next_time as i64) @@ -84,7 +85,6 @@ impl WorldMember for EndSink { } impl Sink for EndSink { - fn next(&mut self, _world: &mut World, _scheduler: &mut Scheduler) { self.ticks.inc() } @@ -102,7 +102,12 @@ pub struct LoadBalancer { impl LoadBalancer { pub fn new(sinks: Vec) -> Self { assert!(sinks.len() > 0); - LoadBalancer { sinks, sr: None, counter: Counter::new(), cur: 0 } + LoadBalancer { + sinks, + sr: None, + counter: Counter::new(), + cur: 0, + } } } @@ -135,7 +140,6 @@ impl StatEmitter for LoadBalancer { } } - use std::collections::VecDeque; pub struct Server { distribution: Poisson, @@ -179,8 +183,12 @@ impl Sink for Server { impl StatEmitter for Server { fn stats(&self) -> String { - format!("meter {} queue {} counter {}", self.meter.stats(), - tostring(self.queue.len()), self.counter.stats()) + format!( + "meter {} queue {} counter {}", + self.meter.stats(), + tostring(self.queue.len()), + self.counter.stats() + ) } } @@ -190,7 +198,6 @@ impl HasQueue for Server { } } - impl WorldMember for Server { fn add(&mut self, system_ref: SystemRef, name: String) { self.meter.name = Some(name + "_meter"); @@ -203,17 +210,15 @@ impl WorldMember for Server { } impl<'a> Emmitter for Server { - fn tick(&mut self, world: &mut World, scheduler: &mut Scheduler) -> Option { let _ob = self.queue.front().cloned(); self.queue.pop_front(); - world.with_system(self.sink, |system, world|{system.next(world, scheduler)}); + world.with_system(self.sink, |system, world| system.next(world, scheduler)); let _nb = self.queue.front(); self.queue.front().cloned() } } - pub enum System { Unset, EndSink(EndSink), @@ -234,13 +239,13 @@ impl System { } pub fn next(&mut self, world: &mut World, scheduler: &mut Scheduler) { - match self { - System::EndSink(es) => es.next(world, scheduler), - System::Server(sr) => sr.next(world, scheduler), - System::ArrivalSource(_ars) => unimplemented!(), - System::Unset => unimplemented!(), - System::LoadBalancer(lb) => lb.next(world, scheduler), - } + match self { + System::EndSink(es) => es.next(world, scheduler), + System::Server(sr) => sr.next(world, scheduler), + System::ArrivalSource(_ars) => unimplemented!(), + System::Unset => unimplemented!(), + System::LoadBalancer(lb) => lb.next(world, scheduler), + } } pub fn queue_size(&self) -> i64 { @@ -255,7 +260,7 @@ impl System { } impl StatEmitter for System { - fn stats(&self) -> String { + fn stats(&self) -> String { match self { System::EndSink(es) => es.stats(), System::Server(sr) => sr.stats(), @@ -287,4 +292,3 @@ impl WorldMember for System { } } } - diff --git a/src/traits.rs b/src/traits.rs index 46d3f5f..a398f6a 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -3,7 +3,6 @@ pub type SystemRef = usize; use crate::objects::Scheduler; use crate::objects::World; - pub trait WorldMember { fn add(&mut self, system_ref: SystemRef, name: String); fn getref(&self) -> Option; diff --git a/src/utils.rs b/src/utils.rs index 60b0656..559c271 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,3 @@ - use num_format::{Locale, ToFormattedString}; pub fn tostring(arg: T) -> String { arg.to_formatted_string(&Locale::en) @@ -21,13 +20,19 @@ pub struct Meter { impl Meter { pub fn new() -> Self { - Meter { sm: 0, co: 0, name: None } + Meter { + sm: 0, + co: 0, + name: None, + } } pub fn inc(&mut self, d: i64) { self.co += 1; self.sm += d; - self.name.as_ref().map(|name|{ global_registry().meter(name.as_str()).mark() }); + self.name + .as_ref() + .map(|name| global_registry().meter(name.as_str()).mark()); } pub fn stats(&self) -> String { @@ -40,7 +45,7 @@ impl Meter { } pub struct Counter { - co: i64, + co: i64, pub name: Option, } @@ -51,7 +56,9 @@ impl Counter { pub fn inc(&mut self) { self.co += 1; - self.name.as_ref().map(|name|{ global_registry().counter(name.as_str()).inc(1) }); + self.name + .as_ref() + .map(|name| global_registry().counter(name.as_str()).inc(1)); } pub fn stats(&self) -> String {