@@ -29,6 +29,8 @@ import (
2929 srv_commands "github.com/arduino/arduino-cli/rpc/commands"
3030 srv_monitor "github.com/arduino/arduino-cli/rpc/monitor"
3131 srv_settings "github.com/arduino/arduino-cli/rpc/settings"
32+ stats "github.com/segmentio/stats/v4"
33+ "github.com/segmentio/stats/v4/prometheus"
3234 "github.com/sirupsen/logrus"
3335 "github.com/spf13/cobra"
3436 "github.com/spf13/viper"
@@ -54,25 +56,49 @@ func NewCommand() *cobra.Command {
5456var daemonize bool
5557
5658func runDaemonCommand (cmd * cobra.Command , args []string ) {
59+
60+ logrus .Infof ("configure telemetry" )
61+
62+ // Configure telemetry engine
63+ ph := prometheus .DefaultHandler
64+
65+ // Register the client so it receives metrics from the default engine.
66+ stats .Register (ph )
67+
68+ // Flush the default stats engine on return to ensure all buffered
69+ // metrics are sent to the server.
70+ defer stats .Flush ()
71+ http .Handle ("/metrics" , ph )
72+ go http .ListenAndServe (":2112" , nil )
73+ logrus .Infof ("Prometheus telemetry is available on /metrics, TCP port 2112" )
74+ // Set a tag on a counter increment.
75+ stats .Incr ("user.login" , stats.Tag {"user" , "luke" })
76+
5777 port := viper .GetString ("daemon.port" )
5878 s := grpc .NewServer ()
5979
60- // register the commands service
61- headers := http.Header {"User-Agent" : []string {
62- fmt .Sprintf ("%s/%s daemon (%s; %s; %s) Commit:%s" ,
63- globals .VersionInfo .Application ,
64- globals .VersionInfo .VersionString ,
65- runtime .GOARCH , runtime .GOOS ,
66- runtime .Version (), globals .VersionInfo .Commit )}}
80+ // Compose user agent header
81+ headers := http.Header {
82+ "User-Agent" : []string {
83+ fmt .Sprintf ("%s/%s daemon (%s; %s; %s) Commit:%s" ,
84+ globals .VersionInfo .Application ,
85+ globals .VersionInfo .VersionString ,
86+ runtime .GOARCH ,
87+ runtime .GOOS ,
88+ runtime .Version (),
89+ globals .VersionInfo .Commit ),
90+ },
91+ }
92+ // Register the commands service
6793 srv_commands .RegisterArduinoCoreServer (s , & daemon.ArduinoCoreServerImpl {
6894 DownloaderHeaders : headers ,
6995 VersionString : globals .VersionInfo .VersionString ,
7096 })
7197
72- // register the monitors service
98+ // Register the monitors service
7399 srv_monitor .RegisterMonitorServer (s , & daemon.MonitorService {})
74100
75- // register the settings service
101+ // Register the settings service
76102 srv_settings .RegisterSettingsServer (s , & daemon.SettingsService {})
77103
78104 if ! daemonize {
@@ -92,4 +118,5 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
92118 if err := s .Serve (lis ); err != nil {
93119 logrus .Fatalf ("failed to serve: %v" , err )
94120 }
121+
95122}
0 commit comments