@@ -34,6 +34,8 @@ import (
34
34
srv_debug "github.com/arduino/arduino-cli/rpc/debug"
35
35
srv_monitor "github.com/arduino/arduino-cli/rpc/monitor"
36
36
srv_settings "github.com/arduino/arduino-cli/rpc/settings"
37
+ stats "github.com/segmentio/stats/v4"
38
+ "github.com/segmentio/stats/v4/prometheus"
37
39
"github.com/sirupsen/logrus"
38
40
"github.com/spf13/cobra"
39
41
"github.com/spf13/viper"
@@ -59,16 +61,40 @@ func NewCommand() *cobra.Command {
59
61
var daemonize bool
60
62
61
63
func runDaemonCommand (cmd * cobra.Command , args []string ) {
64
+
65
+ logrus .Infof ("configure telemetry" )
66
+
67
+ // Configure telemetry engine
68
+ ph := prometheus .DefaultHandler
69
+
70
+ // Register the client so it receives metrics from the default engine.
71
+ stats .Register (ph )
72
+
73
+ // Flush the default stats engine on return to ensure all buffered
74
+ // metrics are sent to the server.
75
+ defer stats .Flush ()
76
+ http .Handle ("/metrics" , ph )
77
+ go http .ListenAndServe (":2112" , nil )
78
+ logrus .Infof ("Prometheus telemetry is available on /metrics, TCP port 2112" )
79
+ // Set a tag on a counter increment.
80
+ stats .Incr ("user.login" , stats.Tag {"user" , "luke" })
81
+
62
82
port := viper .GetString ("daemon.port" )
63
83
s := grpc .NewServer ()
64
84
65
- // register the commands service
66
- headers := http.Header {"User-Agent" : []string {
67
- fmt .Sprintf ("%s/%s daemon (%s; %s; %s) Commit:%s" ,
68
- globals .VersionInfo .Application ,
69
- globals .VersionInfo .VersionString ,
70
- runtime .GOARCH , runtime .GOOS ,
71
- runtime .Version (), globals .VersionInfo .Commit )}}
85
+ // Compose user agent header
86
+ headers := http.Header {
87
+ "User-Agent" : []string {
88
+ fmt .Sprintf ("%s/%s daemon (%s; %s; %s) Commit:%s" ,
89
+ globals .VersionInfo .Application ,
90
+ globals .VersionInfo .VersionString ,
91
+ runtime .GOARCH ,
92
+ runtime .GOOS ,
93
+ runtime .Version (),
94
+ globals .VersionInfo .Commit ),
95
+ },
96
+ }
97
+ // Register the commands service
72
98
srv_commands .RegisterArduinoCoreServer (s , & daemon.ArduinoCoreServerImpl {
73
99
DownloaderHeaders : headers ,
74
100
VersionString : globals .VersionInfo .VersionString ,
@@ -121,4 +147,5 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
121
147
if err := s .Serve (lis ); err != nil {
122
148
logrus .Fatalf ("Failed to serve: %v" , err )
123
149
}
150
+
124
151
}
0 commit comments