# Quick Start

## Introduction

### What is the Traffic Parrot License Server?

The license server allows Traffic Parrot instances to start up and make use of the licenses that were purchased.

Each Traffic Parrot instance will consume one of the purchased licenses until it is shut down.

There are 3 key states of a Traffic Parrot instance when connecting to the usage server:

1. Check out a license on startup
2. (optional) Keep alive a license if it is used for an extended period
3. Check in a license on shutdown (waits for check in before shutting down)

### Architecture

Each Traffic Parrot instance connects to the Traffic Parrot License Server to check out a license on startup.

![Traffic Parrot License Server Architecture](https://trafficparrot.com/documentation/license/1.17.x/img/license-server-architecture.png)

## First Steps

### Prerequisites

Traffic Parrot License Server has the following minimum requirements. Customers with a large number of Traffic Parrot instances or with intensive usage may exceed these minimum requirements.

- 256MB RAM
- 1GB persistent volume (SSD recommended)
- Host with 24/7 availability
- Host accessible from all Traffic Parrot instances
- Each purchased license pool must be used with a separate single license server instance

### Installation

1. You will have received links containing the license server installation files. Please download the `.zip` file for your corresponding operating system.
2. Transfer the `.zip` file to the host machine and extract the contents. You will have a folder with a name starting with `trafficparrot-license-usage-*`.
3. Configure `licenseusage.properties` with:
   - The persistent volume data directory location e.g. `license.data.directory=data`

   - The UI HTTP port e.g.

     ```
     user.interface.port=8050
     user.interface.port.enabled=true
     ```

   - (optional) The UI HTTPS port and certificates e.g.

     ```
     user.interface.https.port=8051
     user.interface.https.port.enabled=true
     user.interface.https.jks.path=certs/user-interface-https.jks
     user.interface.https.jks.password=trafficparrot
     ```

   - The usage port that Traffic Parrot will connect to e.g.

     ```
     license.usage.port=8040
     license.usage.port.ssl.enabled=true
     ```

   - It is also possible for Traffic Parrot to connect to the UI port on path `/api/usage` if you need to use a single port for both the UI and license usage

   - The number of minutes before a license is released if Traffic Parrot loses connectivity to the license server e.g. `license.time.out.in.minutes=5`
4. Place a copy of your `trafficparrot.usage.license` file in the usage server working directory
5. Deploy the license usage server as a 24/7 application somewhere in your network that is visible to all Traffic Parrot instances
6. The start script will launch the license server in a foreground process. To detach the process you can use commands:
   - `nohup ./start.sh >nohup.out 2>&1 </dev/null &` on Linux
   - Task Scheduler or [NSSM](http://nssm.cc/) service helper on Windows

### Running in Docker

You may optionally use Docker to run the license server using the following steps:

1. Copy the `trafficparrot-license-usage-*.zip` release to the current directory.

   - We recommend to use the bundled JRE distribution we provide per OS, which means you do not need a base image with Java installed. Linux is typically used for Docker.
   - The examples below show how to use a Java base image, in case you are using the no-JRE bundle

2. Copy the `trafficparrot.usage.license` file to the current directory.

3. Save the following `Dockerfile` content. These are only example files, to help get you started, but you can modify them to suit your needs.

   ##### Eclipse Temurin OpenJDK 21 LTS base image example

   ```
   FROM eclipse-temurin:21-jre

   RUN apt-get update && apt-get install unzip -y

   WORKDIR /opt
   COPY trafficparrot-license-usage-*.zip trafficparrot-license-usage.zip
   RUN unzip trafficparrot-license-usage.zip && rm trafficparrot-license-usage.zip && mv trafficparrot-license-usage-* trafficparrot-license-usage
   COPY trafficparrot.usage.license /opt/trafficparrot-license-usage

   RUN chgrp -R 0 /opt/trafficparrot-license-usage && chmod -R g=u /opt/trafficparrot-license-usage

   WORKDIR /opt/trafficparrot-license-usage
   VOLUME ["/opt/trafficparrot-license-usage/data"]
   CMD ["./start.sh"]
   ```

   ##### Alpine base image example with Java 21 LTS

   ```
   FROM alpine:3

   RUN apk add --no-cache openjdk21-jre bash libc6-compat gcompat

   WORKDIR /opt
   COPY trafficparrot-license-usage-*.zip trafficparrot-license-usage.zip
   RUN unzip trafficparrot-license-usage.zip && rm trafficparrot-license-usage.zip && mv trafficparrot-license-usage-* trafficparrot-license-usage
   COPY trafficparrot.usage.license /opt/trafficparrot-license-usage

   RUN chgrp -R 0 /opt/trafficparrot-license-usage && chmod -R g=u /opt/trafficparrot-license-usage
   ENV LD_LIBRARY_PATH=/usr/lib:/opt/trafficparrot-license-usage/jre/lib/amd64/server:/opt/trafficparrot-license-usage/jre/lib/amd64

   WORKDIR /opt/trafficparrot-license-usage
   VOLUME ["/opt/trafficparrot-license-usage/data"]
   CMD ["./start.sh"]
   ```

4. Build an image, for example:

   ```
   docker build -t trafficparrot-license-usage:latest -t trafficparrot-license-usage:$(date '+%d-%b-%YT%H-%M-%S') .
   ```

5. Run a container, for example:

   ```
   docker run -p 8050:8050 -p 8040:8040 -v /opt/data:/opt/trafficparrot-license-usage/data trafficparrot-license-usage:latest
   ```

6. In this example:

   - The host persistent volume is `/opt/data`
   - The container mount point is `/opt/trafficparrot-license-usage/data`

7. You **must always provide a persistent volume mount** when starting the container so that the license server data is not lost if the container is stopped.

### Running in OpenShift

You may optionally use OpenShift to run the license server using the following steps:

1. Follow the steps to build a [Docker container](https://trafficparrot.com/documentation/license/1.17.x/start.html#configuration-docker) and push to your OpenShift Docker registry
2. Configure a persistent volume
3. Configure a single pod deployment configuration with the persistent volume mounted
4. Configure a service with TCP ports 8040, 8050, 8051
5. Configure a health check `GET /api/health` on either of the UI ports HTTP 8050 or HTTPS 8051
6. (optional) Configure an alerting check `GET /api/activation` on either of the UI ports HTTP 8050 or HTTPS 8051
7. Configure a route for the UI
   - Use Edge termination if routing to the HTTP UI port 8050
   - Use Passthrough or Re-encrypt termination if routing to the HTTPS UI port 8051
   - It is also possible for Traffic Parrot to connect to the UI port on path `/api/usage` if you need to use a single port for both the UI and license usage
8. Configure a route for the license usage port 8040. Your `trafficparrot.license` will be configured to support either a direct SSL/TLS binary connection to the license server or an HTTP(S) connection to allow for an on premise proxy server with path based routing (e.g. an F5 or NGINX proxy).
   - Use Passthrough termination when using a direct SSL/TLS binary connection to the license server
   - Use Re-encrypt termination when using an HTTPS proxy server and `license.usage.port.ssl.enabled=true`
   - Use Edge termination when using an HTTPS proxy server and `license.usage.port.ssl.enabled=false`
9. In this example:
   - The license usage port is 8040
   - The HTTP UI port is 8050
   - The HTTPS UI port is 8051
10. You **must configure a persistent volume mount** in the deployment configuration so that the license server data is not lost if the pod is stopped.
11. If you receive an HTTP 502 response from an OpenShift route this can sometimes mean you are incorrectly using insecure Edge termination for a secure target.

We also have a sample [Helm chart](https://helm.sh/) that can be used to help you get started, you can [download it here](https://trafficparrot.com/documentation/license/1.17.x/download/TPLS-sample-openshift4-v1.0.3.zip) and follow the included instructions.

For the latest examples, check out our [Traffic Parrot Helm Examples GitHub repository](https://github.com/trafficparrot/trafficparrot-examples-helm).

### Activation

Before Traffic Parrot instances can successfully connect to the license server, it must be activated.

**Please note that this is a one time only operation that should only be performed on a production ready license server that has been assigned a permanent persistent data volume and the installation directory or Docker image will no longer be changing.**

Please follow the steps below to perform activation:

1. Visit the Traffic Parrot License Activation web page by clicking the link on the license server UI:

   ![Traffic Parrot License Activation Link](https://trafficparrot.com/documentation/license/1.17.x/img/license-server-activation-page.png)

2. Follow the link, including the full URL that looks like `https://license.trafficparrot.com?id=example`

   ![Traffic Parrot License Activation](https://trafficparrot.com/documentation/license/1.17.x/img/license-activation-server.png)

3. (optional) If you do not have access to the activation web page, contact [support@trafficparrot.com](mailto:support@trafficparrot.com) and we will issue a token via email if you provide us with the link

4. Upload your `trafficparrot.usage.license` file

5. You will receive a response with an activation token that is valid for 72 hours to activate the running license server:

   ![Traffic Parrot License Activation success](https://trafficparrot.com/documentation/license/1.17.x/img/license-activation-server-success.png)

6. **This is the only time you will be shown this token, please take note of it**

7. **If the license server is restarted before activation then the token will no longer be valid**

8. Visit your local license server activation page:

   ![GUI Activation page](https://trafficparrot.com/documentation/license/1.17.x/img/license-server-activation-page.png)

9. Enter your token and click submit

10. You will see a success message:

    ![GUI Activation page success](https://trafficparrot.com/documentation/license/1.17.x/img/license-server-activation-page-success.png)

11. **The server will remain activated unless any of the following occur:**

    - The license server data directory changes
    - The license server installation directory changes
    - The license server Docker image is rebuilt

    which will require you to contact us to request activation of the new installation.

12. If you encounter any issues or lose your activation token please contact [support@trafficparrot.com](mailto:support@trafficparrot.com)

### Connecting Traffic Parrot

Now the license server is deployed, we can connect Traffic Parrot instances to it:

1. Place a copy of your `trafficparrot.license` file in the Traffic Parrot working directory (this has already been done for you in the download links we provide)

2. Configure `trafficparrot.properties` with the host and port of the usage server. Your `trafficparrot.license` will be configured to support either a direct SSL/TLS binary connection to the license server or an HTTP(S) connection to allow for an on premise proxy server with path based routing (e.g. an F5 or NGINX proxy).

   - When using a direct SSL/TLS binary connection to the license server e.g.

     ```
     trafficparrot.license.usage.server=licensehost:8040
     ```

   - When using an HTTPS proxy server with SSL e.g.

     ```
     trafficparrot.license.usage.server=https://proxyhost/some/path
     ```

     with the proxy server routing to `https://licensehost:8040` and license server `licenseusage.properties`

     ```
     license.usage.port.ssl.enabled=true
     ```

   - When using an HTTPS proxy server without SSL e.g.

     ```
     trafficparrot.license.usage.server=https://proxyhost/some/path
     ```

     with the proxy server routing to `http://licensehost:8040` and license server `licenseusage.properties`

     ```
     license.usage.port.ssl.enabled=false
     ```

   - It is also possible for Traffic Parrot to connect to the UI port on path `/api/usage` if you need to use a single port for both the UI and license usage

3. (optional) Configure `trafficparrot.properties` to allow sending custom headers to the proxy server, which may be necessary if your proxy server requires header based authentication:

   ```
   trafficparrot.license.usage.custom.headers=ExampleA:ValueA,ExampleB:ValueB
   ```

4. Check `logs/trafficparrot.log` and you should see messages like this:

   ```
   Checking out initial license usage token
   Checked out initial license usage token PWEZWDW8S7E6EWOG with expiry 2020-11-15T13:37:54.465Z
   License usage token PWEZWDW8S7E6EWOG renewed with expiry 2020-11-15T13:42:54.523Z
   Checking in license usage token PWEZWDW8S7E6EWOG before shutdown
   Checked in license usage token PWEZWDW8S7E6EWOG
   ```

5. Now when Traffic Parrot instances start up and shut down you should start to see data in the usage server

6. **Please ensure Traffic Parrot is shut down gracefully (in particular [when using Docker](https://trafficparrot.com/documentation/latest/user_guide.html#running-docker)) so that licenses can be released as soon as they are not in use, otherwise you will not be able to use the license until it has timed out**

## Upgrades

### Upgrading only Traffic Parrot

1. Stop Traffic Parrot
2. Take a backup of the previous installation directory
3. Copy the configuration that you would like to preserve from the previous installation to the new installation, for example this typically includes:
   - Compare `trafficparrot.properties` with the previous version and keep any custom property settings
   - Compare `jvm.args` with the previous version and keep any custom JVM settings
   - Copy `ibm-mq-connections.json`
   - Copy `mappings` directory
   - Copy `ibm-mq-mappings` directory
   - Copy `data` directory
   - Copy `__files` directory
   - Copy `certificates` certificate directory if you have custom certificates
   - Copy `lib/external` JAR directory if you have custom JARs
   - Copy `jre` custom JRE directory if you are using a custom JRE
   - Compare the installation directory with the previous version to check for any other configuration differences
4. Follow the instructions for [connecting](https://trafficparrot.com/documentation/license/1.17.x/start.html#configuration-connecting-traffic-parrot) to the license server
5. (optional) You can use the upgrade script (upgrade.sh on Linux/Mac or upgrade.exe on Windows) to help you perform the backup and configuration migration in the previous steps:
   - First, unzip the new release, and you will find the upgrade script there

   - For example on Linux/Mac in a terminal:

     ```
     ./upgrade.sh /path/to/previous-trafficparrot
     ```

   - For example on Windows at the command prompt:

     ```
     upgrade.exe "C:\path\to\previous-trafficparrot"
     ```

   - Your configuration changes from the previous installation will be merged into the new installation

   - (optional) Additional arguments can be used with the upgrade script:

     - `--replace-existing` will automatically replace the previous installation with the new installation, and backup the previous installation into a new folder
     - `--interactive` will prompt for user input to decide whether to stop the old instance and start the new instance
     - `--automatic-stop` will automatically stop a previously running instance before upgrading
     - `--automatic-start` will automatically start the new instance after upgrading

   - (optional) If you are using a custom JRE, please copy it over manually to the `jre` folder of the new installation
6. Start Traffic Parrot

### Upgrading only Traffic Parrot License Server

Before you upgrade, open the [release notes](https://trafficparrot.com/documentation/license/1.17.x/release_notes.html) and choose the release you are running in the **Upgrading from** list at the top: the page then shows only the notes marked **Upgrade** in every later release, which are the changes to what an existing installation does and the steps an upgrade asks of you.

1. Stop Traffic Parrot License Server
   - For example on Linux/Mac in a terminal:

     ```
     pkill -f ".*com.trafficparrot.licenseusage.api.LicenseUsageMain"
     ```

   - For example on Windows at the PowerShell prompt:

     ```
     $filter = "commandline like '%com.trafficparrot.licenseusage.api.LicenseUsageMain%'"
     Get-WmiObject Win32_Process -Filter $filter | ForEach-Object {
         $_.Terminate()
     }
     ```
2. Take a backup of the installation directory
3. To preserve the usage history, copy the data directory from the previous installation to the new installation before starting
4. Follow the instructions for [installation](https://trafficparrot.com/documentation/license/1.17.x/start.html#configuration-installation)
5. Follow the instructions for [activation](https://trafficparrot.com/documentation/license/1.17.x/start.html#configuration-activation)

### Upgrading both Traffic Parrot and Traffic Parrot License Server

1. Follow the instructions for [upgrading Traffic Parrot License Server](https://trafficparrot.com/documentation/license/1.17.x/start.html#upgrade-license-server-only)
2. Follow the instructions for [upgrading Traffic Parrot](https://trafficparrot.com/documentation/license/1.17.x/start.html#upgrade-traffic-parrot-only)

### Renewing the license files

1. Keep the old Traffic Parrot License Server instance running while the old license is still valid
2. Use the new `trafficparrot.usage.license` file with a new Traffic Parrot License Server instance, following the [installation instructions](https://trafficparrot.com/documentation/license/1.17.x/start.html#configuration-installation)
3. Start up the new Traffic Parrot License Server instance
4. Use the new `trafficparrot.license` file with new Traffic Parrot instances
5. Check that new Traffic Parrot instances can [connect to](https://trafficparrot.com/documentation/license/1.17.x/start.html#configuration-connecting-traffic-parrot) the new Traffic Parrot License Server instance
6. Shut down the old Traffic Parrot License Server instance

## Monitoring

### Prometheus metrics

The license server can serve its figures as Prometheus metrics, so your own Prometheus and Grafana can show which teams and projects use Traffic Parrot and how many licenses each holds. Metrics are off by default. To switch them on, set in `licenseusage.properties`:

```
metrics.enabled=true
```

The license server then serves `GET /metrics` on whichever user interface ports are enabled (`user.interface.port`, 8050 by default, and `user.interface.https.port`, 8051 by default), with no credentials, like the rest of the user interface. At start-up it logs `Prometheus metrics available at http://localhost:8050/metrics` for each port, and warns when metrics are on but both ports are off. With metrics off, `/metrics` answers 404. Until the first usage snapshot has been built after start-up, it answers 503 `License usage is still loading`.

The response is in Prometheus text format and carries these metrics:

| Metric | Type | Labels | Value |
| --- | --- | --- | --- |
| `tp_licences_purchased` | gauge |  | Licenses the license file allows. |
| `tp_licences_in_use` | gauge | team tags, `version` | Licenses checked out now, by team tag and Traffic Parrot version. |
| `tp_licence_rejections_total` | counter | team tags | License check-outs refused because none was free, since the license server started. |
| `tp_mappings` | gauge | team tags, `protocol` (`http`, `grpc`, `ibmmq`, `jms`) | Mappings loaded on checked-out instances at instance start-up, summed, by protocol and team tag. |

The team tags are the `trafficparrot.telemetry.<name>` properties each Traffic Parrot instance sends with its license check-out and keep-alive; the Monitoring page of the Traffic Parrot documentation describes them. The `project` label is the instance's `project` tag, or the project name it reports when it sends no such tag, so licenses group by project before any instance is upgraded. Up to nine other tag names are used as labels, in the order the license server first sees them after it starts; a tag name beyond that is dropped and named in a warning. An instance that lacks a tag reads `none` for it. Refused check-outs beyond 1000 distinct label sets are counted under `other`. No host name, IP address or user name appears in any label.

An example Prometheus scrape configuration, with the license server as its own job (two license servers in one job would add up their licenses in use while showing one server's purchased):

```
scrape_configs:
  - job_name: traffic-parrot-license-server
    static_configs:
      - targets: ['licensehost:8050']
```

### Monitoring on the home page

The home page of the license server's user interface has a **Monitoring** section, whether metrics are on or off. It shows:

- whether metrics are on and, when they are off, the property and the restart that turn them on;
- the scrape URL: `/metrics` at the address the page was opened at;
- an example Prometheus scrape configuration: the one above with `metrics_path: /metrics` written out and that address as its target;
- a **Download license-usage.json** link to the [License usage dashboard](https://trafficparrot.com/documentation/license/1.17.x/start.html#monitoring-license-usage-dashboard) for Grafana.

Before you copy the example:

- The address is the one your browser used. If Prometheus reaches the license server at another address, for example behind a proxy, use that address with the same path.
- Opened over HTTPS, the example also carries `scheme: https` and, commented out, a `tls_config` with `insecure_skip_verify: true`. As pasted, Prometheus verifies the license server's certificate, and it does not trust the self-signed certificate the license server ships with. Uncomment the two lines only to scrape a license server that still has that certificate, without verifying it.

### License usage dashboard

The **License usage** dashboard for Grafana shows the licenses purchased, in use and refused, by project and team. The license server serves it as a Grafana dashboard JSON file, whether metrics are on or off, so you can import it before you turn them on: use the **Download license-usage.json** link on the home page, or `GET /api/monitoring/dashboards/license-usage.json` on a user interface port.

Import the file into Grafana. At the top of the dashboard, choose your Prometheus data source, the license server (the Prometheus job that scrapes it) and whether to break the figures down by `project`, by `team` or by both. Its history starts when Prometheus first scrapes a license server that has metrics on. The Monitoring page of the Traffic Parrot documentation lists its panels.

## Usage Reports

### Hourly Peak Usage CSV Export

Customers with an on premise license server are requested to provide usage reports to Traffic Parrot via email. To export a CSV report:

1. Visit the license server GUI Reports page:

   ![GUI Reports page](https://trafficparrot.com/documentation/license/1.17.x/img/hourly-usage-csv.png)

2. Select the date range

3. Click the "Load selected date range" button

4. Click the "Peak license usage by hour" button

5. A report with a file name similar to `peak-usage-by-hour-16-Oct-2020-to-15-Nov-2020-Kq20bQre6MhgswfyG2RYFFIWr3FXTszZkDPnDq5FctL3wkxbb3KpGQ_.csv` will be downloaded with content

   ```
   Date,Peak license usage in hour
   2020-10-16-00,3
   2020-10-16-01,2
   2020-10-16-02,2
   2020-10-16-03,0
   2020-10-16-05,1
   2020-10-16-06,4
   ...
   ```

6. Please send a copy of the report to [support@trafficparrot.com](mailto:support@trafficparrot.com), keeping the same file name that was generated
