Monitoring

Monitoring applications and databases is essential to track the load and resources used by the system.

Memgraph currently supports:

  1. Real-time logs tracking via WebSocket server: Log tracking is helpful for debugging purposes and monitoring the database operations.
  2. Metrics tracking via HTTP server (Enterprise Edition): In the Enterprise edition, besides log tracking, Memgraph allows tracking information about transactions, query latencies, types of queries executed, snapshot recovery latencies, triggers, TTL data, Bolt messages, indexes, streams, memory, operators and sessions. There are also many metrics which are trying to describe the state of high availability. These include metrics which describe latencies of RPC messages, time needed to perform a failover and counters for events occurring throughout the lifetime of HA Memgraph.
  3. Session trace: Profile the execution of all queries within a session to identify performance bottlenecks.

For deeper troubleshooting — including profiling with perf, capturing core dumps, and GDB workflows — see the Debugging guide. If you run HA on Kubernetes, the K8s setup guide covers init-container diagnostics and uploading core dumps to S3.

Real-time logs tracking via WebSocket server

Connect to Memgraph’s logging server via WebSocket to forward logs to all the connected clients.

Log messages

Each log that is written to the log file is forwarded to the connected clients in the following format:

{
  event: "log",
  level: "trace"|"debug"|"info"|"warning"|"error"|"critical",
  message: "<log-message>"
}

Connection

To connect to Memgraph’s WebSocket server, use the following URL:

ws://host:port

The default host is 0.0.0.0, but it can be changed using the --monitoring-address= configuration flag.

The default port is 7444, but it can be changed using the --monitoring-port configuration flag.

To connect to Memgraph’s WebSocket server using the default configuration and Python client, you can use the following code snippet:

import asyncio
import websockets
 
HOST = 'localhost'
PORT = '7444'
 
# The WebSocket URL
ws_url = f'ws://{HOST}:{PORT}'
 
async def read_logs():
    async with websockets.connect(ws_url) as websocket:
        print(f"Connected to Memgraph at {ws_url}")
        try:
            # Keep reading messages (logs) from the server
            while True:
 log_message = await websocket.recv()
                print(log_message)
        except websockets.exceptions.ConnectionClosed:
            print("Connection to Memgraph closed.")
 
asyncio.run(read_logs())

The code structure is similar in other languages, depending on the WebSocket library used.

If you want to connect with a WebSocket Secure (WSS) connection, set the --bolt-cert-file and --bolt-key-file configuration flags to enable an SSL connection. Refer to the configuration page to learn how to update the configuration and to see the list of all available configuration flags.

Authentication

When authentication is not used due to no users present in Memgraph, no authentication message is expected, and no response will be returned.

When the authentication is used, Memgraph won’t send a message to a certain connection until it’s authenticated.

To authenticate, create a JSON with the credentials in the following format:

{
  "username": "<username>",
  "password": "<password>"
}

If the credentials are valid, the connection will be made, and the client will receive the messages. As a response, the client should receive the following message:

{
  "success": true,
  "message": "User has been successfully authenticated!"
}

If they are invalid or the first message is in an invalid format, the connection is dropped. As a response, the following message is sent:

{
  "success": false,
  "message": "<error-message>"
}

To use WebSocket to authenticate, send the JSON message to the WebSocket server:

import asyncio
import json
import websockets
 
HOST = "localhost"
PORT = "7444"
USERNAME = "memgraph"
PASSWORD = "memgraph"
 
ws_url = f"ws://{HOST}:{PORT}"
 
 
async def authenticate_and_read_logs(websocket):
    # Send authentication credentials
    credentials = json.dumps({"username": USERNAME, "password": PASSWORD})
    await websocket.send(credentials)
 
    # Wait for authentication response
    response = await websocket.recv()
    response_data = json.loads(response)
    if response_data.get("success"):
        print("Authentication successful!")
    else:
        print(f"Authentication failed: {response_data.get('message')}")
        return  # Stop if authentication fails
 
    # After successful authentication, start reading logs
    try:
        while True:
            log_message = await websocket.recv()
            print(log_message)
    except websockets.exceptions.ConnectionClosed:
        print("Connection to Memgraph closed.")
 
 
async def connect_and_authenticate():
    async with websockets.connect(ws_url) as websocket:
        print(f"Connected to Memgraph at {ws_url}")
        await authenticate_and_read_logs(websocket)
 
 
asyncio.run(connect_and_authenticate())

Authorization (Enterprise)

Permission for connecting through WebSocket is controlled by the WEBSOCKET privilege.

Metrics tracking via HTTP server (Enterprise Edition)

In the Enterprise Edition, Memgraph allows tracking information about high availability, transactions, query latencies, snapshot recovery latencies, triggers, Bolt messages, indexes, constraints, streams, memory, operators and sessions, all by using an HTTP server.

To retrieve data from the HTTP server, enter a valid Memgraph Enterprise license key.

The default address and port for the metrics server is 0.0.0.0:9091, and can be configured using the --metrics-address and --metrics-port configuration flags.

Metrics format

The --metrics-format configuration flag controls the response format of the HTTP endpoint. The allowed values are:

  • OpenMetrics: Prometheus-compatible OpenMetrics text format (application/openmetrics-text). Metrics are labeled per-database. Any OpenMetrics compatible clients can connect directly to Memgraph to scrape metrics.
  • JSON (default): A flat JSON object. The JSON format is deprecated. Using JSON with any OpenMetrics compatible client requires the Prometheus exporter middleware.

New deployments should use OpenMetrics, which enables direct Prometheus scraping and provides per-database metric labels.

Per-database metrics

Most metrics are tracked per-database. In a multi-tenant setup, each database maintains its own counters, gauges, and histograms. How per-database metrics are exposed depends on the format — see the OpenMetrics and JSON sections below.

Session-related metrics (active sessions, Bolt messages) and high-availability metrics remain global — they are not scoped to any single database.

System metrics

All system metrics measuring different parts of the system can be divided into three different types:

  • Gauge — a single value of some variable in the system (e.g. memory usage, active transaction count)
  • Counter — a monotonically increasing value (e.g. total number of committed transactions)
  • Histogram — distribution of measured values (e.g. query latency percentiles)

The metric names in the tables below use the OpenMetrics format. The deprecated JSON endpoint and SHOW METRICS INFO use different names — see JSON monitoring for details.

General metrics

NameTypeDescription
memgraph_vertex_countGaugeNumber of nodes stored in the database.
memgraph_edge_countGaugeNumber of relationships stored in the database.
memgraph_disk_usage_bytesGaugeDisk space used by the database’s data directory (in bytes).
memgraph_memory_res_bytesGaugeRAM used by the Memgraph process as reported by the OS (in bytes). Reflects the resident set size, not the value used for license enforcement.
memgraph_peak_memory_res_bytesGaugePeak RAM used by the Memgraph process (in bytes).

Index metrics

NameTypeDescription
memgraph_active_label_indicesGaugeNumber of active label indexes.
memgraph_active_label_property_indicesGaugeNumber of active label-property indexes.
memgraph_active_edge_type_indicesGaugeNumber of active edge-type indexes.
memgraph_active_edge_type_property_indicesGaugeNumber of active edge-type-property indexes.
memgraph_active_edge_property_indicesGaugeNumber of active edge-property indexes.
memgraph_active_point_indicesGaugeNumber of active point indexes.
memgraph_active_text_indicesGaugeNumber of active text indexes on vertices.
memgraph_active_text_edge_indicesGaugeNumber of active text indexes on edges.
memgraph_active_vector_indicesGaugeNumber of active vector indexes on vertices.
memgraph_active_vector_edge_indicesGaugeNumber of active vector indexes on edges.

Constraint metrics

NameTypeDescription
memgraph_active_existence_constraintsGaugeNumber of active existence constraints.
memgraph_active_unique_constraintsGaugeNumber of active unique constraints.
memgraph_active_type_constraintsGaugeNumber of active type constraints.

Memory metrics

NameTypeDescription
memgraph_db_memory_tracked_bytesGaugeTotal tracked memory for the database (in bytes).
memgraph_db_peak_memory_tracked_bytesGaugePeak tracked memory for the database (in bytes).
memgraph_db_storage_memory_tracked_bytesGaugeMemory used by graph structures (vertices, edges, properties).
memgraph_db_embedding_memory_tracked_bytesGaugeMemory used by vector index embeddings.
memgraph_db_query_memory_tracked_bytesGaugeMemory used by query execution.
memgraph_unreleased_delta_objectsGaugeNumber of unreleased delta objects.
memgraph_gc_latency_secondsHistogramGC total cleanup time.
memgraph_gc_skiplist_cleanup_latency_secondsHistogramGC time spent cleaning skiplists in indexes.

