#ifndef RUDB_AWR_HPP
|
#define RUDB_AWR_HPP
|
|
#include <cstdint>
|
#include <optional>
|
#include <string>
|
#include <vector>
|
|
extern "C" void rudb_awr_init(void);
|
extern "C" void rudb_awr_postmaster_init(void);
|
|
extern "C"
|
{
|
#include "postgres.h"
|
#include "utils/timestamp.h"
|
}
|
|
/**
|
* Назначение:
|
* Управление локальными снимками AWR, архивирование записей ASH
|
* и подготовка данных для отчётных пакетов.
|
*/
|
namespace rudb::awr
|
{
|
enum class WorkerState : int
|
{
|
Empty = 0,
|
Pending,
|
Starting,
|
Running,
|
Backoff,
|
Disabled,
|
Stopping,
|
Error
|
};
|
|
/** Параметры XML с метаданными выбора временного диапазона. */
|
struct TimepickerMetadataRequest
|
{
|
bool include_metadata = false;
|
int64_t dbid = 0;
|
int retention_seconds = 0;
|
};
|
|
/** Границы отчёта по снимкам AWR применяются как (начало, конец]. */
|
struct SnapshotReportRequest
|
{
|
int64_t dbid = 0;
|
int64_t inst_num = 1;
|
int64_t begin_snap_id = 0;
|
int64_t end_snap_id = 0;
|
std::optional<int64_t> options;
|
};
|
|
/** Параметры SQL-отчёта с необязательным ограничением SQL_ID и DBID контейнера. */
|
struct SqlReportRequest
|
{
|
int64_t dbid = 0;
|
int64_t inst_num = 1;
|
int64_t begin_snap_id = 0;
|
int64_t end_snap_id = 0;
|
std::optional<std::string> sql_id;
|
std::optional<int64_t> options;
|
std::optional<int64_t> con_dbid;
|
};
|
|
// Инициализация и локальный DBID.
|
void initialize(void);
|
bool is_initialized(void);
|
int64_t local_dbid(void);
|
std::optional<int64_t> get_awr_id(const std::optional<std::string>& hub_name,
|
const std::optional<std::string>& source_name);
|
int64_t validate_local_dbid(const std::optional<int64_t>& requested_dbid);
|
// Создание и удаление снимков AWR.
|
const char* launcher_database(void);
|
int snapshot_interval_seconds(void);
|
int retention_seconds(void);
|
int effective_snapshot_interval_seconds(int64_t dbid);
|
int effective_retention_seconds(int64_t dbid);
|
void modify_snapshot_settings(int64_t dbid,
|
const std::optional<int>& retention_minutes,
|
const std::optional<int>& interval_minutes);
|
void maybe_rotate_snapshot_marker(TimestampTz now);
|
int64_t create_snapshot(int64_t dbid, int64_t instance_number, bool automatic = false);
|
void drop_snapshot_range(int64_t dbid, int64_t low_snap_id, int64_t high_snap_id);
|
void purge_expired_history(int64_t dbid, TimestampTz now);
|
// Формирование отчётов.
|
std::vector<std::string> report_text(const SnapshotReportRequest& request);
|
std::vector<std::string> report_html(const SnapshotReportRequest& request);
|
std::vector<std::string> sql_report_text(const SqlReportRequest& request);
|
std::vector<std::string> sql_report_html(const SqlReportRequest& request);
|
// Метаданные выбора временного диапазона.
|
std::string build_timepicker_metadata_xml(const TimepickerMetadataRequest& request);
|
// Состояние механизма.
|
std::string service_state(void);
|
} // namespace rudb::awr
|
|
#endif
|