ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
telemetry_repository Class Reference

Repository for telemetry log persistence and querying. More...

#include <telemetry_repository.hpp>

Collaboration diagram for telemetry_repository:
Collaboration graph

Public Types

using context = ores::database::context
 

Public Member Functions

std::string sql ()
 Returns the SQL created by sqlgen to construct the table.
 
void create (context ctx, const domain::telemetry_log_entry &entry)
 Creates a single log entry.
 
std::size_t create_batch (context ctx, const domain::telemetry_batch &batch)
 Creates multiple log entries in a batch.
 
std::vector< domain::telemetry_log_entryquery (context ctx, const domain::telemetry_query &q)
 Queries log entries with filters.
 
std::uint64_t count (context ctx, const domain::telemetry_query &q)
 Counts log entries matching a query.
 
std::vector< domain::telemetry_log_entryread_by_session (context ctx, const boost::uuids::uuid &session_id, std::uint32_t limit=1000)
 Reads logs for a specific session.
 
std::vector< domain::telemetry_log_entryread_by_account (context ctx, const boost::uuids::uuid &account_id, const std::chrono::system_clock::time_point &start, const std::chrono::system_clock::time_point &end, std::uint32_t limit=1000)
 Reads logs for a specific account.
 
std::vector< domain::telemetry_statsread_hourly_stats (context ctx, const domain::telemetry_stats_query &q)
 Reads hourly statistics.
 
std::vector< domain::telemetry_statsread_daily_stats (context ctx, const domain::telemetry_stats_query &q)
 Reads daily statistics.
 
domain::telemetry_summary get_summary (context ctx, std::uint32_t hours=24)
 Gets a summary of telemetry activity.
 
std::uint64_t count_errors (context ctx, const std::string &source_name, std::uint32_t hours=1)
 Counts error logs in the last N hours for a source.
 
std::uint64_t delete_old_logs (context ctx, const std::chrono::system_clock::time_point &older_than)
 Deletes logs older than the specified retention period.
 
void insert_server_sample (context ctx, const domain::nats_server_sample &sample)
 Inserts a single NATS server-level metrics sample.
 
void insert_stream_samples (context ctx, const std::vector< domain::nats_stream_sample > &samples)
 Inserts a batch of NATS per-stream metrics samples.
 
std::vector< domain::nats_server_samplequery_server_samples (context ctx, const domain::nats_server_samples_query &q)
 Queries NATS server samples within a time range.
 
std::vector< domain::nats_stream_samplequery_stream_samples (context ctx, const domain::nats_stream_samples_query &q)
 Queries NATS stream samples within a time range.
 
void insert_service_sample (context ctx, const domain::service_sample &sample)
 Inserts a single service heartbeat sample.
 
std::vector< domain::service_samplelist_service_samples (context ctx)
 Returns the latest heartbeat per (service_name, instance_id).
 

Detailed Description

Repository for telemetry log persistence and querying.

Handles CRUD operations for telemetry log records stored in a TimescaleDB hypertable. Supports time-range queries and statistics aggregation.

Member Function Documentation

◆ create_batch()

std::size_t create_batch ( context  ctx,
const domain::telemetry_batch batch 
)

Creates multiple log entries in a batch.

More efficient than individual inserts for bulk operations.

Returns
Number of entries successfully inserted.

◆ count()

std::uint64_t count ( context  ctx,
const domain::telemetry_query q 
)

Counts log entries matching a query.

Useful for pagination.

Here is the caller graph for this function:

◆ read_by_session()

std::vector< domain::telemetry_log_entry > read_by_session ( context  ctx,
const boost::uuids::uuid &  session_id,
std::uint32_t  limit = 1000 
)

Reads logs for a specific session.

Parameters
ctxThe database context
session_idThe session UUID
limitMaximum number of logs to return
Returns
Logs ordered by timestamp descending (newest first)

◆ read_by_account()

std::vector< domain::telemetry_log_entry > read_by_account ( context  ctx,
const boost::uuids::uuid &  account_id,
const std::chrono::system_clock::time_point &  start,
const std::chrono::system_clock::time_point &  end,
std::uint32_t  limit = 1000 
)

Reads logs for a specific account.

Parameters
ctxThe database context
account_idThe account UUID
startStart of time range
endEnd of time range
limitMaximum number of logs to return

◆ get_summary()

domain::telemetry_summary get_summary ( context  ctx,
std::uint32_t  hours = 24 
)

Gets a summary of telemetry activity.

Parameters
ctxThe database context
hoursNumber of hours to include (default: 24)

◆ count_errors()

std::uint64_t count_errors ( context  ctx,
const std::string &  source_name,
std::uint32_t  hours = 1 
)

Counts error logs in the last N hours for a source.

Useful for monitoring and alerting.

Parameters
ctxThe database context

◆ delete_old_logs()

std::uint64_t delete_old_logs ( context  ctx,
const std::chrono::system_clock::time_point &  older_than 
)

Deletes logs older than the specified retention period.

Note: With TimescaleDB, this is typically handled by retention policies. This method is for manual cleanup or non-TimescaleDB deployments.

Parameters
ctxThe database context
older_thanDelete logs older than this timestamp
Returns
Number of logs deleted

◆ insert_service_sample()

void insert_service_sample ( context  ctx,
const domain::service_sample sample 
)

Inserts a single service heartbeat sample.

Called by the telemetry service each time it receives a heartbeat publish from a domain service.

◆ list_service_samples()

std::vector< domain::service_sample > list_service_samples ( context  ctx)

Returns the latest heartbeat per (service_name, instance_id).

Used by the service dashboard to determine which services are currently running and when they were last seen.