Operator metrics

Before a Cypher query is executed, it is converted into an internal form suitable for execution, known as a query plan. A query plan is a tree-like data structure describing a pipeline of operations that will be performed on the database in order to yield the results for a given query. Every node within a plan is known as a logical operator and describes a particular operation.

All operator metrics are counters tracking how many times each operator was used.

NameType
memgraph_once_operator_totalCounter
memgraph_create_node_operator_totalCounter
memgraph_create_expand_operator_totalCounter
memgraph_scan_all_operator_totalCounter
memgraph_scan_all_by_label_operator_totalCounter
memgraph_scan_all_by_label_properties_operator_totalCounter
memgraph_scan_all_by_id_operator_totalCounter
memgraph_scan_all_by_edge_operator_totalCounter
memgraph_scan_all_by_edge_type_operator_totalCounter
memgraph_scan_all_by_edge_type_property_operator_totalCounter
memgraph_scan_all_by_edge_type_property_value_operator_totalCounter
memgraph_scan_all_by_edge_type_property_range_operator_totalCounter
memgraph_scan_all_by_edge_property_operator_totalCounter
memgraph_scan_all_by_edge_property_value_operator_totalCounter
memgraph_scan_all_by_edge_property_range_operator_totalCounter
memgraph_scan_all_by_edge_id_operator_totalCounter
memgraph_scan_all_by_point_distance_operator_totalCounter
memgraph_scan_all_by_point_withinbbox_operator_totalCounter
memgraph_expand_operator_totalCounter
memgraph_expand_variable_operator_totalCounter
memgraph_construct_named_path_operator_totalCounter
memgraph_filter_operator_totalCounter
memgraph_produce_operator_totalCounter
memgraph_delete_operator_totalCounter
memgraph_set_property_operator_totalCounter
memgraph_set_properties_operator_totalCounter
memgraph_set_labels_operator_totalCounter
memgraph_set_nested_property_operator_totalCounter
memgraph_remove_property_operator_totalCounter
memgraph_remove_labels_operator_totalCounter
memgraph_remove_nested_property_operator_totalCounter
memgraph_edge_uniqueness_filter_operator_totalCounter
memgraph_empty_result_operator_totalCounter
memgraph_accumulate_operator_totalCounter
memgraph_aggregate_operator_totalCounter
memgraph_skip_operator_totalCounter
memgraph_limit_operator_totalCounter
memgraph_order_by_operator_totalCounter
memgraph_merge_operator_totalCounter
memgraph_optional_operator_totalCounter
memgraph_unwind_operator_totalCounter
memgraph_distinct_operator_totalCounter
memgraph_union_operator_totalCounter
memgraph_cartesian_operator_totalCounter
memgraph_call_procedure_operator_totalCounter
memgraph_foreach_operator_totalCounter
memgraph_evaluate_pattern_filter_operator_totalCounter
memgraph_apply_operator_totalCounter
memgraph_indexed_join_operator_totalCounter
memgraph_hash_join_operator_totalCounter
memgraph_roll_up_apply_operator_totalCounter
memgraph_periodic_commit_operator_totalCounter
memgraph_periodic_subquery_operator_totalCounter

Query metrics

NameTypeDescription
memgraph_query_execution_latency_secondsHistogramQuery execution latency.
memgraph_read_queries_totalCounterNumber of read-only queries executed.
memgraph_write_queries_totalCounterNumber of write-only queries executed.
memgraph_read_write_queries_totalCounterNumber of read-write queries executed.

Schema and storage info metrics

NameTypeDescription
memgraph_show_schema_totalCounterNumber of times SHOW SCHEMA INFO was executed.
memgraph_show_storage_info_totalCounterNumber of times SHOW STORAGE INFO or SHOW STORAGE INFO ON DATABASE was executed.

Session metrics

Session metrics are global; they are not scoped to any individual database.

NameTypeDescription
memgraph_active_sessionsGaugeNumber of active connections.
memgraph_active_bolt_sessionsGaugeNumber of active Bolt connections.
memgraph_active_tcp_sessionsGaugeNumber of active TCP connections.
memgraph_active_ssl_sessionsGaugeNumber of active SSL connections.
memgraph_active_websocket_sessionsGaugeNumber of active WebSocket connections.
memgraph_bolt_messages_totalCounterNumber of Bolt messages sent.

Snapshot metrics

NameTypeDescription
memgraph_snapshot_creation_latency_secondsHistogramSnapshot creation latency.
memgraph_snapshot_recovery_latency_secondsHistogramSnapshot recovery latency.

Stream metrics

NameTypeDescription
memgraph_streams_created_totalCounterNumber of streams created.
memgraph_messages_consumed_totalCounterNumber of consumed streamed messages.

Transaction metrics

NameTypeDescription
memgraph_active_transactionsGaugeNumber of active transactions.
memgraph_committed_transactions_totalCounterNumber of committed transactions.
memgraph_rolled_back_transactions_totalCounterNumber of rolled-back transactions.
memgraph_failed_queries_totalCounterNumber of times executing a query failed (during parse time or runtime).
memgraph_failed_prepares_totalCounterNumber of times preparing a query failed.
memgraph_failed_pulls_totalCounterNumber of times pulling a query failed.
memgraph_successful_queries_totalCounterNumber of successful queries.
memgraph_transient_errors_totalCounterNumber of transient errors (errors which can be retried).
memgraph_write_write_conflicts_totalCounterNumber of write-write conflicts (two transactions modifying the same node simultaneously).

Trigger metrics

NameTypeDescription
memgraph_triggers_created_totalCounterNumber of triggers created.
memgraph_triggers_executed_totalCounterNumber of triggers executed.

TTL metrics

NameTypeDescription
memgraph_deleted_nodes_totalCounterNumber of nodes deleted via TTL.
memgraph_deleted_edges_totalCounterNumber of edges deleted via TTL.

HA metrics

HA metrics are global; they are not scoped to any individual database.

Latency histograms
NameTypeDescription
memgraph_socket_connect_secondsHistogramSocket connect latency.
memgraph_prepare_commit_rpc_secondsHistogramPrepareCommitRpc latency.
memgraph_current_wal_rpc_secondsHistogramCurrentWalRpc latency.
memgraph_wal_files_rpc_secondsHistogramWalFilesRpc latency.
memgraph_replica_stream_secondsHistogramTime to construct PrepareCommitRpc stream.
memgraph_snapshot_rpc_secondsHistogramSnapshotRpc latency.
memgraph_frequent_heartbeat_rpc_secondsHistogramFrequentHeartbeatRpc latency.
memgraph_heartbeat_rpc_secondsHistogramHeartbeatRpc latency.
memgraph_system_recovery_rpc_secondsHistogramSystemRecoveryRpc latency.
memgraph_choose_most_up_to_date_instance_secondsHistogramLatency of choosing the next main instance.
memgraph_get_histories_secondsHistogramLatency of retrieving instance histories.
memgraph_instance_fail_callback_secondsHistogramInstance failure callback latency.
memgraph_instance_succ_callback_secondsHistogramInstance success callback latency.
memgraph_data_failover_secondsHistogramFailover procedure latency.
memgraph_start_txn_replication_secondsHistogramLatency of starting transaction replication.
memgraph_finalize_txn_replication_secondsHistogramLatency of finishing transaction replication.
memgraph_demote_main_to_replica_rpc_secondsHistogramDemoteMainToReplicaRpc latency.
memgraph_enable_writing_on_main_rpc_secondsHistogramEnableWritingOnMainRpc latency.
memgraph_get_database_histories_rpc_secondsHistogramGetDatabaseHistoriesRpc latency.
memgraph_promote_to_main_rpc_secondsHistogramPromoteToMainRpc latency.
memgraph_register_replica_on_main_rpc_secondsHistogramRegisterReplicaOnMainRpc latency.
memgraph_state_check_rpc_secondsHistogramStateCheckRpc latency.
memgraph_unregister_replica_rpc_secondsHistogramUnregisterReplicaRpc latency.
memgraph_update_data_instance_config_rpc_secondsHistogramUpdateDataInstanceConfigRpc latency.
Throughput histograms

Throughput metrics are labeled per replica with an mg_instance label.

