metrics-viewer

command module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

JFrog CLI metrics-viewer Plugin

A plugin or standalone binary to show open-metrics formatted data in a terminal based graph.

  • JFrog Artifactory The Metrics Viewer Graph - single metric

  • JFrog Metadata (multiple metrics) The Metrics Viewer Graph - multiple metrics

About this plugin

This JFrog CLI plugin is for viewing JFrog products metrics in real time in a terminal.

Building from source

To build the metrics-viewer binary

go build

To build the metrics-viewer binary for multiple operating systems and architectures (Mac, Linux and Windows)

./build-binary.sh

Testing the code

# Just run the tests
go test ./...

# Run the tests and create a coverage report
mkdir -p out && go test -coverprofile=out/coverage.out ./... && go tool cover -html=out/coverage.out

Building a Docker image

To build the metrics-viewer into a Docker image and use it

# Build the Docker image
docker build -t metrics-viewer:0.2.1 .

# Test the Docker image
docker run --rm metrics-viewer:0.2.1 --version

Installation of local binary with JFrog CLI

If you don't want to install the plugin from the JFrog CLI Plugins Registry, it needs to be built and installed manually.

Follow these steps to install and use this plugin with JFrog CLI.

  1. Make sure JFrog CLI is installed on you machine by running jfrog. If it is not installed, install it.
  2. Create a directory named plugins under ~/.jfrog/ if it does not exist already.
  3. Clone this repository.
  4. CD into the root directory of the cloned project.
  5. Run go build to create the binary in the current directory.
  6. Copy the binary into the ~/.jfrog/plugins directory.

Installation with JFrog CLI (when plugin is in the JFrog CLI Plugins Registry)

Installing the latest version:

jfrog plugin install metrics-viewer

Installing a specific version:

jfrog plugin install metrics-viewer@version

Uninstalling a plugin

jfrog plugin uninstall metrics-viewer

Artifactory Metrics

You can view Artifactory Metrics in various ways. To try it out, you can run Artifactory as Docker container.

  • Start Artifactory as Docker container and enable its metrics
docker run --rm -d --name artifactory \
    -p 8082:8082 \
    -e JF_SHARED_METRICS_ENABLED=true \
    -v $(pwd)/artifactory:/var/opt/jfrog/artifactory/ docker.bintray.io/jfrog/artifactory-oss
# See the metrics log files
cat artifactory/log/artifactory-metrics.log
cat artifactory/log/metadata-metrics.log

# Get the metrics from Artifactory REST API
curl -s -uadmin:password http://localhost:8082/artifactory/api/v1/metrics

Usage

Commands
As JFrog CLI plugin

The metrics-viewer can be run as a JFrog CLI Plugin or directly as a binary

  • Usage
jfrog metrics-viewer <command> [options]
  • Commands: See available commands by just running the binary
jfrog metrics-viewer
jfrog metrics-viewer help
  • Options: To see available options for each command, call it with the help
jfrog metrics-viewer help graph 
jfrog metrics-viewer help print 
As a standalone binary
  • Usage
./metrics-viewer <command> [options]
  • Commands: See available commands by just running the binary
./metrics-viewer
./metrics-viewer help
  • Options: To see available options for each command, call it with the help
./metrics-viewer help graph 
./metrics-viewer help print 
Examples as JFrog CLI plugin
  • Using the metrics-viewer binary
# Use with the default Artifactory that is configured by the JFrog CLI
jfrog metrics-viewer graph

# Use with direct Artifactory metrics API URL
jfrog metrics-viewer graph --url http://localhost:8082/artifactory/api/v1/metrics --user admin --password password

# Use with direct Metadata metrics API URL (NOTE: must get an access token from Artifactory)
jfrog metrics-viewer graph --url http://localhost:8082/metadata/api/v1/metrics --token ${TOKEN}

# Print metrics of the default Artifactory that is configured by the JFrog CLI
jfrog metrics-viewer print

# Print metrics of the "art17" Artifactory with name matching the "app_" filter
jfrog metrics-viewer print --server-id art17 --filter 'app_.*'

# Print selected Artifactory metrics as CSV
jfrog metrics-viewer print --url http://localhost:8082/artifactory/api/v1/metrics --user admin --password password \
    --format csv --metrics jfrt_runtime_heap_totalmemory_bytes,jfrt_db_connections_active_total
Examples as standalone binary
  • Using the metrics-viewer binary
# Use with the default Artifactory that is configured by the JFrog CLI
./metrics-viewer graph

# Use with direct Artifactory metrics API URL
./metrics-viewer graph --url http://localhost:8082/artifactory/api/v1/metrics --user admin --password password

# Use with direct Metadata metrics API URL (NOTE: must get an access token from Artifactory)
./metrics-viewer graph --url http://localhost:8082/metadata/api/v1/metrics --token ${TOKEN}

# Print metrics of the default Artifactory that is configured by the JFrog CLI
./metrics-viewer print

# Print metrics of the "art17" Artifactory with name matching the "app_" filter
./metrics-viewer print --server-id art17 --filter 'app_.*'

# Print selected Artifactory metrics as CSV
./metrics-viewer print --url http://localhost:8082/artifactory/api/v1/metrics --user admin --password password \
    --format csv --metrics jfrt_runtime_heap_totalmemory_bytes,jfrt_db_connections_active_total
  • Using the Docker image
# Use with direct Artifactory metrics API URL
# NOTE: The server URL has to be accessible from within the Docker container
docker run --rm --name metrics-viewer metrics-viewer:0.1 \
    graph --url http://artifactory-server/artifactory/api/v1/metrics --user admin --password password

# Print specific metrics as CSV
# NOTE: The Docker container needs to access the file system for the logs, so need to mount it into the container 
docker run --rm --name metrics-viewer -v $(pwd)/artifactory:/artifactory metrics-viewer:0.1 \
    print --file /artifactory/log/artifactory-metrics.log \
    --format csv --metrics jfrt_runtime_heap_freememory_bytes,jfrt_runtime_heap_totalmemory_bytes
The Viewer

Once running, the viewer will show 3 main sections

  • Left pane: List of available metrics
  • Center pane: Graph of selected metrics
  • Right pane: Selected metrics Max, Min and Current values
Keys
  • Up/Down arrow keys: Move between available metrics
  • Space/Enter: Select/Deselect metric to view
  • Free text: Apply text filter on available metrics
  • Ctrl+C: Close metrics-viewer

Release Notes

The release notes are available here.

Contributions

A big THANK YOU to the real developers here for joining me for this idea!

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL