From 29ac1595004db35053dc0d586c7143d03a58cf3b Mon Sep 17 00:00:00 2001 From: thiagoftsm Date: Wed, 20 Nov 2024 22:33:53 +0000 Subject: [PATCH] Fix MSSQL algorithm (Windows.plugin) (#19035) Co-authored-by: ilyam8 --- src/collectors/windows.plugin/perflib-mssql.c | 464 ++++++++++-------- 1 file changed, 259 insertions(+), 205 deletions(-) diff --git a/src/collectors/windows.plugin/perflib-mssql.c b/src/collectors/windows.plugin/perflib-mssql.c index e8b5b6641a51cc..f6f5c434d8d1fb 100644 --- a/src/collectors/windows.plugin/perflib-mssql.c +++ b/src/collectors/windows.plugin/perflib-mssql.c @@ -71,13 +71,6 @@ struct mssql_instance { RRDSET *st_deadLocks; DICTIONARY *locks_instances; - RRDSET *st_db_data_file_size; - RRDSET *st_db_active_transactions; - RRDSET *st_db_backup_restore_operations; - RRDSET *st_db_log_flushed; - RRDSET *st_db_log_flushes; - RRDSET *st_db_transactions; - RRDSET *st_db_write_transactions; DICTIONARY *databases; RRDSET *st_conn_memory; @@ -112,6 +105,13 @@ struct mssql_instance { COUNTER_DATA MSSQLRecompilations; }; +enum lock_instance_idx { + NETDATA_MSSQL_ENUM_MLI_IDX_WAIT, + NETDATA_MSSQL_ENUM_MLI_IDX_DEAD_LOCKS, + + NETDATA_MSSQL_ENUM_MLI_IDX_END +}; + struct mssql_lock_instance { struct mssql_instance *parent; @@ -120,18 +120,32 @@ struct mssql_lock_instance { RRDDIM *rd_lockWait; RRDDIM *rd_deadLocks; + + uint32_t updated; +}; + +enum db_instance_idx { + NETDATA_MSSQL_ENUM_MDI_IDX_FILE_SIZE, + NETDATA_MSSQL_ENUM_MDI_IDX_ACTIVE_TRANSACTIONS, + NETDATA_MSSQL_ENUM_MDI_IDX_BACKUP_RESTORE_OP, + NETDATA_MSSQL_ENUM_MDI_IDX_LOG_FLUSHED, + NETDATA_MSSQL_ENUM_MDI_IDX_LOG_FLUSHES, + NETDATA_MSSQL_ENUM_MDI_IDX_TRANSACTIONS, + NETDATA_MSSQL_ENUM_MDI_IDX_WRITE_TRANSACTIONS, + + NETDATA_MSSQL_ENUM_MDI_IDX_END }; struct mssql_db_instance { struct mssql_instance *parent; - COUNTER_DATA MSSQLDatabaseActiveTransactions; - COUNTER_DATA MSSQLDatabaseBackupRestoreOperations; - COUNTER_DATA MSSQLDatabaseDataFileSize; - COUNTER_DATA MSSQLDatabaseLogFlushed; - COUNTER_DATA MSSQLDatabaseLogFlushes; - COUNTER_DATA MSSQLDatabaseTransactions; - COUNTER_DATA MSSQLDatabaseWriteTransactions; + RRDSET *st_db_data_file_size; + RRDSET *st_db_active_transactions; + RRDSET *st_db_backup_restore_operations; + RRDSET *st_db_log_flushed; + RRDSET *st_db_log_flushes; + RRDSET *st_db_transactions; + RRDSET *st_db_write_transactions; RRDDIM *rd_db_data_file_size; RRDDIM *rd_db_active_transactions; @@ -140,6 +154,16 @@ struct mssql_db_instance { RRDDIM *rd_db_log_flushes; RRDDIM *rd_db_transactions; RRDDIM *rd_db_write_transactions; + + COUNTER_DATA MSSQLDatabaseActiveTransactions; + COUNTER_DATA MSSQLDatabaseBackupRestoreOperations; + COUNTER_DATA MSSQLDatabaseDataFileSize; + COUNTER_DATA MSSQLDatabaseLogFlushed; + COUNTER_DATA MSSQLDatabaseLogFlushes; + COUNTER_DATA MSSQLDatabaseTransactions; + COUNTER_DATA MSSQLDatabaseWriteTransactions; + + uint32_t updated; }; static DICTIONARY *mssql_instances = NULL; @@ -182,7 +206,6 @@ static void initialize_mssql_objects(struct mssql_instance *p, const char *insta p->objectName[NETDATA_MSSQL_ACCESS_METHODS] = strdup(name); p->instanceID = strdup(instance); - netdata_fix_chart_name(p->instanceID); } static inline void initialize_mssql_keys(struct mssql_instance *p) { @@ -226,7 +249,6 @@ void dict_mssql_insert_databases_cb(const DICTIONARY_ITEM *item __maybe_unused, struct mssql_db_instance *ptr = value; ptr->MSSQLDatabaseDataFileSize.key = "Data File(s) Size (KB)"; - ptr->MSSQLDatabaseActiveTransactions.key = "Active Transactions"; ptr->MSSQLDatabaseBackupRestoreOperations.key = "Backup/Restore Throughput/sec"; ptr->MSSQLDatabaseLogFlushed.key = "Log Bytes Flushed/sec"; @@ -315,19 +337,21 @@ static int initialize(void) { static void do_mssql_general_stats(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; + PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, p->objectName[NETDATA_MSSQL_GENERAL_STATS]); if (!pObjectType) return; if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLUserConnections)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_user_connection", p->instanceID); if (!p->st_user_connections) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_user_connections", p->instanceID); + netdata_fix_chart_name(id); p->st_user_connections = rrdset_create_localhost( "mssql", id, NULL, "connections", - "mssql.instance_user_connection", + "mssql.instance_user_connections", "User connections", "connections", PLUGIN_WINDOWS_NAME, @@ -336,8 +360,7 @@ static void do_mssql_general_stats(PERF_DATA_BLOCK *pDataBlock, struct mssql_ins update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_genstats_user_connections", p->instanceID); - p->rd_user_connections = rrddim_add(p->st_user_connections, id, "user", 1, 1, RRD_ALGORITHM_ABSOLUTE); + p->rd_user_connections = rrddim_add(p->st_user_connections, "user", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add(p->st_user_connections->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -348,8 +371,9 @@ static void do_mssql_general_stats(PERF_DATA_BLOCK *pDataBlock, struct mssql_ins } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLBlockedProcesses)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_blocked_process", p->instanceID); if (!p->st_process_blocked) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_blocked_process", p->instanceID); + netdata_fix_chart_name(id); p->st_process_blocked = rrdset_create_localhost( "mssql", id, @@ -364,8 +388,7 @@ static void do_mssql_general_stats(PERF_DATA_BLOCK *pDataBlock, struct mssql_ins update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_genstats_blocked_processes", p->instanceID); - p->rd_process_blocked = rrddim_add(p->st_process_blocked, id, "blocked", 1, 1, RRD_ALGORITHM_ABSOLUTE); + p->rd_process_blocked = rrddim_add(p->st_process_blocked, "blocked", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add(p->st_process_blocked->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -378,13 +401,15 @@ static void do_mssql_general_stats(PERF_DATA_BLOCK *pDataBlock, struct mssql_ins static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; + PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, p->objectName[NETDATA_MSSQL_SQL_STATS]); if (!pObjectType) return; if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLStatsAutoParameterization)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_auto_parameterization_attempts", p->instanceID); if (!p->st_stats_auto_param) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_auto_parameterization_attempts", p->instanceID); + netdata_fix_chart_name(id); p->st_stats_auto_param = rrdset_create_localhost( "mssql", id, @@ -399,9 +424,8 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in update_every, RRDSET_TYPE_LINE); - snprintfz( - id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_sqlstats_auto_parameterization_attempts", p->instanceID); - p->rd_stats_auto_param = rrddim_add(p->st_stats_auto_param, id, "failed", 1, 1, RRD_ALGORITHM_INCREMENTAL); + p->rd_stats_auto_param = + rrddim_add(p->st_stats_auto_param, "failed", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_stats_auto_param->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -414,8 +438,9 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLStatsBatchRequests)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_batch_requests", p->instanceID); if (!p->st_stats_batch_request) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_batch_requests", p->instanceID); + netdata_fix_chart_name(id); p->st_stats_batch_request = rrdset_create_localhost( "mssql", id, @@ -430,9 +455,8 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_sqlstats_batch_requests", p->instanceID); p->rd_stats_batch_request = - rrddim_add(p->st_stats_batch_request, id, "batch", 1, 1, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(p->st_stats_batch_request, "batch", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_stats_batch_request->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -445,8 +469,9 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLStatSafeAutoParameterization)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_safe_auto_parameterization_attempts", p->instanceID); if (!p->st_stats_safe_auto) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_safe_auto_parameterization_attempts", p->instanceID); + netdata_fix_chart_name(id); p->st_stats_safe_auto = rrdset_create_localhost( "mssql", id, @@ -461,9 +486,7 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in update_every, RRDSET_TYPE_LINE); - snprintfz( - id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_sqlstats_safe_auto_parameterization_attempts", p->instanceID); - p->rd_stats_safe_auto = rrddim_add(p->st_stats_safe_auto, id, "safe", 1, 1, RRD_ALGORITHM_INCREMENTAL); + p->rd_stats_safe_auto = rrddim_add(p->st_stats_safe_auto, "safe", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_stats_safe_auto->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -476,8 +499,9 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLCompilations)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_sql_compilations", p->instanceID); if (!p->st_stats_compilation) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_sql_compilations", p->instanceID); + netdata_fix_chart_name(id); p->st_stats_compilation = rrdset_create_localhost( "mssql", id, @@ -492,9 +516,8 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_sqlstats_sql_compilations", p->instanceID); p->rd_stats_compilation = - rrddim_add(p->st_stats_compilation, id, "compilations", 1, 1, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(p->st_stats_compilation, "compilations", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_stats_compilation->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -505,8 +528,9 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLRecompilations)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_sql_recompilations", p->instanceID); if (!p->st_stats_recompiles) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sqlstats_sql_recompilations", p->instanceID); + netdata_fix_chart_name(id); p->st_stats_recompiles = rrdset_create_localhost( "mssql", id, @@ -521,9 +545,8 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_sqlstats_sql_recompilations", p->instanceID); p->rd_stats_recompiles = - rrddim_add(p->st_stats_recompiles, id, "recompiles", 1, 1, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(p->st_stats_recompiles, "recompiles", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_stats_recompiles->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -536,14 +559,16 @@ static void do_mssql_sql_statistics(PERF_DATA_BLOCK *pDataBlock, struct mssql_in static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; + PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, p->objectName[NETDATA_MSSQL_BUFFER_MANAGEMENT]); if (!pObjectType) return; if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLBufferCacheHits)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_cache_hit_ratio", p->instanceID); if (!p->st_buff_cache_hits) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_cache_hit_ratio", p->instanceID); + netdata_fix_chart_name(id); p->st_buff_cache_hits = rrdset_create_localhost( "mssql", id, @@ -558,8 +583,7 @@ static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_cache_hit_ratio", p->instanceID); - p->rd_buff_cache_hits = rrddim_add(p->st_buff_cache_hits, id, "hit_ratio", 1, 1, RRD_ALGORITHM_ABSOLUTE); + p->rd_buff_cache_hits = rrddim_add(p->st_buff_cache_hits, "hit_ratio", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add(p->st_buff_cache_hits->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -570,8 +594,9 @@ static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLBufferCheckpointPages)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_bufman_checkpoint_pages", p->instanceID); if (!p->st_buff_checkpoint_pages) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_bufman_checkpoint_pages", p->instanceID); + netdata_fix_chart_name(id); p->st_buff_checkpoint_pages = rrdset_create_localhost( "mssql", id, @@ -586,9 +611,8 @@ static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_bufman_checkpoint_pages", p->instanceID); p->rd_buff_checkpoint_pages = - rrddim_add(p->st_buff_checkpoint_pages, id, "log", 1, 1, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(p->st_buff_checkpoint_pages, "log", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_buff_checkpoint_pages->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -601,8 +625,9 @@ static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLBufferPageLifeExpectancy)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_bufman_page_life_expectancy", p->instanceID); if (!p->st_buff_cache_page_life_expectancy) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_bufman_page_life_expectancy", p->instanceID); + netdata_fix_chart_name(id); p->st_buff_cache_page_life_expectancy = rrdset_create_localhost( "mssql", id, @@ -617,9 +642,8 @@ static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_bufman_page_life_expectancy_seconds", p->instanceID); - p->rd_buff_cache_page_life_expectancy = - rrddim_add(p->st_buff_cache_page_life_expectancy, id, "life_expectancy", 1, 1, RRD_ALGORITHM_ABSOLUTE); + p->rd_buff_cache_page_life_expectancy = rrddim_add( + p->st_buff_cache_page_life_expectancy, "life_expectancy", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add( p->st_buff_cache_page_life_expectancy->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); @@ -634,8 +658,9 @@ static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLBufferPageReads) && perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLBufferPageWrites)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_bufman_iops", p->instanceID); if (!p->st_buff_page_iops) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_bufman_iops", p->instanceID); + netdata_fix_chart_name(id); p->st_buff_page_iops = rrdset_create_localhost( "mssql", id, @@ -650,34 +675,34 @@ static void do_mssql_buffer_management(PERF_DATA_BLOCK *pDataBlock, struct mssql update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_bufman_page_reads", p->instanceID); - p->rd_buff_page_reads = rrddim_add(p->st_buff_page_iops, id, "read", 1, 1, RRD_ALGORITHM_INCREMENTAL); - - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_bufman_page_writes", p->instanceID); - p->rd_buff_page_writes = rrddim_add(p->st_buff_page_iops, id, "written", -1, 1, RRD_ALGORITHM_INCREMENTAL); + p->rd_buff_page_reads = rrddim_add(p->st_buff_page_iops, "read", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + p->rd_buff_page_writes = + rrddim_add(p->st_buff_page_iops, "written", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_buff_page_iops->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } rrddim_set_by_pointer( p->st_buff_page_iops, p->rd_buff_page_reads, (collected_number)p->MSSQLBufferPageReads.current.Data); - rrddim_set_by_pointer( p->st_buff_page_iops, p->rd_buff_page_writes, (collected_number)p->MSSQLBufferPageWrites.current.Data); + rrdset_done(p->st_buff_page_iops); } } static void do_mssql_access_methods(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; + PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, p->objectName[NETDATA_MSSQL_ACCESS_METHODS]); if (!pObjectType) return; if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLAccessMethodPageSplits)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_accessmethods_page_splits", p->instanceID); if (!p->st_access_method_page_splits) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_accessmethods_page_splits", p->instanceID); + netdata_fix_chart_name(id); p->st_access_method_page_splits = rrdset_create_localhost( "mssql", id, @@ -692,9 +717,8 @@ static void do_mssql_access_methods(PERF_DATA_BLOCK *pDataBlock, struct mssql_in update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_accessmethods_page_splits", p->instanceID); p->rd_access_method_page_splits = - rrddim_add(p->st_access_method_page_splits, id, "page", 1, 1, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(p->st_access_method_page_splits, "page", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add( p->st_access_method_page_splits->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); @@ -710,20 +734,22 @@ static void do_mssql_access_methods(PERF_DATA_BLOCK *pDataBlock, struct mssql_in static void do_mssql_errors(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; + PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, p->objectName[NETDATA_MSSQL_SQL_ERRORS]); if (!pObjectType) return; if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLSQLErrorsTotal)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sql_errors_total", p->instanceID); if (!p->st_sql_errors) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_sql_errors_total", p->instanceID); + netdata_fix_chart_name(id); p->st_sql_errors = rrdset_create_localhost( "mssql", id, NULL, - "Errors", - "mssql.instance_sql_errors", "errors", + "mssql.instance_sql_errors", + "Errors", "errors/s", PLUGIN_WINDOWS_NAME, "PerflibMSSQL", @@ -731,8 +757,7 @@ static void do_mssql_errors(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance * update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_sql_errors_total", p->instanceID); - p->rd_sql_errors = rrddim_add(p->st_sql_errors, id, "errors", 1, 1, RRD_ALGORITHM_INCREMENTAL); + p->rd_sql_errors = rrddim_add(p->st_sql_errors, "errors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrdlabels_add(p->st_sql_errors->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -745,6 +770,7 @@ static void do_mssql_errors(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance * int dict_mssql_locks_charts_cb(const DICTIONARY_ITEM *item __maybe_unused, void *value, void *data __maybe_unused) { char id[RRD_ID_LENGTH_MAX + 1]; + struct mssql_lock_instance *mli = value; const char *instance = dictionary_acquired_item_name((DICTIONARY_ITEM *)item); @@ -752,6 +778,7 @@ int dict_mssql_locks_charts_cb(const DICTIONARY_ITEM *item __maybe_unused, void if (!mli->parent->st_lockWait) { snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_locks_lock_wait", mli->parent->instanceID); + netdata_fix_chart_name(id); mli->parent->st_lockWait = rrdset_create_localhost( "mssql", id, @@ -766,24 +793,22 @@ int dict_mssql_locks_charts_cb(const DICTIONARY_ITEM *item __maybe_unused, void *update_every, RRDSET_TYPE_LINE); - rrdlabels_add(mli->parent->st_lockWait->rrdlabels, "mssql_instance", instance, RRDLABEL_SRC_AUTO); + rrdlabels_add( + mli->parent->st_lockWait->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); } if (!mli->rd_lockWait) { - snprintfz( - id, - RRD_ID_LENGTH_MAX, - "mssql_instance_%s_resource_%s_locks_lock_wait_seconds", - mli->parent->instanceID, - instance); - - mli->rd_lockWait = rrddim_add(mli->parent->st_lockWait, id, instance, 1, 1, RRD_ALGORITHM_INCREMENTAL); + mli->rd_lockWait = rrddim_add(mli->parent->st_lockWait, instance, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } - rrddim_set_by_pointer(mli->parent->st_lockWait, mli->rd_lockWait, (collected_number)mli->lockWait.current.Data); + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MLI_IDX_WAIT)) { + rrddim_set_by_pointer( + mli->parent->st_lockWait, mli->rd_lockWait, (collected_number)(mli->lockWait.current.Data)); + } if (!mli->parent->st_deadLocks) { snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_locks_deadlocks", mli->parent->instanceID); + netdata_fix_chart_name(id); mli->parent->st_deadLocks = rrdset_create_localhost( "mssql", id, @@ -791,23 +816,25 @@ int dict_mssql_locks_charts_cb(const DICTIONARY_ITEM *item __maybe_unused, void "locks", "mssql.instance_locks_deadlocks", "Lock requests that resulted in deadlock.", - "locks/s", + "deadlocks/s", PLUGIN_WINDOWS_NAME, "PerflibMSSQL", PRIO_MSSQL_LOCKS_DEADLOCK, *update_every, RRDSET_TYPE_LINE); - rrdlabels_add(mli->parent->st_deadLocks->rrdlabels, "mssql_instance", instance, RRDLABEL_SRC_AUTO); + + rrdlabels_add( + mli->parent->st_deadLocks->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); } if (!mli->rd_deadLocks) { - snprintfz( - id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_resource_%s_locks_deadlocks", mli->parent->instanceID, instance); - - mli->rd_deadLocks = rrddim_add(mli->parent->st_deadLocks, id, instance, 1, 1, RRD_ALGORITHM_INCREMENTAL); + mli->rd_deadLocks = rrddim_add(mli->parent->st_deadLocks, instance, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } - rrddim_set_by_pointer(mli->parent->st_deadLocks, mli->rd_deadLocks, (collected_number)mli->deadLocks.current.Data); + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MLI_IDX_DEAD_LOCKS)) { + rrddim_set_by_pointer( + mli->parent->st_deadLocks, mli->rd_deadLocks, (collected_number)mli->deadLocks.current.Data); + } return 1; } @@ -829,7 +856,6 @@ static void do_mssql_locks(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p if (!strcasecmp(windows_shared_buffer, "_Total")) continue; - netdata_fix_chart_name(windows_shared_buffer); struct mssql_lock_instance *mli = dictionary_set(p->locks_instances, windows_shared_buffer, NULL, sizeof(*mli)); if (!mli) continue; @@ -838,8 +864,11 @@ static void do_mssql_locks(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p mli->parent = p; } - perflibGetObjectCounter(pDataBlock, pObjectType, &mli->lockWait); - perflibGetObjectCounter(pDataBlock, pObjectType, &mli->deadLocks); + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mli->lockWait)) + mli->updated |= (1 << NETDATA_MSSQL_ENUM_MLI_IDX_WAIT); + + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mli->deadLocks)) + mli->updated |= (1 << NETDATA_MSSQL_ENUM_MLI_IDX_DEAD_LOCKS); } dictionary_sorted_walkthrough_read(p->locks_instances, dict_mssql_locks_charts_cb, &update_every); @@ -849,9 +878,11 @@ static void do_mssql_locks(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p static void mssql_database_backup_restore_chart(struct mssql_db_instance *mli, const char *db, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; - if (!mli->parent->st_db_backup_restore_operations) { + + if (!mli->st_db_backup_restore_operations) { snprintfz(id, RRD_ID_LENGTH_MAX, "db_%s_instance_%s_backup_restore_operations", db, mli->parent->instanceID); - mli->parent->st_db_backup_restore_operations = rrdset_create_localhost( + netdata_fix_chart_name(id); + mli->st_db_backup_restore_operations = rrdset_create_localhost( "mssql", id, NULL, @@ -866,33 +897,35 @@ static void mssql_database_backup_restore_chart(struct mssql_db_instance *mli, c RRDSET_TYPE_LINE); rrdlabels_add( - mli->parent->st_db_backup_restore_operations->rrdlabels, + mli->st_db_backup_restore_operations->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); - - rrdlabels_add(mli->parent->st_db_backup_restore_operations->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_backup_restore_operations->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); } if (!mli->rd_db_backup_restore_operations) { - snprintfz( - id, RRD_ID_LENGTH_MAX, "mssql_db_%s_instance_%s_backup_restore_operations", db, mli->parent->instanceID); - mli->rd_db_backup_restore_operations = - rrddim_add(mli->parent->st_db_backup_restore_operations, id, db, 1, 1, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(mli->st_db_backup_restore_operations, "backup", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } - rrddim_set_by_pointer( - mli->parent->st_db_backup_restore_operations, - mli->rd_db_backup_restore_operations, - (collected_number)mli->MSSQLDatabaseBackupRestoreOperations.current.Data); + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MDI_IDX_BACKUP_RESTORE_OP)) { + rrddim_set_by_pointer( + mli->st_db_backup_restore_operations, + mli->rd_db_backup_restore_operations, + (collected_number)mli->MSSQLDatabaseBackupRestoreOperations.current.Data); + } + + rrdset_done(mli->st_db_backup_restore_operations); } static void mssql_database_log_flushes_chart(struct mssql_db_instance *mli, const char *db, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; - if (!mli->parent->st_db_log_flushes) { + + if (!mli->st_db_log_flushes) { snprintfz(id, RRD_ID_LENGTH_MAX, "db_%s_instance_%s_log_flushes", db, mli->parent->instanceID); - mli->parent->st_db_log_flushes = rrdset_create_localhost( + netdata_fix_chart_name(id); + mli->st_db_log_flushes = rrdset_create_localhost( "mssql", id, NULL, @@ -906,29 +939,31 @@ static void mssql_database_log_flushes_chart(struct mssql_db_instance *mli, cons update_every, RRDSET_TYPE_LINE); - rrdlabels_add( - mli->parent->st_db_log_flushes->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); - - rrdlabels_add(mli->parent->st_db_log_flushes->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_log_flushes->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_log_flushes->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); } if (!mli->rd_db_log_flushes) { - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_db_%s_instance_%s_log_flushes_bytes", db, mli->parent->instanceID); + mli->rd_db_log_flushes = rrddim_add(mli->st_db_log_flushes, "flushes", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + } - mli->rd_db_log_flushes = rrddim_add(mli->parent->st_db_log_flushes, id, db, 1, 1, RRD_ALGORITHM_INCREMENTAL); + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MDI_IDX_LOG_FLUSHES)) { + rrddim_set_by_pointer( + mli->st_db_log_flushes, + mli->rd_db_log_flushes, + (collected_number)mli->MSSQLDatabaseLogFlushes.current.Data); } - rrddim_set_by_pointer( - mli->parent->st_db_log_flushes, - mli->rd_db_log_flushes, - (collected_number)mli->MSSQLDatabaseLogFlushes.current.Data); + rrdset_done(mli->st_db_log_flushes); } static void mssql_database_log_flushed_chart(struct mssql_db_instance *mli, const char *db, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; - if (!mli->parent->st_db_log_flushed) { + + if (!mli->st_db_log_flushed) { snprintfz(id, RRD_ID_LENGTH_MAX, "db_%s_instance_%s_log_flushed", db, mli->parent->instanceID); - mli->parent->st_db_log_flushed = rrdset_create_localhost( + netdata_fix_chart_name(id); + mli->st_db_log_flushed = rrdset_create_localhost( "mssql", id, NULL, @@ -942,29 +977,31 @@ static void mssql_database_log_flushed_chart(struct mssql_db_instance *mli, cons update_every, RRDSET_TYPE_LINE); - rrdlabels_add( - mli->parent->st_db_log_flushed->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); - - rrdlabels_add(mli->parent->st_db_log_flushed->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_log_flushed->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_log_flushed->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); } if (!mli->rd_db_log_flushed) { - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_db_%s_instance_%s_log_flushed_bytes", db, mli->parent->instanceID); + mli->rd_db_log_flushed = rrddim_add(mli->st_db_log_flushed, "flushed", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + } - mli->rd_db_log_flushed = rrddim_add(mli->parent->st_db_log_flushed, id, db, 1, 1, RRD_ALGORITHM_INCREMENTAL); + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MDI_IDX_LOG_FLUSHED)) { + rrddim_set_by_pointer( + mli->st_db_log_flushed, + mli->rd_db_log_flushed, + (collected_number)mli->MSSQLDatabaseLogFlushed.current.Data); } - rrddim_set_by_pointer( - mli->parent->st_db_log_flushed, - mli->rd_db_log_flushed, - (collected_number)mli->MSSQLDatabaseLogFlushed.current.Data); + rrdset_done(mli->st_db_log_flushed); } static void mssql_transactions_chart(struct mssql_db_instance *mli, const char *db, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; - if (!mli->parent->st_db_transactions) { + + if (!mli->st_db_transactions) { snprintfz(id, RRD_ID_LENGTH_MAX, "db_%s_instance_%s_transactions", db, mli->parent->instanceID); - mli->parent->st_db_transactions = rrdset_create_localhost( + netdata_fix_chart_name(id); + mli->st_db_transactions = rrdset_create_localhost( "mssql", id, NULL, @@ -978,29 +1015,32 @@ static void mssql_transactions_chart(struct mssql_db_instance *mli, const char * update_every, RRDSET_TYPE_LINE); - rrdlabels_add( - mli->parent->st_db_transactions->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); - - rrdlabels_add(mli->parent->st_db_transactions->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_transactions->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_transactions->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); } if (!mli->rd_db_transactions) { - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_db_%s_instance_%s_transactions", db, mli->parent->instanceID); + mli->rd_db_transactions = + rrddim_add(mli->st_db_transactions, "transactions", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + } - mli->rd_db_transactions = rrddim_add(mli->parent->st_db_transactions, id, db, 1, 1, RRD_ALGORITHM_INCREMENTAL); + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MDI_IDX_TRANSACTIONS)) { + rrddim_set_by_pointer( + mli->st_db_transactions, + mli->rd_db_transactions, + (collected_number)mli->MSSQLDatabaseTransactions.current.Data); } - rrddim_set_by_pointer( - mli->parent->st_db_transactions, - mli->rd_db_transactions, - (collected_number)mli->MSSQLDatabaseTransactions.current.Data); + rrdset_done(mli->st_db_transactions); } static void mssql_write_transactions_chart(struct mssql_db_instance *mli, const char *db, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; - if (!mli->parent->st_db_write_transactions) { + + if (!mli->st_db_write_transactions) { snprintfz(id, RRD_ID_LENGTH_MAX, "db_%s_instance_%s_write_transactions", db, mli->parent->instanceID); - mli->parent->st_db_write_transactions = rrdset_create_localhost( + netdata_fix_chart_name(id); + mli->st_db_write_transactions = rrdset_create_localhost( "mssql", id, NULL, @@ -1015,32 +1055,32 @@ static void mssql_write_transactions_chart(struct mssql_db_instance *mli, const RRDSET_TYPE_LINE); rrdlabels_add( - mli->parent->st_db_write_transactions->rrdlabels, - "mssql_instance", - mli->parent->instanceID, - RRDLABEL_SRC_AUTO); - - rrdlabels_add(mli->parent->st_db_write_transactions->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); + mli->st_db_write_transactions->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_write_transactions->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); } if (!mli->rd_db_write_transactions) { - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_db_%s_instance_%s_write_transactions", db, mli->parent->instanceID); - mli->rd_db_write_transactions = - rrddim_add(mli->parent->st_db_write_transactions, id, db, 1, 1, RRD_ALGORITHM_INCREMENTAL); + rrddim_add(mli->st_db_write_transactions, "write", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + } + + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MDI_IDX_WRITE_TRANSACTIONS)) { + rrddim_set_by_pointer( + mli->st_db_write_transactions, + mli->rd_db_write_transactions, + (collected_number)mli->MSSQLDatabaseWriteTransactions.current.Data); } - rrddim_set_by_pointer( - mli->parent->st_db_write_transactions, - mli->rd_db_write_transactions, - (collected_number)mli->MSSQLDatabaseWriteTransactions.current.Data); + rrdset_done(mli->st_db_write_transactions); } static void mssql_active_transactions_chart(struct mssql_db_instance *mli, const char *db, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; - if (!mli->parent->st_db_active_transactions) { + + if (!mli->st_db_active_transactions) { snprintfz(id, RRD_ID_LENGTH_MAX, "db_%s_instance_%s_active_transactions", db, mli->parent->instanceID); - mli->parent->st_db_active_transactions = rrdset_create_localhost( + netdata_fix_chart_name(id); + mli->st_db_active_transactions = rrdset_create_localhost( "mssql", id, NULL, @@ -1055,32 +1095,32 @@ static void mssql_active_transactions_chart(struct mssql_db_instance *mli, const RRDSET_TYPE_LINE); rrdlabels_add( - mli->parent->st_db_active_transactions->rrdlabels, - "mssql_instance", - mli->parent->instanceID, - RRDLABEL_SRC_AUTO); - - rrdlabels_add(mli->parent->st_db_active_transactions->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); + mli->st_db_active_transactions->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_active_transactions->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); } if (!mli->rd_db_active_transactions) { - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_db_%s_instance_%s_active_transactions", db, mli->parent->instanceID); - mli->rd_db_active_transactions = - rrddim_add(mli->parent->st_db_active_transactions, id, db, 1, 1, RRD_ALGORITHM_ABSOLUTE); + rrddim_add(mli->st_db_active_transactions, "active", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } - rrddim_set_by_pointer( - mli->parent->st_db_active_transactions, - mli->rd_db_active_transactions, - (collected_number)mli->MSSQLDatabaseActiveTransactions.current.Data); + if (mli->updated & (1 << NETDATA_MSSQL_ENUM_MDI_IDX_ACTIVE_TRANSACTIONS)) { + rrddim_set_by_pointer( + mli->st_db_active_transactions, + mli->rd_db_active_transactions, + (collected_number)mli->MSSQLDatabaseActiveTransactions.current.Data); + } + + rrdset_done(mli->st_db_active_transactions); } static void mssql_data_file_size_chart(struct mssql_db_instance *mli, const char *db, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; - if (!mli->parent->st_db_data_file_size) { + + if (!mli->st_db_data_file_size) { snprintfz(id, RRD_ID_LENGTH_MAX, "db_%s_instance_%s_data_files_size", db, mli->parent->instanceID); - mli->parent->st_db_data_file_size = rrdset_create_localhost( + netdata_fix_chart_name(id); + mli->st_db_data_file_size = rrdset_create_localhost( "mssql", id, NULL, @@ -1095,21 +1135,20 @@ static void mssql_data_file_size_chart(struct mssql_db_instance *mli, const char RRDSET_TYPE_LINE); rrdlabels_add( - mli->parent->st_db_data_file_size->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); - - rrdlabels_add(mli->parent->st_db_data_file_size->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); + mli->st_db_data_file_size->rrdlabels, "mssql_instance", mli->parent->instanceID, RRDLABEL_SRC_AUTO); + rrdlabels_add(mli->st_db_data_file_size->rrdlabels, "database", db, RRDLABEL_SRC_AUTO); } if (!mli->rd_db_data_file_size) { - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_db_%s_instance_%s_data_files_size_bytes", db, mli->parent->instanceID); - - mli->rd_db_data_file_size = rrddim_add(mli->parent->st_db_data_file_size, id, db, 1, 1, RRD_ALGORITHM_ABSOLUTE); + mli->rd_db_data_file_size = rrddim_add(mli->st_db_data_file_size, "size", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } - rrddim_set_by_pointer( - mli->parent->st_db_data_file_size, - mli->rd_db_data_file_size, - (collected_number)mli->MSSQLDatabaseDataFileSize.current.Data * 1024); + // FIXME: If the value cannot be retrieved, remove the chart instead of displaying a 0 value. + collected_number data = + (mli->updated & (1 << NETDATA_MSSQL_ENUM_MDI_IDX_FILE_SIZE)) ? mli->MSSQLDatabaseDataFileSize.current.Data : 0; + rrddim_set_by_pointer(mli->st_db_data_file_size, mli->rd_db_data_file_size, data); + + rrdset_done(mli->st_db_data_file_size); } int dict_mssql_databases_charts_cb(const DICTIONARY_ITEM *item __maybe_unused, void *value, void *data __maybe_unused) { @@ -1119,7 +1158,9 @@ int dict_mssql_databases_charts_cb(const DICTIONARY_ITEM *item __maybe_unused, v int *update_every = data; void (*transaction_chart[])(struct mssql_db_instance *, const char *, int) = { - mssql_data_file_size_chart, + // FIXME: allegedly Netdata collects negative values (MSSQLDatabaseDataFileSize). + // something is wrong, perflibdump shows correct values. + // mssql_data_file_size_chart, mssql_transactions_chart, mssql_database_backup_restore_chart, mssql_database_log_flushed_chart, @@ -1155,43 +1196,54 @@ static void do_mssql_databases(PERF_DATA_BLOCK *pDataBlock, struct mssql_instanc if (!strcasecmp(windows_shared_buffer, "_Total")) continue; - netdata_fix_chart_name(windows_shared_buffer); struct mssql_db_instance *mdi = dictionary_set(p->databases, windows_shared_buffer, NULL, sizeof(*mdi)); if (!mdi) continue; + mdi->updated = 0; if (!mdi->parent) { mdi->parent = p; } - perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseDataFileSize); - perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseActiveTransactions); - perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseBackupRestoreOperations); - perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseLogFlushed); - perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseLogFlushes); - perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseTransactions); - perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseWriteTransactions); + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseDataFileSize)) { + LONGLONG value = (LONGLONG)mdi->MSSQLDatabaseDataFileSize.current.Data; + if (value > 0) + mdi->updated |= (1 << NETDATA_MSSQL_ENUM_MDI_IDX_FILE_SIZE); + } + + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseActiveTransactions)) + mdi->updated |= (1 << NETDATA_MSSQL_ENUM_MDI_IDX_ACTIVE_TRANSACTIONS); + + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseBackupRestoreOperations)) + mdi->updated |= (1 << NETDATA_MSSQL_ENUM_MDI_IDX_BACKUP_RESTORE_OP); + + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseLogFlushed)) + mdi->updated |= (1 << NETDATA_MSSQL_ENUM_MDI_IDX_LOG_FLUSHED); + + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseLogFlushes)) + mdi->updated |= (1 << NETDATA_MSSQL_ENUM_MDI_IDX_LOG_FLUSHES); + + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseTransactions)) + mdi->updated |= (1 << NETDATA_MSSQL_ENUM_MDI_IDX_TRANSACTIONS); + + if (perflibGetObjectCounter(pDataBlock, pObjectType, &mdi->MSSQLDatabaseWriteTransactions)) + mdi->updated |= (1 << NETDATA_MSSQL_ENUM_MDI_IDX_WRITE_TRANSACTIONS); } dictionary_sorted_walkthrough_read(p->databases, dict_mssql_databases_charts_cb, &update_every); - rrdset_done(p->st_db_data_file_size); - rrdset_done(p->st_db_active_transactions); - rrdset_done(p->st_db_backup_restore_operations); - rrdset_done(p->st_db_log_flushed); - rrdset_done(p->st_db_log_flushes); - rrdset_done(p->st_db_transactions); - rrdset_done(p->st_db_write_transactions); } static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instance *p, int update_every) { char id[RRD_ID_LENGTH_MAX + 1]; + PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, p->objectName[NETDATA_MSSQL_MEMORY]); if (!pObjectType) return; if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLConnectionMemoryBytes)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_connection_memory_bytes", p->instanceID); if (!p->st_conn_memory) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_connection_memory_bytes", p->instanceID); + netdata_fix_chart_name(id); p->st_conn_memory = rrdset_create_localhost( "mssql", id, @@ -1206,8 +1258,7 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_memmgr_connection_memory_bytes", p->instanceID); - p->rd_conn_memory = rrddim_add(p->st_conn_memory, id, "memory", 1, 1, RRD_ALGORITHM_ABSOLUTE); + p->rd_conn_memory = rrddim_add(p->st_conn_memory, "memory", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add(p->st_conn_memory->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -1220,8 +1271,9 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLExternalBenefitOfMemory)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_external_benefit_of_memory", p->instanceID); if (!p->st_ext_benefit_mem) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_external_benefit_of_memory", p->instanceID); + netdata_fix_chart_name(id); p->st_ext_benefit_mem = rrdset_create_localhost( "mssql", id, @@ -1236,8 +1288,7 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_memmgr_external_benefit_of_memory", p->instanceID); - p->rd_ext_benefit_mem = rrddim_add(p->st_ext_benefit_mem, id, "benefit", 1, 1, RRD_ALGORITHM_INCREMENTAL); + p->rd_ext_benefit_mem = rrddim_add(p->st_ext_benefit_mem, "benefit", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add(p->st_ext_benefit_mem->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -1250,8 +1301,9 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLPendingMemoryGrants)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_pending_memory_grants", p->instanceID); if (!p->st_pending_mem_grant) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_pending_memory_grants", p->instanceID); + netdata_fix_chart_name(id); p->st_pending_mem_grant = rrdset_create_localhost( "mssql", id, @@ -1259,15 +1311,15 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan "memory", "mssql.instance_memmgr_pending_memory_grants", "Process waiting for memory grant", - "process", + "processes", PLUGIN_WINDOWS_NAME, "PerflibMSSQL", PRIO_MSSQL_MEMMGR_PENDING_MEMORY_GRANTS, update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_memmgr_pending_memory_grants", p->instanceID); - p->rd_pending_mem_grant = rrddim_add(p->st_pending_mem_grant, id, "pending", 1, 1, RRD_ALGORITHM_ABSOLUTE); + p->rd_pending_mem_grant = + rrddim_add(p->st_pending_mem_grant, "pending", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add(p->st_pending_mem_grant->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -1276,12 +1328,14 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan p->st_pending_mem_grant, p->rd_pending_mem_grant, (collected_number)p->MSSQLPendingMemoryGrants.current.Data); + rrdset_done(p->st_pending_mem_grant); } if (perflibGetObjectCounter(pDataBlock, pObjectType, &p->MSSQLTotalServerMemory)) { - snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_server_memory", p->instanceID); if (!p->st_mem_tot_server) { + snprintfz(id, RRD_ID_LENGTH_MAX, "instance_%s_memmgr_server_memory", p->instanceID); + netdata_fix_chart_name(id); p->st_mem_tot_server = rrdset_create_localhost( "mssql", id, @@ -1296,8 +1350,7 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan update_every, RRDSET_TYPE_LINE); - snprintfz(id, RRD_ID_LENGTH_MAX, "mssql_instance_%s_memmgr_total_server_memory_bytes", p->instanceID); - p->rd_mem_tot_server = rrddim_add(p->st_mem_tot_server, id, "memory", 1, 1, RRD_ALGORITHM_ABSOLUTE); + p->rd_mem_tot_server = rrddim_add(p->st_mem_tot_server, "memory", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrdlabels_add(p->st_mem_tot_server->rrdlabels, "mssql_instance", p->instanceID, RRDLABEL_SRC_AUTO); } @@ -1306,6 +1359,7 @@ static void do_mssql_memory_mgr(PERF_DATA_BLOCK *pDataBlock, struct mssql_instan p->st_mem_tot_server, p->rd_mem_tot_server, (collected_number)(p->MSSQLTotalServerMemory.current.Data * 1024)); + rrdset_done(p->st_mem_tot_server); } }