NameTypeDescription
memgraph_snapshot_throughput_bytes_per_secondHistogramSnapshot replication throughput to a replica (bytes/second).
memgraph_wal_throughput_bytes_per_secondHistogramWAL replication throughput to a replica (bytes/second).
Counters
NameTypeDescription
memgraph_successful_failovers_totalCounterSuccessful failovers.
memgraph_raft_failed_failovers_totalCounterFailovers that failed because writing to Raft failed.
memgraph_no_alive_instance_failed_failovers_totalCounterFailovers that failed because no instance was alive.
memgraph_become_leader_success_totalCounterTimes a coordinator successfully became leader.
memgraph_failed_to_become_leader_totalCounterTimes a coordinator failed to become leader.
memgraph_show_instance_totalCounterTimes SHOW INSTANCE was called.
memgraph_show_instances_totalCounterTimes SHOW INSTANCES was called.
memgraph_demote_instance_totalCounterTimes the user manually demoted an instance.
memgraph_unregister_repl_instance_totalCounterTimes the user tried to unregister a replication instance.
memgraph_remove_coord_instance_totalCounterTimes the user tried to remove a coordinator instance.
memgraph_state_check_rpc_success_totalCounterSuccessful StateCheckRpc responses.
memgraph_state_check_rpc_fail_totalCounterFailed or missing StateCheckRpc responses.
memgraph_unregister_replica_rpc_success_totalCounterSuccessful UnregisterReplicaRpc responses.
memgraph_unregister_replica_rpc_fail_totalCounterFailed or missing UnregisterReplicaRpc responses.
memgraph_enable_writing_on_main_rpc_success_totalCounterSuccessful EnableWritingOnMainRpc responses.
memgraph_enable_writing_on_main_rpc_fail_totalCounterFailed or missing EnableWritingOnMainRpc responses.
memgraph_promote_to_main_rpc_success_totalCounterSuccessful PromoteToMainRpc responses.
memgraph_promote_to_main_rpc_fail_totalCounterFailed or missing PromoteToMainRpc responses.
memgraph_demote_main_to_replica_rpc_success_totalCounterSuccessful DemoteMainToReplicaRpc responses.
memgraph_demote_main_to_replica_rpc_fail_totalCounterFailed or missing DemoteMainToReplicaRpc responses.
memgraph_register_replica_on_main_rpc_success_totalCounterSuccessful RegisterReplicaOnMainRpc responses.
memgraph_register_replica_on_main_rpc_fail_totalCounterFailed or missing RegisterReplicaOnMainRpc responses.
memgraph_swap_main_uuid_rpc_success_totalCounterSuccessful SwapMainUUIDRpc responses.
memgraph_swap_main_uuid_rpc_fail_totalCounterFailed or missing SwapMainUUIDRpc responses.
memgraph_get_database_histories_rpc_success_totalCounterSuccessful GetDatabaseHistoriesRpc responses.
memgraph_get_database_histories_rpc_fail_totalCounterFailed or missing GetDatabaseHistoriesRpc responses.
memgraph_update_data_instance_config_rpc_success_totalCounterSuccessful UpdateDataInstanceConfigRpc responses.
memgraph_update_data_instance_config_rpc_fail_totalCounterFailed or missing UpdateDataInstanceConfigRpc responses.
memgraph_replica_recovery_success_totalCounterSuccessful replica recovery processes.
memgraph_replica_recovery_fail_totalCounterFailed replica recovery processes.
memgraph_replica_recovery_skip_totalCounterSkipped replica recovery tasks.

OpenMetrics monitoring

Set --metrics-format=OpenMetrics to enable the OpenMetrics endpoint. The response uses OpenMetrics text format (application/openmetrics-text), which any Prometheus-compatible client can scrape directly.

The metrics are served at http://host:port/metrics (or http://host:port/). See Prometheus scrape configuration for how to set up scraping.

Per-database labels

Per-database metrics carry database and uuid labels identifying which database they belong to. Global metrics (such as sessions, HA) have no database label.

# TYPE memgraph_vertex_count gauge
memgraph_vertex_count{database="memgraph",uuid="abc-123"} 42254
memgraph_vertex_count{database="analytics",uuid="def-456"} 1000
# TYPE memgraph_active_sessions gauge
memgraph_active_sessions 3

Instance status gauges

The following per-instance gauges are exposed for each registered HA instance. Each metric carries an mg_instance label identifying the instance by name.

All instances expose instance_up and instance_last_response_seconds. Coordinator instances additionally expose instance_is_leader, while data instances expose instance_is_main.

