# Neo4j Monitor

This application is a Lambda function, that connects to Neo4j and runs queries to get cluster status. The results are printed to stdout and can be uploaded to S3.

Example output is provided in the `examples` directory.

## Usage for QA/Prod
This no longer runs on schedule. It can be triggered manually by using this Jenkins job: https://scheduler.theorchard.io/job/lambda-neo4j-monitor-invoke/

## Neo4j queries

The application runs the following queries:

| Alias | Query |
|---|---|
| cluster-overview | SHOW SERVERS |
| list-transactions | SHOW TRANSACTIONS |
| list-connections | dbms.listConnections() |

## Application configuration

### Neo4j credentials

Neo4j URL and credentials can be specified in 2 different ways:

- As environment variable `NEO4J_CREDENTIALS_SECRET_ARN` which points to SecretsManager's secret. This option has a priority over the other one.
- As 3 self-explanatory environment variables `NEO4J_URL`, `NEO4J_USERNAME`, `NEO4J_PASSWORD`.

SecretsManager's secret should be in a key-value format with the following fields:

```json
{
  "URL": "neo4j+s://dev-neo4j-cluster.dev.theorchard.io:7687",
  "USERNAME": "neo4j-monitor",
  "PASSWORD": "..."
}
```

### Output format

Queries output can be uploaded to S3 as CSV and printable output in zip archives. To enable S3 storage set environment variable `S3_BUCKET_NAME` to specify bucket name and/or `S3_BUCKET_PREFIX` to configure prefix for archives.

For printable output, you can set the maximum table column width with the `MAX_TABLE_COLUMN_WIDTH` environment variable.
