Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stats functions #12

Merged
merged 5 commits into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,33 @@ app.get('/container/:containerId/start', function (req, res) {
});


/**
* Stats the container by the ID specified
*/
app.get('/container/:containerId/stats', function (req, res) {
var containerId = req.params.containerId;
console.log("Getting Stats for " + containerId);
var opts= new Object();
opts.stream = false
getContainer(containerId, function (container) {
docker.getContainer(container.Id).stats(opts, function (err, data) {
if (err) {
res.status(500);
res.send(err);
return;
}
res.status(200); //We found the container! This reponse can be trusted
res.send(data);
});
}, function (status, message) {
res.status(status);
if (message) {
res.send(message);
}
})
});


/**
* Stop the container by the ID specified
*/
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ As of this release, you can:

* Get the status of a container (running, stopped).
* Start or stop a container by issuing a `POST` request.
* Start or stop a container by issuing a `GET` requst.
* Restart a container by making a `GET` request to a URL for the container (details below).
* Execute commands inside a container using the `/exec` endpoint of a container.

## Getting Started

Expand Down Expand Up @@ -76,7 +78,7 @@ You can run this service directly from a host that has NPM and NodeJS installed.
## Using this service

### HTTP Endpoints
This service exposes two HTTP endpoints
This service exposes the following HTTP endpoints

#### GET /container/{container name}

Expand Down Expand Up @@ -210,5 +212,11 @@ switch:
is_on_template: '{{ value_json is not none and value_json.state == "running" }}'
```

### Home Assistant Custom Component

Thanks to [Joakim Sørensen (@ludeeus)](https://github.com/ludeeus) you can use a custom Home Assistant Component, which can automatically add switches to your Home Assistant instance from Dockermon.

You can get the custom component [here](https://github.com/ludeeus/custom_component_hadockermon).

# Further Reading
For more in-depth Home Assistant examples and some ideas for use, please check out [this article on my blog](https://philhawthorne.com/ha-dockermon-use-home-assistant-to-monitor-start-or-stop-docker-containers).