| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package dockersd |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/plugin/agent/discovery/sd/model" |
| 9 | ) |
| 10 | |
| 11 | type targetGroup struct { |
| 12 | source string |
| 13 | targets []model.Target |
| 14 | } |
| 15 | |
| 16 | func (g *targetGroup) Provider() string { return "sd:docker" } |
| 17 | func (g *targetGroup) Source() string { return g.source } |
| 18 | func (g *targetGroup) Targets() []model.Target { return g.targets } |
| 19 | |
| 20 | type target struct { |
| 21 | model.Base `hash:"ignore"` |
| 22 | |
| 23 | hash uint64 |
| 24 | |
| 25 | ID string |
| 26 | Name string |
| 27 | Image string |
| 28 | Command string |
| 29 | Labels map[string]any |
| 30 | PrivatePort string // Port on the container |
| 31 | PublicPort string // Port exposed on the host |
| 32 | PublicPortIP string // Host IP address that the container's port is mapped to |
| 33 | PortProtocol string |
| 34 | NetworkMode string |
| 35 | NetworkDriver string |
| 36 | IPAddress string |
| 37 | |
| 38 | Address string // "IPAddress:PrivatePort" |
| 39 | } |
| 40 | |
| 41 | func (t *target) TUID() string { |
| 42 | if t.PublicPort != "" { |
| 43 | return fmt.Sprintf("%s_%s_%s_%s_%s_%s", |
| 44 | t.Name, t.IPAddress, t.PublicPortIP, t.PortProtocol, t.PublicPort, t.PrivatePort) |
| 45 | } |
| 46 | if t.PrivatePort != "" { |
| 47 | return fmt.Sprintf("%s_%s_%s_%s", |
| 48 | t.Name, t.IPAddress, t.PortProtocol, t.PrivatePort) |
| 49 | } |
| 50 | return fmt.Sprintf("%s_%s", t.Name, t.IPAddress) |
| 51 | } |
| 52 | |
| 53 | func (t *target) Hash() uint64 { |
| 54 | return t.hash |
| 55 | } |