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 | |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame^] | 59 | # TODO We should make SR commands optional |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 60 | CLI_COMMANDS=( |
Thomas Vachuska | a40aa0b | 2018-02-01 15:52:10 -0800 | [diff] [blame] | 61 | "feature:repo-list" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 62 | "feature:list" |
| 63 | "bundle:list" |
| 64 | "scr:list" |
| 65 | |
| 66 | "summary" |
| 67 | "nodes" |
| 68 | "apps -s" |
| 69 | "netcfg" |
| 70 | "cfg get" |
| 71 | |
| 72 | "devices" |
| 73 | "links" |
| 74 | "hosts" |
| 75 | |
| 76 | "ports -e" |
| 77 | "portstats -nz" |
| 78 | |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 79 | "packet-processors" |
| 80 | "packet-requests" |
| 81 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 82 | "intents" |
| 83 | "flows -s" |
| 84 | "groups" |
| 85 | |
| 86 | "roles" |
| 87 | "masters" |
| 88 | |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame^] | 89 | "fpm-connections" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 90 | "routes" |
| 91 | "obj-next-ids" |
| 92 | "obj-pending-nexts" |
| 93 | |
Charles Chan | c6576fa | 2018-03-08 14:59:42 -0800 | [diff] [blame^] | 94 | "sr-device-subnets" |
| 95 | "sr-ecmp-spg" |
| 96 | "sr-link-state" |
| 97 | "sr-mcast-next" |
| 98 | "sr-mcast-tree" |
| 99 | "sr-next-hops" |
| 100 | "pseudowires" |
| 101 | "dhcp-relay" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 102 | ) |
| 103 | |
| 104 | # Scan arguments for user/password or other options... |
| 105 | while getopts n:u:p:x?h o; do |
| 106 | case "$o" in |
| 107 | n) name=$OPTARG;; |
| 108 | u) user=$OPTARG;; |
| 109 | p) password=$OPTARG;; |
| 110 | x) extract=true;; |
| 111 | *) usage;; |
| 112 | esac |
| 113 | done |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 114 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 115 | user=${user:-$ONOS_WEB_USER} |
| 116 | password=${password:-$ONOS_WEB_PASS} |
| 117 | let OPC=$OPTIND-1 |
| 118 | shift $OPC |
| 119 | |
| 120 | [ $# -lt 1 -a -z "$ONOS_INSTANCES" ] && usage; |
| 121 | |
| 122 | diags=/tmp/${name:-onos}-diags |
| 123 | rm -fr $diags $diags.tar.gz; mkdir -p $diags |
| 124 | |
| 125 | [ -z $1 ] && nodes=$ONOS_INSTANCES || nodes=$* |
| 126 | |
| 127 | # Collect diagnostics from each cluster node |
| 128 | for node in $nodes; do |
| 129 | printf "Collecting diagnostics on $node..." |
| 130 | |
| 131 | # Prepare a clean place for collecting the node diagnostic data |
| 132 | cd $diags; rm -fr $node; mkdir -p $node; cd $node; |
| 133 | |
| 134 | # Acquire locally obtained diagnostics via REST API and extract them |
| 135 | printf "logs " |
| 136 | curl -sS --fail --user $user:$password \ |
| 137 | http://$node:8181/onos/v1/diagnostics > ../$node.tar.gz |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 138 | tar zxf ../$node.tar.gz && rm ../$node.tar.gz |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 139 | |
| 140 | # Acquire remotely obtained diagnostics via ssh CLI |
| 141 | for cmd in "${CLI_COMMANDS[@]}"; do |
| 142 | cmdLog="$(echo $cmd | cut -d\ -f1 | sed 's/:/-/g').txt" |
| 143 | printf "$cmdLog " |
| 144 | onos $node $cmd 2>/dev/null >$cmdLog |
| 145 | done |
| 146 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 147 | printf " Done.\n" |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 148 | done |
| 149 | |
| 150 | # Tar-up diagnostics from all the nodes |
| 151 | cd $diags |
| 152 | tar zcf $diags.tar.gz * |
| 153 | [ -z $extract ] && rm -fr $diags |