NameTypeApplies toDescription
memgraph_instance_upGaugeAll1 if the instance is up, 0 if down.
memgraph_instance_last_response_secondsGaugeAllSeconds since the last successful response from the instance.
memgraph_instance_is_leaderGaugeCoordinators1 if the coordinator is the leader, 0 if follower.
memgraph_instance_is_mainGaugeData instances1 if the data instance is the main, 0 if replica.

Prometheus scrape configuration

Add Memgraph as a scrape target in your prometheus.yml:

scrape_configs:
  - job_name: "memgraph"
    metrics_path: "/metrics"
    static_configs:
      - targets: ["memgraph-host:9091"]

JSON monitoring (deprecated)

Set --metrics-format=JSON (the current default) to enable the JSON endpoint. This format is deprecated and will be removed in a future release.

To retrieve the metrics, send a GET request to http://host:port/metrics or http://host:port/:

import json
import requests
 
 
def fetch_memgraph_metrics():
    metrics_url = "http://0.0.0.0:9091/metrics"
 
    try:
        response = requests.get(metrics_url, timeout=5)
 
        if response.status_code == 200:
            metrics_data = json.loads(response.text)
            print("Memgraph Metrics:\n", json.dumps(metrics_data, indent=4))
        else:
            print(f"Failed to fetch metrics. Status code: {response.status_code}")
    except requests.exceptions.RequestException as e:
        print(f"An error occurred: {e}")
 
 
fetch_memgraph_metrics()

Response format

The endpoint returns a JSON object grouped by metric category. Each category contains key-value pairs of metric names and their values:

{
  "General": {
    "vertex_count": 42254,
    "edge_count": 871978,
    "average_degree": 41.2732,
    "disk_usage": 81508835,
    "memory_usage": 339640320,
    "peak_memory_usage": 339775488,
    "unreleased_delta_objects": 0,
    "SocketConnect_us_50p": 0,
    "SocketConnect_us_90p": 0,
    "SocketConnect_us_99p": 0
  },
  "Index": {
    "ActiveLabelIndices": 6,
    "ActiveLabelPropertyIndices": 18
  },
  "Transaction": {
    "ActiveTransactions": 1,
    "CommitedTransactions": 0,
    "RollbackedTransactions": 0
  }
}

Metric naming

The JSON endpoint uses different metric names from the OpenMetrics tables above, and groups metrics into categories. Histogram values are reported in microseconds with _us_50p, _us_90p, _us_99p suffixes rather than as native Prometheus histograms in seconds.

Some notable name differences:

OpenMetrics nameJSON nameJSON category
memgraph_vertex_countvertex_countGeneral
memgraph_edge_countedge_countGeneral
memgraph_memory_res_bytesmemory_usageGeneral
memgraph_peak_memory_res_bytespeak_memory_usageGeneral
memgraph_disk_usage_bytesdisk_usageGeneral
memgraph_rolled_back_transactions_totalRollbackedTransactionsTransaction
memgraph_query_execution_latency_secondsQueryExecutionLatency_us_50p/90p/99pQuery
memgraph_active_label_indicesActiveLabelIndicesIndex

The full set of JSON names can be seen in the SHOW METRICS INFO output documented on the server stats page.

Aggregated metrics

The JSON format aggregates per-database metrics into global totals; it does not expose per-database breakdowns. For per-database visibility, use --metrics-format=OpenMetrics or the SHOW METRICS INFO Cypher query.

HA counter reset behaviour

All HA metrics with type Counter are aggregated for all coordinators. That makes it easier for users to track what is going on since they don’t need to aggregate by their own metrics specific to each coordinators. Also, after every pull, HA metrics with type Counter are in Memgraph reset to 0. This makes it possible to use Gauge on the client side without worrying that on restart we will lose all data.

The ReplicaRecoverySuccess, ReplicaRecoveryFail, and ReplicaRecoverySkip counters are excluded from this behaviour and report cumulative totals.

mg-exporter

OpenMetrics compatible clients cannot scrape the JSON endpoint directly. Use the separate Prometheus exporter middleware, which reads the JSON endpoint and re-exposes metrics in a Prometheus-compatible format.

Migrating from JSON to OpenMetrics

If you are currently using the deprecated JSON metrics endpoint, follow these steps to switch to OpenMetrics.

