这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions create/bin/gen_history_upgrade.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

my @dbs = ('mysql', 'oracle', 'postgresql', 'timescaledb');
my @tables = ('history', 'history_uint', 'history_str', 'history_log', 'history_text');
my @tables_tsdb = ('history', 'history_uint', 'history_str', 'history_log', 'history_text', 'trends');
my @tables_tsdb = ('history', 'history_uint', 'history_str', 'history_log', 'history_text', 'trends', 'proxy_history');

my %mysql = (
'alter_table' => 'RENAME TABLE %TBL TO %TBL_old;',
Expand Down Expand Up @@ -137,6 +137,22 @@
value_min DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,
value_avg DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,
value_max DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,
HEREDOC
, 'proxy_history' => <<'HEREDOC'
id bigint NOT NULL,
itemid bigint NOT NULL,
clock integer DEFAULT '0' NOT NULL,
timestamp integer DEFAULT '0' NOT NULL,
source varchar(64) DEFAULT '' NOT NULL,
severity integer DEFAULT '0' NOT NULL,
value text DEFAULT '' NOT NULL,
logeventid integer DEFAULT '0' NOT NULL,
ns integer DEFAULT '0' NOT NULL,
state integer DEFAULT '0' NOT NULL,
lastlogsize bigint DEFAULT '0' NOT NULL,
mtime integer DEFAULT '0' NOT NULL,
flags integer DEFAULT '0' NOT NULL,
write_clock integer DEFAULT '0' NOT NULL,
HEREDOC
);

Expand Down Expand Up @@ -225,7 +241,7 @@
tsdb_version_minor INTEGER;
compress_after INTEGER;
BEGIN
PERFORM create_hypertable('%HISTTBL', 'clock', chunk_time_interval => (
PERFORM create_hypertable('%HISTTBL', '%PARTCOL', chunk_time_interval => (
SELECT integer_interval FROM timescaledb_information.dimensions WHERE hypertable_name='%HISTTBL_old'
), migrate_data => true);

Expand Down Expand Up @@ -258,6 +274,10 @@ sub output_table {
{
$pk_constraint =~ s/%HISTPK/itemid,clock/g;
}
elsif ($tbl eq 'proxy_history')
{
$pk_constraint =~ s/%HISTPK/id/g;
}
else
{
$pk_constraint =~ s/%HISTPK/itemid,clock,ns/g;
Expand All @@ -281,14 +301,21 @@ sub output_tsdb {
{
$tsdb_compress_sql =~ s/%COMPRESS_ORDERBY/clock/g;
$tsdb_out =~ s/%HISTPK/itemid,clock/g;
$tsdb_out =~ s/%PARTCOL/clock/g;
}
elsif ($tbl eq 'proxy_history')
{
$tsdb_out =~ s/%HISTPK/id/g;
$tsdb_out =~ s/%PARTCOL/id/g;
}
else
{
$tsdb_compress_sql =~ s/%COMPRESS_ORDERBY/clock,ns/g;
$tsdb_out =~ s/%HISTPK/itemid,clock,ns/g;
$tsdb_out =~ s/%PARTCOL/clock/g;
}

if ((defined $tsdb_compression) && $tsdb_compression eq 'with_compression')
if ((defined $tsdb_compression) && $tsdb_compression eq 'with_compression' && $tbl ne 'proxy_history')
{
$tsdb_out =~ s/%COMPRESS/$tsdb_compress_sql/g;
$tsdb_out =~ s/%CONFIG_COMPR/UPDATE config SET compression_status=1;/g;
Expand Down
8 changes: 8 additions & 0 deletions create/bin/gen_schema.pl
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,14 @@ BEGIN
;
}

for ("proxy_history")
{
print<<EOF
PERFORM create_hypertable('$_', 'id', chunk_time_interval => 1000000, $flags);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our testing, 1000000 is a good balance between low throughput and high throughput systems, such that it may be a few hours before a partition is dropped on a small proxy, while not too many partitions are created between housekeeping executions for large proxy.

EOF
;
}

print<<EOF

IF (current_db_extension = 'timescaledb') THEN
Expand Down
52 changes: 51 additions & 1 deletion src/zabbix_proxy/housekeeper/housekeeper_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "zbx_rtc_constants.h"
#include "zbxipcservice.h"
#include "zbxdbhigh.h"
#include "zbxstr.h"
#include "zbxdb.h"

/******************************************************************************
Expand Down Expand Up @@ -75,6 +76,55 @@ static int delete_history(const char *table, const char *lastid_field, const cha
ZBX_STR2UINT64(maxid, row[0]);
zbx_db_free_result(result);

#if defined(HAVE_POSTGRESQL)
const char* enable_timescale = getenv("ENABLE_TIMESCALEDB");

if (0 == strcmp(table,"proxy_history") && 0 == zbx_strcmp_null(enable_timescale, "true"))
{
zbx_uint64_t keep_from;

if (0 != config_local_buffer)
condition = zbx_dsprintf(NULL, " or %s>=%d", clock_field, now - config_local_buffer * SEC_PER_HOUR);

result = zbx_db_select(
"select floor(coalesce(min(id)," ZBX_FS_UI64 ")/1000000)*1000000 from %s"
" where (id>" ZBX_FS_UI64 " and %s>=%d) %s",
maxid + 1, table, lastid,
clock_field, now - config_offline_buffer * SEC_PER_HOUR,
ZBX_NULL2EMPTY_STR(condition));
zbx_free(condition);

if (NULL == (row = zbx_db_fetch(result)) || SUCCEED == zbx_db_is_null(row[0]))
goto rollback;

ZBX_STR2UINT64(keep_from, row[0]);
zbx_db_free_result(result);

zabbix_log(LOG_LEVEL_TRACE, "%s: table=%s keep_from=" ZBX_FS_UI64, __func__, table, keep_from);

result = zbx_db_select("select count(id) from %s where id < " ZBX_FS_UI64, table, keep_from);

if (NULL == (row = zbx_db_fetch(result)) || SUCCEED == zbx_db_is_null(row[0]))
goto rollback;

ZBX_STR2UINT64(records, row[0]);
zbx_db_free_result(result);

result = zbx_db_select("select drop_chunks(relation=>'%s',older_than=>" ZBX_FS_UI64 ")", table, keep_from);

if (NULL == result)
{
zabbix_log(LOG_LEVEL_ERR, "cannot drop chunks for %s", table);
goto rollback;
}

zbx_db_commit();

zbx_db_free_result(result);
goto skip;
}
#endif

if (0 != config_local_buffer)
condition = zbx_dsprintf(NULL, " and %s<%d", clock_field, now - config_local_buffer * SEC_PER_HOUR);

Expand All @@ -89,7 +139,7 @@ static int delete_history(const char *table, const char *lastid_field, const cha
zbx_free(condition);

zbx_db_commit();

skip:
return records;
rollback:
zbx_db_free_result(result);
Expand Down