Magistrala
Dev GuideServices

Journal

Audit log service for Magistrala — persists platform events to PostgreSQL and exposes HTTP endpoints for querying journals and viewing per-client telemetry.

The Journal service consumes the platform event stream from NATS, persists each event to PostgreSQL, and exposes HTTP endpoints for querying the audit log and viewing per-client telemetry (first/last seen, message in/out counters, active subscriptions). It is the primary observability tool for tracking what happened and when across the platform.

Configuration

VariableDescriptionDefault
MG_JOURNAL_LOG_LEVELLog level (debug, info, warn, error)info
MG_JOURNAL_HTTP_HOSTHTTP hostlocalhost
MG_JOURNAL_HTTP_PORTHTTP port9021
MG_JOURNAL_DB_HOSTDatabase hostlocalhost
MG_JOURNAL_DB_PORTDatabase port5432
MG_JOURNAL_DB_USERDatabase usermagistrala
MG_JOURNAL_DB_PASSDatabase passwordmagistrala
MG_JOURNAL_DB_NAMEDatabase namejournal
MG_JOURNAL_DB_SSL_MODESSL mode (disable, require, verify-ca, verify-full)disable
MG_ES_URLNATS event store URL consumed for journal entriesnats://localhost:4222
MG_AUTH_GRPC_URLAuth service gRPC URL""
MG_AUTH_GRPC_TIMEOUTAuth gRPC timeout1s
MG_DOMAINS_GRPC_URLDomains service gRPC URL""
MG_DOMAINS_GRPC_TIMEOUTDomains gRPC timeout1s
MG_JAEGER_URLJaeger tracing endpointhttp://localhost:4318/v1/traces
MG_JAEGER_TRACE_RATIOTrace sampling ratio1.0
MG_SEND_TELEMETRYSend telemetry to Magistrala call-home servertrue
MG_ALLOW_UNVERIFIED_USERAllow unverified users to authenticate (useful in dev)false

Deployment

Journal requires a running PostgreSQL instance, NATS, Auth gRPC, and Domains gRPC.

git clone https://github.com/absmach/magistrala
cd magistrala

make journal
make install

MG_JOURNAL_LOG_LEVEL=info \
MG_JOURNAL_HTTP_HOST=localhost \
MG_JOURNAL_HTTP_PORT=9021 \
MG_JOURNAL_DB_HOST=localhost \
MG_JOURNAL_DB_PORT=5432 \
MG_JOURNAL_DB_USER=magistrala \
MG_JOURNAL_DB_PASS=magistrala \
MG_JOURNAL_DB_NAME=journal \
MG_AUTH_GRPC_URL=localhost:7001 \
MG_DOMAINS_GRPC_URL=localhost:7003 \
MG_ES_URL=nats://localhost:4222 \
$GOBIN/magistrala-journal

HTTP API

Base URL defaults to http://localhost:9021. Journal and telemetry endpoints require Authorization: Bearer <token>.

OperationDescription
List user journalsPage through events for a user across all domains
List entity journalsPage through events for a specific client, channel, group, or user in a domain
View client telemetryAggregate counters: subscriptions, inbound/outbound messages, first/last seen
Health checkLiveness and build info (public endpoint)

List user journals

curl "http://localhost:9021/journal/user/${USER_ID}?limit=10&with_attributes=true&dir=desc" \
  -H "Authorization: Bearer $TOKEN"

Expected response:

{
  "total": 1,
  "offset": 0,
  "limit": 10,
  "journals": [
    {
      "operation": "user.create",
      "occurred_at": "2024-01-11T12:05:07.449053Z",
      "attributes": { "id": "...", "name": "Ada Lovelace", "status": "enabled" }
    }
  ]
}

List entity journals in a domain

curl "http://localhost:9021/${DOMAIN_ID}/journal/client/${CLIENT_ID}?operation=client.create&dir=desc&limit=10" \
  -H "Authorization: Bearer $TOKEN"

View client telemetry

curl "http://localhost:9021/${DOMAIN_ID}/journal/client/${CLIENT_ID}/telemetry" \
  -H "Authorization: Bearer $TOKEN"

Expected response:

{
  "client_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879",
  "domain_id": "29d425c8-542b-4614-8a4d-a5951945d720",
  "subscriptions": 5,
  "inbound_messages": 1234567,
  "outbound_messages": 987654,
  "first_seen": "2024-01-11T10:00:00Z",
  "last_seen": "2024-01-11T12:05:07Z"
}

Health check

curl http://localhost:9021/health

On this page