-
Notifications
You must be signed in to change notification settings - Fork 0
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
Alessio Treglia
committed
May 25, 2015
0 parents
commit fe09c8d
Showing
6 changed files
with
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Alessio Treglia <[email protected]> |
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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Smartodds Ltd | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
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,30 @@ | ||
# Dokku cAdvisor | ||
|
||
[Google cAdvisor](https://github.com/google/cadvisor) plugin for [dokku](https://github.com/progrium/dokku) | ||
|
||
Simple plugin that adds a `cadvisor` entry to the Dokku's menu to start/stop the service. | ||
|
||
## Installation | ||
|
||
On the Dokku server, install the plugin in the plugins directory and run `dokku plugins-install`: | ||
|
||
``` | ||
cd /var/lib/dokku/plugins | ||
git clone https://github.com/alessio/dokku-cadvisor cadvisor | ||
dokku plugins-install | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
Options: | ||
cadvisor:start Start Google cAdvisor service | ||
cadvisor:stop Stop Google cAdvisor | ||
``` | ||
|
||
## Notes | ||
|
||
After the installation type the following to fire a ready-to-use a container of Google cAdvisor: | ||
``` | ||
dokku cadvisor:start | ||
``` |
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,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
|
||
PLUGIN_DIR=$(dirname $0) | ||
. "$PLUGIN_DIR/../common/functions" | ||
. "$PLUGIN_DIR/lib/helpers" | ||
|
||
case "$1" in | ||
cadvisor:start) | ||
f_dokku_cadvisor_start ;; | ||
|
||
cadvisor:stop) | ||
f_dokku_cadvisor_stop ;; | ||
|
||
help | cadvisor:help) | ||
cat && cat<<EOF | ||
cadvisor:start Start Google cAdvisor service | ||
cadvisor:stop Stop Google cAdvisor | ||
EOF | ||
;; | ||
|
||
*) | ||
exit $DOKKU_NOT_IMPLEMENTED_EXIT | ||
;; | ||
esac | ||
|
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,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
|
||
PLUGIN_DIR=$(dirname $0) | ||
. "$PLUGIN_DIR/lib/helpers" | ||
|
||
f_dokku_cadvisor_install |
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,71 @@ | ||
# Helper functions that can be sourced via "." into the rest of the plugin | ||
|
||
DOKKU_CADVISOR_IMAGE="google/cadvisor:latest" | ||
DOKKU_CADVISOR_CONTAINER=dokku-cadvisor | ||
DOKKU_CADVISOR_DEFAULT_PORT=8080 | ||
DOKKU_CADVISOR_PORT=${DOKKU_CADVISOR_PORT:-$DOKKU_CADVISOR_DEFAULT_PORT} | ||
|
||
f_check_container() { | ||
local l_status | ||
|
||
l_status="$(docker inspect -f '{{.State.Running}}' $DOKKU_CADVISOR_CONTAINER 2>/dev/null)" || l_status=none | ||
printf "%s" "$l_status" | ||
} | ||
|
||
|
||
# Start the container | ||
f_dokku_cadvisor_start() { | ||
case $(f_check_container) in | ||
none) | ||
echo "Starting cAdvisor on port ${DOKKU_CADVISOR_PORT} ..." | ||
docker run \ | ||
--volume=/:/rootfs:ro \ | ||
--volume=/var/run:/var/run:rw \ | ||
--volume=/sys:/sys:ro \ | ||
--volume=/var/lib/docker/:/var/lib/docker:ro \ | ||
--publish=$DOKKU_CADVISOR_PORT:8080 \ | ||
--detach=true \ | ||
--name=$DOKKU_CADVISOR_CONTAINER \ | ||
$DOKKU_CADVISOR_IMAGE \ | ||
> /dev/null | ||
;; | ||
false) | ||
echo "Starting cAdvisor on port ${DOKKU_CADVISOR_PORT} ..." | ||
docker start $DOKKU_CADVISOR_CONTAINER >/dev/null | ||
;; | ||
*) | ||
echo "cAdvisor is already running" | ||
;; | ||
esac | ||
} | ||
|
||
|
||
# Stop the container | ||
f_dokku_cadvisor_stop() { | ||
case $(f_check_container) in | ||
true) | ||
echo "Stopping cAdvisor ..." | ||
docker stop $DOKKU_CADVISOR_CONTAINER >/dev/null | ||
;; | ||
*) | ||
echo "cAdvisor is not running" | ||
;; | ||
esac | ||
} | ||
|
||
|
||
# Pull cAdvisor image | ||
f_dokku_cadvisor_install() { | ||
docker pull $DOKKU_CADVISOR_IMAGE >/dev/null | ||
case $(f_check_container) in | ||
true) | ||
f_dokku_cadvisor_stop | ||
docker rm $DOKKU_CADVISOR_CONTAINER >/dev/null | ||
f_dokku_cadvisor_start | ||
;; | ||
false) | ||
docker rm $DOKKU_CADVISOR_CONTAINER >/dev/null | ||
;; | ||
*) ;; | ||
esac | ||
} |