Skip to content

Commit

Permalink
Function to return sqlite database space
Browse files Browse the repository at this point in the history
Compile with disable-ml properly
Do proper time retention check
Temporary additional info in node_instances api
  • Loading branch information
stelfrag committed Apr 24, 2024
1 parent 8065bbf commit d280a21
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/database/contexts/api_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,7 @@ void buffer_json_agents_v2(BUFFER *wb, struct query_timings *timings, time_t now
buffer_json_add_array_item_object(wb);
buffer_json_member_add_uint64(wb, "tier", tier);
char human_retention[128];
//buffer_json_member_add_uint64(wb, "point_every", group_seconds);
convert_seconds_to_dhms(group_seconds, human_retention, sizeof(human_retention) - 1);
convert_seconds_to_dhms((time_t) group_seconds, human_retention, sizeof(human_retention) - 1);
buffer_json_member_add_string(wb, "point_every", human_retention);

buffer_json_member_add_uint64(wb, "metrics", storage_engine_metrics(eng->seb, localhost->db[tier].si));
Expand All @@ -1188,6 +1187,12 @@ void buffer_json_agents_v2(BUFFER *wb, struct query_timings *timings, time_t now
time_t space_retention = (time_t)((NETDATA_DOUBLE)(now_s - first_time_s) * 100.0 / percent);
time_t actual_retention = MIN(space_retention, time_retention ? time_retention : space_retention);

if (time_retention) {
convert_seconds_to_dhms(time_retention, human_retention, sizeof(human_retention) - 1);
buffer_json_member_add_time_t(wb, "requested_retention", time_retention);
buffer_json_member_add_string(wb, "requested_retention_human", human_retention);
}

convert_seconds_to_dhms(actual_retention, human_retention, sizeof(human_retention) - 1);
buffer_json_member_add_time_t(wb, "expected_retention", actual_retention);
buffer_json_member_add_string(wb, "expected_retention_human", human_retention);
Expand Down
4 changes: 2 additions & 2 deletions src/database/engine/rrdengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ static uint64_t get_used_disk_space(struct rrdengine_instance *ctx)

uint64_t estimated_disk_space = ctx_current_disk_space_get(ctx) + rrdeng_target_data_file_size(ctx) - active_space;

uint64_t database_space = sqlite_get_db_space(db_meta) + sqlite_get_context_space() + sqlite_get_ml_space();
uint64_t database_space = get_total_database_space();
uint64_t adjusted_database_space = database_space * ctx->config.disk_percentage / 100 ;
estimated_disk_space += adjusted_database_space;

Expand Down Expand Up @@ -1630,7 +1630,7 @@ bool rrdeng_ctx_tier_cap_exceeded(struct rrdengine_instance *ctx)
uint64_t estimated_disk_space = get_used_disk_space(ctx);
time_t retention = get_tier_retention(ctx);

if (retention && retention > ctx->config.max_retention_s)
if (ctx->config.max_retention_s && retention > ctx->config.max_retention_s)
return true;

if (ctx->config.max_disk_space && estimated_disk_space > ctx->config.max_disk_space)
Expand Down
9 changes: 9 additions & 0 deletions src/database/sqlite/sqlite_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ void sqlite_close_databases(void)
sql_close_database(db_meta, "METADATA");
}

uint64_t get_total_database_space(void)
{
uint64_t database_space = sqlite_get_meta_space() + sqlite_get_context_space();
#ifdef ENABLE_ML
database_space += sqlite_get_ml_space();
#endif
return database_space;
}

int sqlite_library_init(void)
{
initialize_thread_key_pool();
Expand Down
1 change: 1 addition & 0 deletions src/database/sqlite/sqlite_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ void sqlite_library_shutdown(void);

void sql_close_database(sqlite3 *database, const char *database_name);
void sqlite_close_databases(void);
uint64_t get_total_database_space(void);
#endif //NETDATA_SQLITE_FUNCTIONS_H
4 changes: 4 additions & 0 deletions src/database/sqlite/sqlite_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,10 @@ void metadata_delete_host_chart_labels(char *machine_guid)
nd_log(NDLS_DAEMON, NDLP_DEBUG, "Queued command delete chart labels for host %s", machine_guid);
}

uint64_t sqlite_get_meta_space(void)
{
return sqlite_get_db_space(db_meta);
}

//
// unitests
Expand Down

0 comments on commit d280a21

Please sign in to comment.