Permalink
Browse files
Export Prometheus telemetry in daemon mode (#573)
* Apply cosmetics * Implement ugly telemetry POC * Added prefix and moved Insrumentation inside the command package * Refactor the telemetry module * Implement configuration via Viper * Add stats flush in case of a not daemonized cli daemon proces * Add repertory to store installation id and secret * Repertory force write * Cosmetics * Use viper config for repertory dir * Add test for repertory file creation * Add testing for telemetry deaemon and repertory * Wait for repertory and kill daemon * Updated pyinvoke to use async feature to test the daemon * Updated daemon test timeout * Cosmetics * Set getDefaultArduinoDataDir as unexported * Cosmetics * Cosmetics * Cosmetics * Lint on repertory module * Set SIGTERM as kill signal in case of win platform to overcome pyinvoke bug * Import platform as a module * Reverse platform if for signal value * Extract pid value * Remove print leftover * Add better error handling in repertory creation * Update docs with old README extract * Remove telemetry.pattern setting from docs * Remove serverPattern config option for telemetry * Upgrade viper to 1.6.2 * Defer stats Increment in compile command and explicit set for success/failure * Fix board list help message * Implement stats flush anyway to leverage module no-op in case of no handler configured * Rename "repertory" module in "inventory" and refactor Sanitize function * Sanitize ExportFile in command/compile * Refactor daemon start fixture to include daemon process cleanup * Use defer function to push success tag correctly updated * Use named return parameters to handle success tagging for a command stat
- Loading branch information
Showing
with
479 additions
and 28 deletions.
- +1 −1 cli/board/list.go
- +4 −0 cli/cli.go
- +24 −7 cli/daemon/daemon.go
- +2 −3 commands/board/attach.go
- +13 −1 commands/board/list.go
- +30 −2 commands/compile/compile.go
- +4 −0 configuration/defaults.go
- +37 −0 docs/getting-started.md
- +4 −4 go.mod
- +95 −2 go.sum
- +84 −0 inventory/inventory.go
- +65 −0 telemetry/telemetry.go
- +41 −2 test/conftest.py
- +5 −2 test/requirements.in
- +12 −2 test/requirements.txt
- +0 −1 test/test_board.py
- +40 −0 test/test_daemon.py
- +18 −1 test/test_main.py
| @@ -309,3 +309,40 @@ [email protected] downloaded | ||
| Installing [email protected]... | ||
| Installed [email protected] | ||
| ``` | ||
|
|
||
|
|
||
| Using the ``daemon`` mode and the gRPC interface | ||
| ------------------------------------------------ | ||
|
|
||
| Arduino CLI can be launched as a gRPC server via the `daemon` command. | ||
|
|
||
| The [client_example] folder contains a sample client code that shows how to | ||
| interact with the gRPC server. Available services and messages are detailed | ||
| in the [gRPC reference] pages. | ||
|
|
||
|
|
||
| To provide observability for the gRPC server activities besides logs, | ||
| the `daemon` mode activates and exposes by default a [Prometheus](https://prometheus.io/) | ||
| endpoint (http://localhost:9090/metrics) that can be fetched for | ||
| telemetry data like: | ||
|
|
||
| ```text | ||
| # TYPE daemon_compile counter | ||
| daemon_compile{buildProperties="",exportFile="",fqbn="arduino:samd:mkr1000",installationID="ed6f1f22-1fbe-4b1f-84be-84d035b6369c",jobs="0",libraries="",preprocess="false",quiet="false",showProperties="false",sketchPath="5ff767c6fa5a91230f5cb4e267c889aa61489ab2c4f70f35f921f934c1462cb6",success="true",verbose="true",vidPid="",warnings=""} 1 1580385724726 | ||
| # TYPE daemon_board_list counter | ||
| daemon_board_list{installationID="ed6f1f22-1fbe-4b1f-84be-84d035b6369c",success="true"} 1 1580385724833 | ||
| ``` | ||
|
|
||
| The telemetry settings are exposed via the ``telemetry`` section | ||
| in the CLI configuration: | ||
|
|
||
| ```yaml | ||
| telemetry: | ||
| enabled: true | ||
| addr: :9090 | ||
| ``` | ||
|
|
||
| [client_example]: https://github.com/arduino/arduino-cli/blob/master/client_example | ||
| [gRPC reference]: /rpc/commands | ||
| [Prometheus]: https://prometheus.io/ | ||
Oops, something went wrong.

