Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # Copyright 2015-present Open Networking Foundation |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | # ----------------------------------------------------------------------------- |
| 20 | # Tool to collect cluster-wide diagnostics into a single tar stream. |
| 21 | # ----------------------------------------------------------------------------- |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 22 | |
| 23 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| 24 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 25 | |
| 26 | . $(dirname $0)/_find-node |
| 27 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 28 | function usage() { |
| 29 | echo "usage: $(basename $0) [-x] [-n name] [-u user] [-p password] [ip1 ip2...]" |
| 30 | echo "" |
| 31 | echo "Environment Variables:" |
| 32 | echo " ONOS_INSTANCES IPs or hostnames of ONOS cluster machines" |
| 33 | echo " ONOS_WEB_USER username for REST API" |
| 34 | echo " ONOS_WEB_PASS password for REST API" |
| 35 | echo "" |
| 36 | echo "Example Usages:" |
| 37 | echo " # Collect compressed diagnostics for the cluster." |
| 38 | echo " # REST API user and password are drawn from environment variables." |
| 39 | echo " # Collection archive will be named /tmp/onos-diags.tar.gz" |
| 40 | echo " # The cluster node IPs will be drawn from ONOS_INSTANCES variable." |
| 41 | echo " > $(basename $0) " |
| 42 | echo "" |
| 43 | echo " # Collect diagnostics for the cluster and leave them extracted. " |
| 44 | echo " # Collection directory will be named /tmp/prague-diags/" |
| 45 | echo " # Collection archive will be named /tmp/prague-diags.tar.gz." |
| 46 | echo " # REST API user name is 'onos' and password is 'rules'." |
| 47 | echo " # The cluster node IPs will be drawn from ONOS_INSTANCES variable." |
| 48 | echo " > $(basename $0) -x -n prague -u onos -p rules" |
| 49 | echo "" |
| 50 | echo " # Collect compressed diagnostics for a cluster." |
| 51 | echo " # REST API user name is 'onos' and password is 'rules'." |
| 52 | echo " # Collection archive will be named /tmp/onos-diags.tar.gz" |
| 53 | echo " # The cluster node IPs are listed explicitly." |
| 54 | echo " > $(basename $0) -u onos -p rules 172.17.0.11 172.17.0.12 172.17.0.13" |
| 55 | |
| 56 | exit 1 |
| 57 | } |
| 58 | |
| 59 | CLI_COMMANDS=( |
Thomas Vachuska | a40aa0b | 2018-02-01 15:52:10 -0800 | [diff] [blame] | 60 | "feature:repo-list" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 61 | "feature:list" |
| 62 | "bundle:list" |
| 63 | "scr:list" |
| 64 | |
| 65 | "summary" |
| 66 | "nodes" |
| 67 | "apps -s" |
| 68 | "netcfg" |
| 69 | "cfg get" |
| 70 | |
| 71 | "devices" |
| 72 | "links" |
| 73 | "hosts" |
| 74 | |
| 75 | "ports -e" |
| 76 | "portstats -nz" |
| 77 | |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 78 | "packet-processors" |
| 79 | "packet-requests" |
| 80 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 81 | "intents" |
| 82 | "flows -s" |
| 83 | "groups" |
| 84 | |
| 85 | "roles" |
| 86 | "masters" |
| 87 | |
| 88 | "routes" |
| 89 | "obj-next-ids" |
| 90 | "obj-pending-nexts" |
| 91 | |
| 92 | "log:display -l WARN" |
| 93 | ) |
| 94 | |
| 95 | # Scan arguments for user/password or other options... |
| 96 | while getopts n:u:p:x?h o; do |
| 97 | case "$o" in |
| 98 | n) name=$OPTARG;; |
| 99 | u) user=$OPTARG;; |
| 100 | p) password=$OPTARG;; |
| 101 | x) extract=true;; |
| 102 | *) usage;; |
| 103 | esac |
| 104 | done |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 105 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 106 | user=${user:-$ONOS_WEB_USER} |
| 107 | password=${password:-$ONOS_WEB_PASS} |
| 108 | let OPC=$OPTIND-1 |
| 109 | shift $OPC |
| 110 | |
| 111 | [ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage; |
| 112 | |
| 113 | diags=/tmp/${name:-onos}-diags |
| 114 | rm -fr $diags $diags.tar.gz; mkdir -p $diags |
| 115 | |
| 116 | [ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$* |
| 117 | |
| 118 | # Collect diagnostics from each cluster node |
| 119 | for node in $nodes; do |
| 120 | printf "Collecting diagnostics on $node..." |
| 121 | |
| 122 | # Prepare a clean place for collecting the node diagnostic data |
| 123 | cd $diags; rm -fr $node; mkdir -p $node; cd $node; |
| 124 | |
| 125 | # Acquire locally obtained diagnostics via REST API and extract them |
| 126 | printf "logs " |
| 127 | curl -sS --fail --user $user:$password \ |
| 128 | http://$node:8181/onos/v1/diagnostics > ../$node.tar.gz |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame^] | 129 | tar zxf ../$node.tar.gz && rm ../$node.tar.gz |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 130 | |
| 131 | # Acquire remotely obtained diagnostics via ssh CLI |
| 132 | for cmd in "${CLI_COMMANDS[@]}"; do |
| 133 | cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt" |
| 134 | printf "$cmdLog " |
| 135 | onos $node $cmd 2>/dev/null >$cmdLog |
| 136 | done |
| 137 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 138 | printf " Done.\n" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 139 | done |
| 140 | |
| 141 | # Tar-up diagnostics from all the nodes |
| 142 | cd $diags |
| 143 | tar zcf $diags.tar.gz * |
| 144 | [ -z $extract ] && rm -fr $diags |