Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grafana DFP dashboard #989

Merged
merged 12 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
docs/source/developer_guide/guides/img/** filter=lfs diff=lfs merge=lfs -text
examples/data/** filter=lfs diff=lfs merge=lfs -text
examples/digital_fingerprinting/production/grafana/img/** filter=lfs diff=lfs merge=lfs -text
examples/digital_fingerprinting/visualization/img/** filter=lfs diff=lfs merge=lfs -text
morpheus/_version.py export-subst
tests/mock_triton_server/payloads/** filter=lfs diff=lfs merge=lfs -text
Expand Down
13 changes: 13 additions & 0 deletions examples/digital_fingerprinting/production/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ services:
cap_add:
- sys_nice

grafana:
image: grafana/grafana:10.0.0
environment:
GF_INSTALL_PLUGINS: "marcusolsson-csv-datasource"
volumes:
- ./grafana/config/grafana.ini:/etc/grafana/grafana.ini
- ./grafana/config/dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml
- ./grafana/dashboards/:/var/lib/grafana/dashboards/
- ./grafana/datasources/:/etc/grafana/provisioning/datasources/
- ./morpheus:/workspace
ports:
- "3000:3000"

networks:
frontend:
driver: bridge
Expand Down
111 changes: 111 additions & 0 deletions examples/digital_fingerprinting/production/grafana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!--
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-->

# Grafana DFP Dashboard Example

This example demonstrates how to use [Grafana](https://grafana.com/grafana/) to visualize the inference results from the [Azure DFP pipeline example](../production/README.md).

## Grafana Configuration

### CSV data source plugin

The [CSV data source plugin](https://grafana.com/grafana/plugins/marcusolsson-csv-datasource/) is installed to Grafana to read the Azure inference results CSV file. This example assumes we are using the CSV file generated from running the Python script for [Azure DFP pipeline example](../production/README.md).

If using the [notebook version](../production/morpheus/notebooks/dfp_azure_inference.ipynb) to run inference, you'll need to update the `url` in [datasources.yaml](./datasources/datasources.yaml) as follows:
```
url: /workspace/notebooks/dfp_detections_azure.csv
```

Please note that the use of the CSV plugin is for demonstration purposes only. Grafana includes support for many data sources more suitable for production deployments. See [here](https://grafana.com/docs/grafana/latest/datasources/) for more information.

### Updates to grafana.ini

The following is added to the default `grafana.ini` to enable local mode for CSV data source plugin. This allows the CSV data source plugin to access files on local file system.

```
[plugin.marcusolsson-csv-datasource]
allow_local_mode = true
```

## Run Azure Production DFP Training and Inference Examples

### Start Morpheus DFP pipeline container

The following steps are taken from [Azure DFP pipeline example](../production/README.md). Run the followng commands to start the Morpheus container:

Build the Morpheus container:

```bash
./docker/build_container_release.sh
```

Build `docker-compose` services:

```
cd examples/digital_fingerprinting/production
export MORPHEUS_CONTAINER_VERSION="$(git describe --tags --abbrev=0)-runtime"
docker-compose build
```

Create `bash` shell in `morpheus_pipeline` container:

```bash
docker-compose run morpheus_pipeline bash
```

### Run Azure training pipeline

Run the following in the container to train Azure models.

```bash
python dfp_azure_pipeline.py --log_level INFO --train_users generic --start_time "2022-08-01" --input_file="../../../data/dfp/azure-training-data/AZUREAD_2022*.json"
```

### Run Azure inference pipeline:

Run the inference pipeline with `filter_threshold=0.0`. This will disable the filtering of the inference results.

```bash
python dfp_azure_pipeline.py --log_level INFO --train_users none --start_time "2022-08-30" --input_file="../../../data/dfp/azure-inference-data/*.json" --filter_threshold=0.0
```

The inference results will be saved to `dfp_detection_azure.csv` in the directory where script was run.

## Run Grafana Docker Image

To start Grafana, run the following command on host in `examples/digital_fingerprinting/production`:

```
docker compose up grafana
```

## View DFP Dashboard

Our Grafana DFP dashboard can now be accessed via web browser at http://localhost:3000/dashboards.

Log in with admin/admin.

Click on `DFP_Dashboard` in the `General` folder. You may need to expand the `General` folder to see the link.

<img src="./img/screenshot.png">

The dashboard has the following visualization panels:

- Time series of absolute `mean_abs_z` across all rows. We can observe the higher `mean_abs_z` scores for `attacktarget@domain.com` as expected.
- Time series of z-loss per feature across all rows. We can observe the higher z-loss scores for the `appincrement` and `logcount` features.
- Bar gauge of maximum `mean_abs_z` per user.
- Bar gauge of maximum z-loss per feature.
- Table view of all rows/columns in CSV file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: 1

providers:
- name: 'default'
orgId: 1
folder: ''
type: file
options:
path: /var/lib/grafana/dashboards
Loading