Skip to content

Instantly share code, notes, and snippets.

@fxpires
Forked from redmcg/kubedf
Created December 12, 2019 19:43
Show Gist options
  • Select an option

  • Save fxpires/e70b924e357d16de5a57ecc5792460b8 to your computer and use it in GitHub Desktop.

Select an option

Save fxpires/e70b924e357d16de5a57ecc5792460b8 to your computer and use it in GitHub Desktop.

Revisions

  1. @redmcg redmcg revised this gist Nov 20, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kubedf
    Original file line number Diff line number Diff line change
    @@ -40,5 +40,5 @@ else
    fi

    for node in $(getNodes); do
    curl -s 127.0.0.1:8001/api/v1/nodes/$node/proxy/stats/summary
    curl -s $KUBEAPI/$node/proxy/stats/summary
    done | getPVCs | format
  2. @redmcg redmcg revised this gist Oct 22, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kubedf
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    KUBEAPI=127.0.0.1:8001/api/v1/nodes

    function getNodes() {
    curl -s $KUBEAPI | jq '.items[].metadata.name' | sed 's/^"\|"$//g'
    curl -s $KUBEAPI | jq -r '.items[].metadata.name'
    }

    function getPVCs() {
    @@ -41,4 +41,4 @@ fi

    for node in $(getNodes); do
    curl -s 127.0.0.1:8001/api/v1/nodes/$node/proxy/stats/summary
    done | getPVCs | format
    done | getPVCs | format
  3. @redmcg redmcg created this gist May 8, 2019.
    44 changes: 44 additions & 0 deletions kubedf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/usr/bin/env bash

    KUBEAPI=127.0.0.1:8001/api/v1/nodes

    function getNodes() {
    curl -s $KUBEAPI | jq '.items[].metadata.name' | sed 's/^"\|"$//g'
    }

    function getPVCs() {
    jq -s '[flatten | .[].pods[].volume[]? | select(has("pvcRef")) | '\
    '{name: .pvcRef.name, capacityBytes, usedBytes, availableBytes, '\
    'percentageUsed: (.usedBytes / .capacityBytes * 100)}] | sort_by(.name)'
    }

    function column() {
    awk '{ for (i = 1; i <= NF; i++) { d[NR, i] = $i; w[i] = length($i) > w[i] ? length($i) : w[i] } } '\
    'END { for (i = 1; i <= NR; i++) { printf("%-*s", w[1], d[i, 1]); for (j = 2; j <= NF; j++ ) { printf("%*s", w[j] + 1, d[i, j]) } print "" } }'
    }

    function defaultFormat() {
    awk 'BEGIN { print "PVC 1K-blocks Used Available Use%" } '\
    '{$2 = $2/1024; $3 = $3/1024; $4 = $4/1024; $5 = sprintf("%.0f%%",$5); print $0}'
    }

    function humanFormat() {
    awk 'BEGIN { print "PVC Size Used Avail Use%" } '\
    '{$5 = sprintf("%.0f%%",$5); printf("%s ", $1); system(sprintf("numfmt --to=iec %s %s %s | sed '\''N;N;s/\\n/ /g'\'' | tr -d \\\\n", $2, $3, $4)); print " " $5 }'
    }

    function format() {
    jq '.[] | "\(.name) \(.capacityBytes) \(.usedBytes) \(.availableBytes) \(.percentageUsed)"' |
    sed 's/^"\|"$//g' |
    $format | column
    }

    if [ "$1" == "-h" ]; then
    format=humanFormat
    else
    format=defaultFormat
    fi

    for node in $(getNodes); do
    curl -s 127.0.0.1:8001/api/v1/nodes/$node/proxy/stats/summary
    done | getPVCs | format