This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!-- | ||
title: "Docker monitoring with Netdata" | ||
description: "Monitor Docker containers health metrics." | ||
custom_edit_url: https://github.com/netdata/go.d.plugin/edit/master/modules/docker/README.md | ||
sidebar_label: "Docker" | ||
--> | ||
|
||
# Docker monitoring with Netdata | ||
|
||
[Docker Engine](https://docs.docker.com/engine/) is an open source containerization technology for building and | ||
containerizing your applications. | ||
|
||
This module monitors one or more Docker Engine instances, depending on your configuration. | ||
|
||
## Configuration | ||
|
||
Edit the `go.d/docker.conf` configuration file using `edit-config` from the | ||
Netdata [config directory](https://learn.netdata.cloud/docs/configure/nodes), which is typically at `/etc/netdata`. | ||
|
||
```bash | ||
cd /etc/netdata # Replace this path with your Netdata config directory | ||
sudo ./edit-config go.d/docker.conf | ||
``` | ||
|
||
```yaml | ||
jobs: | ||
- name: local | ||
address: 'unix:///var/run/docker.sock' | ||
|
||
- name: remote | ||
address: 'tcp://203.0.113.10:9323' | ||
``` | ||
For all available options see | ||
module [configuration file](https://github.com/netdata/go.d.plugin/blob/master/config/go.d/docker.conf). | ||
## Troubleshooting | ||
To troubleshoot issues with the `docker` collector, run the `go.d.plugin` with the debug option enabled. The output | ||
should give you clues as to why the collector isn't working. | ||
|
||
First, navigate to your plugins' directory, usually at `/usr/libexec/netdata/plugins.d/`. If that's not the case on your | ||
system, open `netdata.conf` and look for the setting `plugins directory`. Once you're in the plugin's directory, switch | ||
to the `netdata` user. | ||
|
||
```bash | ||
cd /usr/libexec/netdata/plugins.d/ | ||
sudo -u netdata -s | ||
``` | ||
|
||
You can now run the `go.d.plugin` to debug the collector: | ||
|
||
```bash | ||
./go.d.plugin -d -m docker | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package docker | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
dockerClient "github.com/docker/docker/client" | ||
) | ||
|
||
func (d *Docker) collect() (map[string]int64, error) { | ||
if d.client == nil { | ||
client, err := dockerClient.NewClientWithOpts() | ||
if err != nil { | ||
return nil, err | ||
} | ||
d.client = client | ||
} | ||
|
||
defer d.client.Close() | ||
|
||
info, err := d.client.Info(context.Background()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fmt.Println(info.Containers, info.ContainersRunning, info.ContainersPaused, info.ContainersStopped) | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package docker | ||
|
||
import ( | ||
"github.com/netdata/go.d.plugin/agent/module" | ||
|
||
dockerClient "github.com/docker/docker/client" | ||
) | ||
|
||
func init() { | ||
module.Register("docker", module.Creator{ | ||
Create: func() module.Module { return New() }, | ||
}) | ||
} | ||
|
||
func New() *Docker { | ||
return &Docker{} | ||
} | ||
|
||
type Config struct { | ||
} | ||
|
||
type Docker struct { | ||
module.Base | ||
Config `yaml:",inline"` | ||
|
||
client *dockerClient.Client | ||
} | ||
|
||
func (d *Docker) Init() bool { | ||
return true | ||
} | ||
|
||
func (d *Docker) Check() bool { | ||
return len(d.Collect()) > 0 | ||
} | ||
|
||
func (d *Docker) Charts() *module.Charts { | ||
return nil | ||
} | ||
|
||
func (d *Docker) Collect() map[string]int64 { | ||
mx, err := d.collect() | ||
if err != nil { | ||
d.Error(err) | ||
} | ||
|
||
if len(mx) == 0 { | ||
return nil | ||
} | ||
return mx | ||
} | ||
|
||
func (d *Docker) Cleanup() { | ||
if d.client == nil { | ||
return | ||
} | ||
if err := d.client.Close(); err != nil { | ||
d.Warningf("error on closing docker client: %v", err) | ||
} | ||
d.client = nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters