| 1 | //go:build cgo |
| 2 | |
| 3 | package pmi |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "fmt" |
| 8 | "strings" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/netdata/netdata/go/plugins/pkg/confopt" |
| 12 | "github.com/netdata/netdata/go/plugins/pkg/matcher" |
| 13 | "github.com/netdata/netdata/go/plugins/pkg/web" |
| 14 | "github.com/netdata/netdata/go/plugins/plugin/ibm.d/framework" |
| 15 | "github.com/netdata/netdata/go/plugins/plugin/ibm.d/modules/websphere/common" |
| 16 | "github.com/netdata/netdata/go/plugins/plugin/ibm.d/modules/websphere/pmi/contexts" |
| 17 | pmiproto "github.com/netdata/netdata/go/plugins/plugin/ibm.d/protocols/websphere/pmi" |
| 18 | ) |
| 19 | |
| 20 | func defaultConfig() Config { |
| 21 | return Config{ |
| 22 | Config: framework.Config{ |
| 23 | UpdateEvery: 5, |
| 24 | ObsoletionIterations: 60, |
| 25 | }, |
| 26 | Vnode: "", |
| 27 | HTTPConfig: web.HTTPConfig{ |
| 28 | ClientConfig: web.ClientConfig{ |
| 29 | Timeout: confopt.Duration(5 * time.Second), |
| 30 | }, |
| 31 | }, |
| 32 | PMIStatsType: "extended", |
| 33 | PMIRefreshRate: 60, |
| 34 | PMICustomStatsPaths: nil, |
| 35 | ClusterName: "", |
| 36 | CellName: "", |
| 37 | NodeName: "", |
| 38 | ServerType: "", |
| 39 | CustomLabels: map[string]string{}, |
| 40 | CollectJVMMetrics: confopt.AutoBoolAuto, |
| 41 | CollectThreadPoolMetrics: confopt.AutoBoolAuto, |
| 42 | CollectJDBCMetrics: confopt.AutoBoolAuto, |
| 43 | CollectJCAMetrics: confopt.AutoBoolAuto, |
| 44 | CollectJMSMetrics: confopt.AutoBoolAuto, |
| 45 | CollectWebAppMetrics: confopt.AutoBoolAuto, |
| 46 | CollectSessionMetrics: confopt.AutoBoolAuto, |
| 47 | CollectTransactionMetrics: confopt.AutoBoolAuto, |
| 48 | CollectClusterMetrics: confopt.AutoBoolAuto, |
| 49 | CollectServletMetrics: confopt.AutoBoolAuto, |
| 50 | CollectEJBMetrics: confopt.AutoBoolAuto, |
| 51 | CollectJDBCAdvanced: confopt.AutoBoolAuto, |
| 52 | MaxThreadPools: 50, |
| 53 | MaxJDBCPools: 50, |
| 54 | MaxJCAPools: 50, |
| 55 | MaxJMSDestinations: 50, |
| 56 | MaxApplications: 100, |
| 57 | MaxServlets: 50, |
| 58 | MaxEJBs: 50, |
| 59 | CollectAppsMatching: "", |
| 60 | CollectPoolsMatching: "", |
| 61 | CollectJMSMatching: "", |
| 62 | CollectServletsMatching: "", |
| 63 | CollectEJBsMatching: "", |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func (c *Collector) Init(ctx context.Context) error { |
| 68 | // Propagate job-level overrides into the embedded framework collector before init |
| 69 | if c.Config.ObsoletionIterations != 0 { |
| 70 | c.Collector.Config.ObsoletionIterations = c.Config.ObsoletionIterations |
| 71 | } |
| 72 | if c.Config.UpdateEvery != 0 { |
| 73 | c.Collector.Config.UpdateEvery = c.Config.UpdateEvery |
| 74 | } |
| 75 | if c.Config.CollectionGroups != nil { |
| 76 | c.Collector.Config.CollectionGroups = c.Config.CollectionGroups |
| 77 | } |
| 78 | |
| 79 | c.RegisterContexts(contexts.GetAllContexts()...) |
| 80 | |
| 81 | if err := c.Collector.Init(ctx); err != nil { |
| 82 | return err |
| 83 | } |
| 84 | c.SetImpl(c) |
| 85 | |
| 86 | cfg := c.Config |
| 87 | if cfg.URL == "" { |
| 88 | return fmt.Errorf("url is required") |
| 89 | } |
| 90 | |
| 91 | if cfg.ClientConfig.Timeout == 0 { |
| 92 | c.Config.ClientConfig.Timeout = confopt.Duration(5 * time.Second) |
| 93 | } |
| 94 | |
| 95 | httpCfg := c.HTTPConfig |
| 96 | httpCfg.RequestConfig.URL = strings.TrimSpace(cfg.URL) |
| 97 | |
| 98 | client, err := pmiproto.NewClient(pmiproto.Config{ |
| 99 | URL: httpCfg.RequestConfig.URL, |
| 100 | StatsType: cfg.PMIStatsType, |
| 101 | HTTPConfig: httpCfg, |
| 102 | }) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | c.client = client |
| 107 | |
| 108 | if cfg.CollectAppsMatching != "" { |
| 109 | sel, err := matcher.NewSimplePatternsMatcher(cfg.CollectAppsMatching) |
| 110 | if err != nil { |
| 111 | return err |
| 112 | } |
| 113 | c.appSelector = sel |
| 114 | } |
| 115 | if cfg.CollectPoolsMatching != "" { |
| 116 | sel, err := matcher.NewSimplePatternsMatcher(cfg.CollectPoolsMatching) |
| 117 | if err != nil { |
| 118 | return err |
| 119 | } |
| 120 | c.poolSelector = sel |
| 121 | } |
| 122 | if cfg.CollectJMSMatching != "" { |
| 123 | sel, err := matcher.NewSimplePatternsMatcher(cfg.CollectJMSMatching) |
| 124 | if err != nil { |
| 125 | return err |
| 126 | } |
| 127 | c.jmsSelector = sel |
| 128 | } |
| 129 | if cfg.CollectServletsMatching != "" { |
| 130 | sel, err := matcher.NewSimplePatternsMatcher(cfg.CollectServletsMatching) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | c.servletSelector = sel |
| 135 | } |
| 136 | if cfg.CollectEJBsMatching != "" { |
| 137 | sel, err := matcher.NewSimplePatternsMatcher(cfg.CollectEJBsMatching) |
| 138 | if err != nil { |
| 139 | return err |
| 140 | } |
| 141 | c.ejbSelector = sel |
| 142 | } |
| 143 | |
| 144 | c.identity = common.Identity{ |
| 145 | Cluster: cfg.ClusterName, |
| 146 | Cell: cfg.CellName, |
| 147 | Node: cfg.NodeName, |
| 148 | Server: cfg.ServerType, |
| 149 | } |
| 150 | |
| 151 | return nil |
| 152 | } |
| 153 | |
| 154 | func (c *Collector) Cleanup(context.Context) { |
| 155 | if c.client != nil { |
| 156 | c.client.Close() |
| 157 | } |
| 158 | } |