@@ -29,6 +29,8 @@ import (
29
29
srv_commands "github.com/arduino/arduino-cli/rpc/commands"
30
30
srv_monitor "github.com/arduino/arduino-cli/rpc/monitor"
31
31
srv_settings "github.com/arduino/arduino-cli/rpc/settings"
32
+ stats "github.com/segmentio/stats/v4"
33
+ "github.com/segmentio/stats/v4/prometheus"
32
34
"github.com/sirupsen/logrus"
33
35
"github.com/spf13/cobra"
34
36
"github.com/spf13/viper"
@@ -54,25 +56,49 @@ func NewCommand() *cobra.Command {
54
56
var daemonize bool
55
57
56
58
func 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
+
57
77
port := viper .GetString ("daemon.port" )
58
78
s := grpc .NewServer ()
59
79
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
67
93
srv_commands .RegisterArduinoCoreServer (s , & daemon.ArduinoCoreServerImpl {
68
94
DownloaderHeaders : headers ,
69
95
VersionString : globals .VersionInfo .VersionString ,
70
96
})
71
97
72
- // register the monitors service
98
+ // Register the monitors service
73
99
srv_monitor .RegisterMonitorServer (s , & daemon.MonitorService {})
74
100
75
- // register the settings service
101
+ // Register the settings service
76
102
srv_settings .RegisterSettingsServer (s , & daemon.SettingsService {})
77
103
78
104
if ! daemonize {
@@ -92,4 +118,5 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
92
118
if err := s .Serve (lis ); err != nil {
93
119
logrus .Fatalf ("failed to serve: %v" , err )
94
120
}
121
+
95
122
}
0 commit comments