Skip to content
Snippets Groups Projects
docker_stats_script.sh 730 B
Newer Older
  • Learn to ignore specific revisions
  • Fabian Seidl's avatar
    Fabian Seidl committed
    #!/bin/bash
    
    container=""
    output=""
    
    # trap ctrl-c and call ctrl_c()
    trap ctrl_c INT
    
    function ctrl_c() {
            echo "Done writing file"
            exit
    }
    
    while getopts ":c:o:" opt; do
        case $opt in
            c)
                container="$OPTARG"
                echo "Container: $container"
                ;;
            o)
                output="$OPTARG"
                echo "Output: $output"
                ;;
            \?)
                echo "wrong flag"
                exit 1
                ;;
            :)
                echo "Option -$OPTARG requires an argument."
                exit 1
                ;;
        esac
    done
    
    echo "Starting docker stats"
    
    while true
    do
        echo "`date -u` `docker stats -a --no-stream --format "{{ json . }}" $container`" >> $output
    done