github.com/pvitto98/fabric@v2.1.1+incompatible/scripts/metrics_doc.sh (about)

     1  #!/bin/bash -e
     2  
     3  # Copyright IBM Corp All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  
     7  fabric_dir="$(cd "$(dirname "$0")/.." && pwd)"
     8  metrics_doc="${fabric_dir}/docs/source/metrics_reference.rst"
     9  
    10  generate_doc() {
    11      local gendoc_command="go run github.com/hyperledger/fabric/common/metrics/cmd/gendoc"
    12      local orderer_prom
    13      local orderer_statsd
    14      local peer_prom
    15      local peer_statsd
    16  
    17      local orderer_deps=()
    18      while IFS= read -r pkg; do orderer_deps+=("$pkg"); done < <(go list -deps github.com/hyperledger/fabric/cmd/orderer | sort -u | grep hyperledger)
    19      orderer_prom="$($gendoc_command -template <(echo '{{PrometheusTable}}') "${orderer_deps[@]}")"
    20      orderer_statsd="$($gendoc_command -template <(echo '{{StatsdTable}}') "${orderer_deps[@]}")"
    21  
    22      local peer_deps=()
    23      while IFS= read -r pkg; do peer_deps+=("$pkg"); done < <(go list -deps github.com/hyperledger/fabric/cmd/peer | sort -u | grep hyperledger)
    24      peer_prom="$($gendoc_command -template <(echo '{{PrometheusTable}}') "${peer_deps[@]}")"
    25      peer_statsd="$($gendoc_command -template <(echo '{{StatsdTable}}') "${peer_deps[@]}")"
    26  
    27  cat <<eof
    28  Metrics Reference
    29  =================
    30  
    31  Orderer Metrics
    32  ---------------
    33  
    34  Prometheus
    35  ~~~~~~~~~~
    36  
    37  The following orderer metrics are exported for consumption by Prometheus.
    38  
    39  ${orderer_prom}
    40  
    41  StatsD
    42  ~~~~~~
    43  
    44  The following orderer metrics are emitted for consumption by StatsD. The
    45  \`\`%{variable_name}\`\` nomenclature represents segments that vary based on
    46  context.
    47  
    48  For example, \`\`%{channel}\`\` will be replaced with the name of the channel
    49  associated with the metric.
    50  
    51  ${orderer_statsd}
    52  
    53  Peer Metrics
    54  ------------
    55  
    56  Prometheus
    57  ~~~~~~~~~~
    58  
    59  The following peer metrics are exported for consumption by Prometheus.
    60  
    61  ${peer_prom}
    62  
    63  StatsD
    64  ~~~~~~
    65  
    66  The following peer metrics are emitted for consumption by StatsD. The
    67  \`\`%{variable_name}\`\` nomenclature represents segments that vary based on
    68  context.
    69  
    70  For example, \`\`%{channel}\`\` will be replaced with the name of the channel
    71  associated with the metric.
    72  
    73  ${peer_statsd}
    74  
    75  .. Licensed under Creative Commons Attribution 4.0 International License
    76     https://creativecommons.org/licenses/by/4.0/
    77  eof
    78  }
    79  
    80  
    81  case "$1" in
    82      # check if the metrics documentation is up to date with the metrics
    83      # options in the tree
    84      "check")
    85          if [ -n "$(diff -u <(generate_doc) "${metrics_doc}")" ]; then
    86              echo "The Fabric metrics reference documentation is out of date."
    87              echo "Please run '$0 generate' to update the documentation."
    88              exit 1
    89          fi
    90          ;;
    91  
    92      # generate the metrics documentation
    93      "generate")
    94           generate_doc > "${metrics_doc}"
    95          ;;
    96  
    97      *)
    98          echo "Please specify check or generate"
    99          exit 1
   100          ;;
   101  esac