@@ -33,10 +33,13 @@ import (
3333 "yunion.io/x/pkg/gotypes"
3434
3535 "yunion.io/x/onecloud/pkg/apis"
36+ identity_apis "yunion.io/x/onecloud/pkg/apis/identity"
37+ "yunion.io/x/onecloud/pkg/cloudcommon/tsdb"
3638 "yunion.io/x/onecloud/pkg/hostman/hostinfo/hostconsts"
3739 "yunion.io/x/onecloud/pkg/hostman/system_service"
3840 agentmodels "yunion.io/x/onecloud/pkg/lbagent/models"
3941 agentutils "yunion.io/x/onecloud/pkg/lbagent/utils"
42+ "yunion.io/x/onecloud/pkg/mcclient/auth"
4043 "yunion.io/x/onecloud/pkg/util/sysutils"
4144)
4245
@@ -187,6 +190,13 @@ func (h *HaproxyHelper) handleUseCorpusCmd(ctx context.Context, cmd *LbagentCmd)
187190 return err
188191 }
189192 }
193+ // refresh telegraf URL from service catalog
194+ s := auth .GetAdminSession (ctx , h .opts .Region )
195+ tsdbSrc , _ := tsdb .GetDefaultServiceSource (s , identity_apis .EndpointInterfacePublic )
196+ if tsdbSrc != nil && len (tsdbSrc .URLs ) > 0 {
197+ agentParams .AgentModel .Params .Telegraf .InfluxDbOutputUrl = tsdbSrc .URLs [0 ]
198+ agentParams .SetTelegrafParams ("influx_db_output_url" , tsdbSrc .URLs [0 ])
199+ }
190200 if agentParams .AgentModel .Params .Telegraf .InfluxDbOutputUrl != "" {
191201 agentParams .SetTelegrafParams ("haproxy_input_stats_socket" , h .haproxyStatsSocketFile ())
192202 // telegraf config
@@ -198,7 +208,7 @@ func (h *HaproxyHelper) handleUseCorpusCmd(ctx context.Context, cmd *LbagentCmd)
198208 p := filepath .Join (dir , "telegraf.conf" )
199209 err := os .WriteFile (p , d , agentutils .FileModeFile )
200210 if err == nil {
201- err := h .reloadTelegraf (ctx , agentParams )
211+ err := h .reloadTelegraf (ctx , agentParams , tsdbSrc )
202212 if err != nil {
203213 log .Errorf ("reloading telegraf.conf failed: %s" , err )
204214 }
@@ -420,15 +430,15 @@ func (h *HaproxyHelper) telegrafPidFile() *agentutils.PidFile {
420430 return pf
421431}
422432
423- func (h * HaproxyHelper ) reloadTelegraf (ctx context.Context , agentParams * agentmodels.AgentParams ) error {
433+ func (h * HaproxyHelper ) reloadTelegraf (ctx context.Context , agentParams * agentmodels.AgentParams , tsdbSrc * tsdb. TSDBServiceSource ) error {
424434 if h .opts .EnableRemoteExecutor {
425- return h .remoteReloadTelegraf (ctx , agentParams )
435+ return h .remoteReloadTelegraf (ctx , agentParams , tsdbSrc )
426436 } else {
427437 return h .localReloadTelegraf (ctx )
428438 }
429439}
430440
431- func (h * HaproxyHelper ) remoteReloadTelegraf (ctx context.Context , agentParams * agentmodels.AgentParams ) error {
441+ func (h * HaproxyHelper ) remoteReloadTelegraf (ctx context.Context , agentParams * agentmodels.AgentParams , tsdbSrc * tsdb. TSDBServiceSource ) error {
432442 telegraf := system_service .GetService ("telegraf" )
433443 conf := map [string ]interface {}{}
434444 conf ["hostname" ] = h .getHostname ()
@@ -442,7 +452,13 @@ func (h *HaproxyHelper) remoteReloadTelegraf(ctx context.Context, agentParams *a
442452 hostconsts .TELEGRAF_TAG_KEY_HOST_TYPE : hostconsts .TELEGRAF_TAG_ONECLOUD_HOST_TYPE_LBAGENT ,
443453 }
444454 conf ["nics" ] = h .getNicsTelegrafConf ()
445- if len (agentParams .AgentModel .Params .Telegraf .InfluxDbOutputUrl ) > 0 {
455+ if tsdbSrc != nil && len (tsdbSrc .URLs ) > 0 {
456+ conf [apis .SERVICE_TYPE_INFLUXDB ] = map [string ]interface {}{
457+ "url" : tsdbSrc .URLs ,
458+ "database" : agentParams .AgentModel .Params .Telegraf .InfluxDbOutputName ,
459+ "tsdb_type" : tsdbSrc .Type ,
460+ }
461+ } else if len (agentParams .AgentModel .Params .Telegraf .InfluxDbOutputUrl ) > 0 {
446462 conf [apis .SERVICE_TYPE_INFLUXDB ] = map [string ]interface {}{
447463 "url" : []string {
448464 agentParams .AgentModel .Params .Telegraf .InfluxDbOutputUrl ,
@@ -452,13 +468,13 @@ func (h *HaproxyHelper) remoteReloadTelegraf(ctx context.Context, agentParams *a
452468 }
453469 conf ["haproxy" ] = map [string ]interface {}{
454470 "interval" : agentParams .AgentModel .Params .Telegraf .HaproxyInputInterval ,
455- "stats_socket_path" : h .haproxyStatsSocketFile (),
471+ "stats_socket_path" : filepath . Join ( "/hostfs" , h .haproxyStatsSocketFile () ),
456472 }
457473 oldConf := telegraf .GetConf ()
458474 log .Debugf ("old config: %s" , oldConf )
459475 log .Debugf ("new config: %s" , conf )
460476 if gotypes .IsNil (oldConf ) || ! reflect .DeepEqual (oldConf , conf ) {
461- log .Debugf ("telegraf config: %s" , conf )
477+ log .Debugf ("telegraf config: %s" , telegraf . GetConfig ( conf ) )
462478 telegraf .SetConf (conf )
463479 telegraf .BgReloadConf (conf )
464480 }
0 commit comments