New creates a new Agent.
(cfg Config)
| 97 | |
| 98 | // New creates a new Agent. |
| 99 | func New(cfg Config) *Agent { |
| 100 | a := &Agent{ |
| 101 | Logger: logger.New().With( |
| 102 | slog.String("component", "agent"), |
| 103 | ), |
| 104 | Name: cfg.Name, |
| 105 | ConfigDir: cfg.PluginConfigDir, |
| 106 | CollectorsConfDir: cfg.CollectorsConfigDir, |
| 107 | ServiceDiscoveryConfigDir: cfg.ServiceDiscoveryConfigDir, |
| 108 | CollectorsConfigWatchPath: cfg.CollectorsConfigWatchPath, |
| 109 | VarLibDir: cfg.VarLibDir, |
| 110 | RunModule: cfg.RunModule, |
| 111 | RunJob: cfg.RunJob, |
| 112 | MinUpdateEvery: cfg.MinUpdateEvery, |
| 113 | IsInsideK8s: cfg.IsInsideK8s, |
| 114 | runModePolicy: cfg.RunModePolicy, |
| 115 | ModuleRegistry: cfg.ModuleRegistry, |
| 116 | DiscoveryProviders: cfg.DiscoveryProviders, |
| 117 | Out: safewriter.Stdout, |
| 118 | api: netdataapi.New(safewriter.Stdout), |
| 119 | quitCh: make(chan struct{}, 1), |
| 120 | auditDuration: cfg.AuditDuration, |
| 121 | auditSummary: cfg.AuditSummary, |
| 122 | DisableServiceDiscovery: cfg.DisableServiceDiscovery, |
| 123 | } |
| 124 | |
| 125 | if a.auditDuration > 0 { |
| 126 | a.auditAnalyzer = metricsaudit.New() |
| 127 | a.Infof("metrics-audit mode enabled: will run for %v and analyze metric structure", a.auditDuration) |
| 128 | if a.auditSummary { |
| 129 | a.Infof("metrics-audit summary enabled: will show consolidated summary across all jobs") |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if cfg.AuditDataDir != "" { |
| 134 | a.auditDataDir = cfg.AuditDataDir |
| 135 | if a.auditAnalyzer == nil { |
| 136 | a.auditAnalyzer = metricsaudit.New() |
| 137 | } |
| 138 | a.auditAnalyzer.EnableDataCapture(cfg.AuditDataDir, a.signalAuditComplete) |
| 139 | a.Infof("metrics-audit data directory: %s", cfg.AuditDataDir) |
| 140 | } |
| 141 | |
| 142 | return a |
| 143 | } |
| 144 | |
| 145 | // RunContext runs one agent instance lifecycle on the provided context. |
| 146 | func (a *Agent) RunContext(ctx context.Context) { |