Skip to content

Commit

Permalink
Merge pull request #72 from longzheng/influx-optional
Browse files Browse the repository at this point in the history
Make InfluxDB optional
  • Loading branch information
longzheng authored Dec 20, 2024
2 parents 14742fa + 3f7bda7 commit f3eef3b
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 101 deletions.
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ CONFIG_DIR=./config
SEP2_CERT_FILE=cert.pem
SEP2_KEY_FILE=key.pem
SEP2_PEN=62223
INFLUXDB_USERNAME=admin
INFLUXDB_PASSWORD=password
INFLUXDB_ADMIN_TOKEN=super-secret-auth-token
INFLUXDB_ORG=open-dynamic-export
INFLUXDB_BUCKET=data
INFLUXDB_PORT=8086
# INFLUXDB_USERNAME=admin
# INFLUXDB_PASSWORD=password
# INFLUXDB_ADMIN_TOKEN=super-secret-auth-token
# INFLUXDB_ORG=open-dynamic-export
# INFLUXDB_BUCKET=data
# INFLUXDB_PORT=8086
41 changes: 21 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ services:
- ./config/:/app/config/
- ./logs/:/app/logs/
restart: 'unless-stopped'
depends_on:
- influxdb
influxdb:
image: influxdb:2
env_file:
- .env
ports:
- ${INFLUXDB_PORT}:${INFLUXDB_PORT}
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
INFLUXD_HTTP_BIND_ADDRESS: :${INFLUXDB_PORT}
DOCKER_INFLUXDB_INIT_USERNAME: ${INFLUXDB_USERNAME}
DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD}
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_ADMIN_TOKEN}
DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_ORG}
DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_BUCKET}
volumes:
- influxdb2-data:/var/lib/influxdb2
- influxdb2-config:/etc/influxdb2
restart: 'unless-stopped'
# depends_on:
# - influxdb

# influxdb:
# image: influxdb:2
# env_file:
# - .env
# ports:
# - ${INFLUXDB_PORT}:${INFLUXDB_PORT}
# environment:
# DOCKER_INFLUXDB_INIT_MODE: setup
# INFLUXD_HTTP_BIND_ADDRESS: :${INFLUXDB_PORT}
# DOCKER_INFLUXDB_INIT_USERNAME: ${INFLUXDB_USERNAME}
# DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD}
# DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_ADMIN_TOKEN}
# DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_ORG}
# DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_BUCKET}
# volumes:
# - influxdb2-data:/var/lib/influxdb2
# - influxdb2-config:/etc/influxdb2
# restart: 'unless-stopped'
volumes:
influxdb2-data:
influxdb2-config:
41 changes: 27 additions & 14 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,41 @@ The system supports one site meter to measure the site's load and export metrics

## Install

### Docker compose

1. Clone Git repo

2. Copy `.env.example` and rename it to `.env` and change the values to suit your environment

```yaml
TZ=Australia/Melbourne # Your system timezone
TZ=Australia/Melbourne # System timezone
SERVER_PORT=3000 # API server port
CONFIG_DIR=./config # Directory to store configuration files
SEP2_CERT_FILE=sapn_cert.pem # CSIP-AUS/SEP2 certificate file (in the config directory)
SEP2_KEY_FILE=sapn_key.pem # CSIP-AUS/SEP2 key file (in the config directory)
SEP2_PEN=62223 # CSIP-AUS/SEP2 Private Enterprise Number
INFLUXDB_USERNAME=admin # InfluxDB username
INFLUXDB_PASSWORD=password # InfluxDB password
INFLUXDB_ADMIN_TOKEN=super-secret-auth-token # InfluxDB admin token
INFLUXDB_ORG=open-dynamic-export # InfluxDB organisation
INFLUXDB_BUCKET=data # InfluxDB bucket
INFLUXDB_PORT=8086 # InfluxDB port
LOGLEVEL=debug # Log level (valid values: trace, debug)
SEP2_CERT_FILE=sapn_cert.pem # CSIP-AUS/SEP2 certificate file path (in the config directory)
SEP2_KEY_FILE=sapn_key.pem # CSIP-AUS/SEP2 key file path (in the config directory)
SEP2_PEN=62223 # CSIP-AUS/SEP2 Provider Private Enterprise Number (does not need to be changed)
# INFLUXDB_USERNAME=admin # Optional InfluxDB username, enable to log data to InfluxDB
# INFLUXDB_PASSWORD=password # Optional InfluxDB password, enable to log data to InfluxDB
# INFLUXDB_ADMIN_TOKEN=super-secret-auth-token # Optional InfluxDB admin token, enable to log data to InfluxDB
# INFLUXDB_ORG=open-dynamic-export # Optional InfluxDB organisation, enable to log data to InfluxDB
# INFLUXDB_BUCKET=data # Optional InfluxDB bucket, enable to log data to InfluxDB
# INFLUXDB_PORT=8086 # Optional InfluxDB port, enable to log data to InfluxDB
# LOGLEVEL=debug # Optional log level (valid values: trace, debug. default: debug)
```

3. In the `/config` folder, make a copy of the `config.example.json` file and rename it to `config.json`. Update it with the relevant values, see the "Configuration" section for more details.

4. Run `docker compose up -d` (optionally run `docker compose up -d --build` to build the image from the source code)
Use Node or Docker to run the project.

### Node
You can run the Node project directly with the Node.js runtime.

1. Install dependencies with `npm install`

2. Build the project with `npm run build`

3. Run the project with `npm start`

### Docker compose

1. Run `docker compose up -d` to use from the Docker Hub image (optionally run `docker compose up -d --build` to build the image from the source code)

2. Optionally uncomment the `influxdb` service in the `docker-compose.yml` file to enable logging to InfluxDB
12 changes: 6 additions & 6 deletions src/helpers/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const envSchema = z.object({
SEP2_CERT_FILE: z.string(),
SEP2_KEY_FILE: z.string(),
SEP2_PEN: z.string(),
INFLUXDB_USERNAME: z.string(),
INFLUXDB_PASSWORD: z.string(),
INFLUXDB_ADMIN_TOKEN: z.string(),
INFLUXDB_ORG: z.string(),
INFLUXDB_BUCKET: z.string(),
INFLUXDB_PORT: z.string().transform(safeParseIntString),
INFLUXDB_USERNAME: z.string().optional(),
INFLUXDB_PASSWORD: z.string().optional(),
INFLUXDB_ADMIN_TOKEN: z.string().optional(),
INFLUXDB_ORG: z.string().optional(),
INFLUXDB_BUCKET: z.string().optional(),
INFLUXDB_PORT: z.string().transform(safeParseIntString).optional(),
});

const parsedEnv = envSchema.safeParse(process.env);
Expand Down
Loading

0 comments on commit f3eef3b

Please sign in to comment.