@@ -18,11 +18,11 @@ import (
1818)
1919
2020var (
21- showVersion = flag .Bool ("version" , false , "Print version information. " )
22- listenAddress = flag .String ("web.listen-address" , ":9399" , "Address to listen on for web interface and telemetry. " )
23- metricsPath = flag .String ("web.metrics-path" , "/metrics" , "Path under which to expose metrics. " )
24- enableReload = flag .Bool ("web.enable-reload" , false , "Enable reload collector data handler. " )
25- configFile = flag .String ("config.file" , "sql_exporter.yml" , "SQL Exporter configuration file name. " )
21+ showVersion = flag .Bool ("version" , false , "Print version information" )
22+ listenAddress = flag .String ("web.listen-address" , ":9399" , "Address to listen on for web interface and telemetry" )
23+ metricsPath = flag .String ("web.metrics-path" , "/metrics" , "Path under which to expose metrics" )
24+ enableReload = flag .Bool ("web.enable-reload" , false , "Enable reload collector data handler" )
25+ configFile = flag .String ("config.file" , "sql_exporter.yml" , "SQL Exporter configuration filename " )
2626)
2727
2828func init () {
@@ -80,12 +80,21 @@ func main() {
8080func reloadCollectors (e sql_exporter.Exporter ) func (http.ResponseWriter , * http.Request ) {
8181 return func (w http.ResponseWriter , r * http.Request ) {
8282 klog .Infof ("Reloading the collectors..." )
83- err := e .Config (). ReloadCollectorFiles ()
84- if err != nil {
85- klog .Errorf ("Error reloading collectors - %v" , err )
83+ config := e .Config ()
84+ if err := config . ReloadCollectorFiles (); err != nil {
85+ klog .Errorf ("Error reloading collector configs - %v" , err )
8686 http .Error (w , err .Error (), http .StatusInternalServerError )
8787 }
88- http .Error (w , `Query collectors have been reloaded` , http .StatusOK )
88+
89+ // FIXME: Should be t.Collectors() instead of config.Collectors
90+ target , err := sql_exporter .NewTarget ("" , "" , string (config .Target .DSN ), config .Collectors , nil , config .Globals )
91+ if err != nil {
92+ klog .Errorf ("Error creating a new target - %v" , err )
93+ }
94+ e .UpdateTarget ([]sql_exporter.Target {target })
95+
96+ klog .Infof ("Query collectors have been successfuly reloaded" )
97+ w .WriteHeader (http .StatusNoContent )
8998 }
9099}
91100
0 commit comments