Configuration change

Set --metrics-format=OpenMetrics instead of JSON. The endpoint address and port remain the same.

If you were using mg-exporter to bridge the JSON endpoint to Prometheus, you can remove it: Prometheus can now scrape the OpenMetrics endpoint directly.

Metric name changes

OpenMetrics uses memgraph_ prefixed, snake_case names (e.g. memgraph_vertex_count) instead of the JSON CamelCase names (e.g. vertex_count). See the metric naming table in the JSON section for a summary of notable differences. You will need to update any dashboard queries or alerting rules that reference the old names.

Histogram format change

⚠️

The OpenMetrics endpoint uses different histogram bucket boundaries from the JSON endpoint. As a result, computed percentiles (p50, p90, p99) may differ slightly from values previously reported by the JSON format for the same workload.

JSON reported histograms as three fixed percentile values in microseconds with _us_50p, _us_90p, _us_99p suffixes. OpenMetrics exposes native Prometheus histograms in seconds with configurable bucket boundaries. Update any dashboard panels that reference histogram metrics to use Prometheus histogram_quantile() functions and adjust for the unit change.

Per-database labels

The JSON endpoint aggregated all database metrics into global totals. The OpenMetrics endpoint exposes metrics per database, using database and uuid labels. Existing dashboard queries that expect flat, unlabelled metrics will need to be updated — either by filtering on a specific database label or by aggregating with sum().

HA counter semantics

In the JSON endpoint, most HA counter metrics use delta semantics: they reset to zero after each scrape. In OpenMetrics, all counters are cumulative (as per the Prometheus data model). If your alerting rules relied on the delta behaviour, switch to using rate() or increase() functions in your queries.

New metrics

The OpenMetrics endpoint exposes instance status gauges for each registered HA instance (e.g. memgraph_instance_is_alive, memgraph_instance_is_main). These are not available in the JSON format.

Session trace

A session refers to a temporary, interactive connection from a client (either a user or an application) to the database server, used to execute a series of transactions and queries. Session trace is a feature in Memgraph that allows you to profile the execution of all queries within a session, providing detailed information on query parsing, planning and execution. This can be invaluable for understanding performance bottlenecks and optimizing database interactions.

Session trace events are emitted into the main Memgraph log at the INFO level, tagged with the session that produced them. There is no separate per-session log file — every traced session interleaves into the same log stream and is told apart by its [session=<uuid>] tag.

Session trace events are written at the INFO level, so they are only visible when --log-level is set to INFO, DEBUG or TRACE. If you enable session trace while the log level filters INFO out, Memgraph logs a warning and no trace events appear. Lower the level at startup, or during runtime with SET DATABASE SETTING "log.level" TO "INFO";.

Enabling session trace

Enable session trace for your current session using the following command:

SET SESSION TRACE ON;

The command returns the unique UUID of the session being traced:

session uuid
”de9c907b-6675-40bd-bf09-d4ce7b24f22d”

Use this UUID to find the session’s events in the log. From this point on, every query executed in the session emits tagged trace events until tracing is turned off.

Reading the trace

Each trace event is a line in the main log prefixed with the session tag, the user (when authenticated) and the current transaction id:

[session=<uuid>] [user=<user>] [tx=<id>] <event>

To isolate a single session’s trace, filter the main log by its UUID:

grep -F '[session=de9c907b-6675-40bd-bf09-d4ce7b24f22d]' /var/log/memgraph/<memgraph_date>.log

The trace captures detailed information for every query executed during the session, including:

  • Session UUID, user and transaction ID: carried on every tagged line.
  • Accepted query: the query text as received.
  • Parsing, planning and execution timings: start and end markers and durations for each phase.
  • Explain and profile plans: the query’s plan and, after execution, its profiling statistics and execution counters.
  • Commit timings: start and end markers for the commit phase.
  • Failed queries: the error message when a query throws.

This detailed logging helps in profiling the entire session workload, increasing visibility into potential performance bottlenecks without enabling trace-level logging globally.

Trace coverage is bounded to the connection’s own thread. Work that Memgraph hands off to background threads (for example parallel index creation, replication, garbage collection or Raft) is not attributed to the session and does not appear in its trace.

Disabling session trace

To stop emitting trace events for the current session, use the following command:

SET SESSION TRACE OFF;

After executing this command, no further trace events are written for the active session.