ad_charts.cc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "ad_charts.h"
  3. void ml_update_dimensions_chart(ml_host_t *host, const ml_machine_learning_stats_t &mls) {
  4. /*
  5. * Machine learning status
  6. */
  7. if (Cfg.enable_statistics_charts) {
  8. if (!host->machine_learning_status_rs) {
  9. char id_buf[1024];
  10. char name_buf[1024];
  11. snprintfz(id_buf, 1024, "machine_learning_status_on_%s", localhost->machine_guid);
  12. snprintfz(name_buf, 1024, "machine_learning_status_on_%s", rrdhost_hostname(localhost));
  13. host->machine_learning_status_rs = rrdset_create(
  14. host->rh,
  15. "netdata", // type
  16. id_buf,
  17. name_buf, // name
  18. NETDATA_ML_CHART_FAMILY, // family
  19. "netdata.machine_learning_status", // ctx
  20. "Machine learning status", // title
  21. "dimensions", // units
  22. NETDATA_ML_PLUGIN, // plugin
  23. NETDATA_ML_MODULE_TRAINING, // module
  24. NETDATA_ML_CHART_PRIO_MACHINE_LEARNING_STATUS, // priority
  25. localhost->rrd_update_every, // update_every
  26. RRDSET_TYPE_LINE // chart_type
  27. );
  28. rrdset_flag_set(host->machine_learning_status_rs , RRDSET_FLAG_ANOMALY_DETECTION);
  29. host->machine_learning_status_enabled_rd =
  30. rrddim_add(host->machine_learning_status_rs, "enabled", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  31. host->machine_learning_status_disabled_sp_rd =
  32. rrddim_add(host->machine_learning_status_rs, "disabled-sp", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  33. }
  34. rrddim_set_by_pointer(host->machine_learning_status_rs,
  35. host->machine_learning_status_enabled_rd, mls.num_machine_learning_status_enabled);
  36. rrddim_set_by_pointer(host->machine_learning_status_rs,
  37. host->machine_learning_status_disabled_sp_rd, mls.num_machine_learning_status_disabled_sp);
  38. rrdset_done(host->machine_learning_status_rs);
  39. }
  40. /*
  41. * Metric type
  42. */
  43. if (Cfg.enable_statistics_charts) {
  44. if (!host->metric_type_rs) {
  45. char id_buf[1024];
  46. char name_buf[1024];
  47. snprintfz(id_buf, 1024, "metric_types_on_%s", localhost->machine_guid);
  48. snprintfz(name_buf, 1024, "metric_types_on_%s", rrdhost_hostname(localhost));
  49. host->metric_type_rs = rrdset_create(
  50. host->rh,
  51. "netdata", // type
  52. id_buf, // id
  53. name_buf, // name
  54. NETDATA_ML_CHART_FAMILY, // family
  55. "netdata.metric_types", // ctx
  56. "Dimensions by metric type", // title
  57. "dimensions", // units
  58. NETDATA_ML_PLUGIN, // plugin
  59. NETDATA_ML_MODULE_TRAINING, // module
  60. NETDATA_ML_CHART_PRIO_METRIC_TYPES, // priority
  61. localhost->rrd_update_every, // update_every
  62. RRDSET_TYPE_LINE // chart_type
  63. );
  64. rrdset_flag_set(host->metric_type_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  65. host->metric_type_constant_rd =
  66. rrddim_add(host->metric_type_rs, "constant", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  67. host->metric_type_variable_rd =
  68. rrddim_add(host->metric_type_rs, "variable", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  69. }
  70. rrddim_set_by_pointer(host->metric_type_rs,
  71. host->metric_type_constant_rd, mls.num_metric_type_constant);
  72. rrddim_set_by_pointer(host->metric_type_rs,
  73. host->metric_type_variable_rd, mls.num_metric_type_variable);
  74. rrdset_done(host->metric_type_rs);
  75. }
  76. /*
  77. * Training status
  78. */
  79. if (Cfg.enable_statistics_charts) {
  80. if (!host->training_status_rs) {
  81. char id_buf[1024];
  82. char name_buf[1024];
  83. snprintfz(id_buf, 1024, "training_status_on_%s", localhost->machine_guid);
  84. snprintfz(name_buf, 1024, "training_status_on_%s", rrdhost_hostname(localhost));
  85. host->training_status_rs = rrdset_create(
  86. host->rh,
  87. "netdata", // type
  88. id_buf, // id
  89. name_buf, // name
  90. NETDATA_ML_CHART_FAMILY, // family
  91. "netdata.training_status", // ctx
  92. "Training status of dimensions", // title
  93. "dimensions", // units
  94. NETDATA_ML_PLUGIN, // plugin
  95. NETDATA_ML_MODULE_TRAINING, // module
  96. NETDATA_ML_CHART_PRIO_TRAINING_STATUS, // priority
  97. localhost->rrd_update_every, // update_every
  98. RRDSET_TYPE_LINE // chart_type
  99. );
  100. rrdset_flag_set(host->training_status_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  101. host->training_status_untrained_rd =
  102. rrddim_add(host->training_status_rs, "untrained", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  103. host->training_status_pending_without_model_rd =
  104. rrddim_add(host->training_status_rs, "pending-without-model", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  105. host->training_status_trained_rd =
  106. rrddim_add(host->training_status_rs, "trained", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  107. host->training_status_pending_with_model_rd =
  108. rrddim_add(host->training_status_rs, "pending-with-model", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  109. host->training_status_silenced_rd =
  110. rrddim_add(host->training_status_rs, "silenced", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  111. }
  112. rrddim_set_by_pointer(host->training_status_rs,
  113. host->training_status_untrained_rd, mls.num_training_status_untrained);
  114. rrddim_set_by_pointer(host->training_status_rs,
  115. host->training_status_pending_without_model_rd, mls.num_training_status_pending_without_model);
  116. rrddim_set_by_pointer(host->training_status_rs,
  117. host->training_status_trained_rd, mls.num_training_status_trained);
  118. rrddim_set_by_pointer(host->training_status_rs,
  119. host->training_status_pending_with_model_rd, mls.num_training_status_pending_with_model);
  120. rrddim_set_by_pointer(host->training_status_rs,
  121. host->training_status_silenced_rd, mls.num_training_status_silenced);
  122. rrdset_done(host->training_status_rs);
  123. }
  124. /*
  125. * Prediction status
  126. */
  127. {
  128. if (!host->dimensions_rs) {
  129. char id_buf[1024];
  130. char name_buf[1024];
  131. snprintfz(id_buf, 1024, "dimensions_on_%s", localhost->machine_guid);
  132. snprintfz(name_buf, 1024, "dimensions_on_%s", rrdhost_hostname(localhost));
  133. host->dimensions_rs = rrdset_create(
  134. host->rh,
  135. "anomaly_detection", // type
  136. id_buf, // id
  137. name_buf, // name
  138. "dimensions", // family
  139. "anomaly_detection.dimensions", // ctx
  140. "Anomaly detection dimensions", // title
  141. "dimensions", // units
  142. NETDATA_ML_PLUGIN, // plugin
  143. NETDATA_ML_MODULE_TRAINING, // module
  144. ML_CHART_PRIO_DIMENSIONS, // priority
  145. localhost->rrd_update_every, // update_every
  146. RRDSET_TYPE_LINE // chart_type
  147. );
  148. rrdset_flag_set(host->dimensions_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  149. host->dimensions_anomalous_rd =
  150. rrddim_add(host->dimensions_rs, "anomalous", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  151. host->dimensions_normal_rd =
  152. rrddim_add(host->dimensions_rs, "normal", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  153. }
  154. rrddim_set_by_pointer(host->dimensions_rs,
  155. host->dimensions_anomalous_rd, mls.num_anomalous_dimensions);
  156. rrddim_set_by_pointer(host->dimensions_rs,
  157. host->dimensions_normal_rd, mls.num_normal_dimensions);
  158. rrdset_done(host->dimensions_rs);
  159. }
  160. // ML running
  161. {
  162. if (!host->ml_running_rs) {
  163. char id_buf[1024];
  164. char name_buf[1024];
  165. snprintfz(id_buf, 1024, "ml_running_on_%s", localhost->machine_guid);
  166. snprintfz(name_buf, 1024, "ml_running_on_%s", rrdhost_hostname(localhost));
  167. host->ml_running_rs = rrdset_create(
  168. host->rh,
  169. "anomaly_detection", // type
  170. id_buf, // id
  171. name_buf, // name
  172. "anomaly_detection", // family
  173. "anomaly_detection.ml_running", // ctx
  174. "ML running", // title
  175. "boolean", // units
  176. NETDATA_ML_PLUGIN, // plugin
  177. NETDATA_ML_MODULE_DETECTION, // module
  178. NETDATA_ML_CHART_RUNNING, // priority
  179. localhost->rrd_update_every, // update_every
  180. RRDSET_TYPE_LINE // chart_type
  181. );
  182. rrdset_flag_set(host->ml_running_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  183. host->ml_running_rd =
  184. rrddim_add(host->ml_running_rs, "ml_running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  185. }
  186. rrddim_set_by_pointer(host->ml_running_rs,
  187. host->ml_running_rd, host->ml_running);
  188. rrdset_done(host->ml_running_rs);
  189. }
  190. }
  191. void ml_update_host_and_detection_rate_charts(ml_host_t *host, collected_number AnomalyRate) {
  192. /*
  193. * Host anomaly rate
  194. */
  195. {
  196. if (!host->anomaly_rate_rs) {
  197. char id_buf[1024];
  198. char name_buf[1024];
  199. snprintfz(id_buf, 1024, "anomaly_rate_on_%s", localhost->machine_guid);
  200. snprintfz(name_buf, 1024, "anomaly_rate_on_%s", rrdhost_hostname(localhost));
  201. host->anomaly_rate_rs = rrdset_create(
  202. host->rh,
  203. "anomaly_detection", // type
  204. id_buf, // id
  205. name_buf, // name
  206. "anomaly_rate", // family
  207. "anomaly_detection.anomaly_rate", // ctx
  208. "Percentage of anomalous dimensions", // title
  209. "percentage", // units
  210. NETDATA_ML_PLUGIN, // plugin
  211. NETDATA_ML_MODULE_DETECTION, // module
  212. ML_CHART_PRIO_ANOMALY_RATE, // priority
  213. localhost->rrd_update_every, // update_every
  214. RRDSET_TYPE_LINE // chart_type
  215. );
  216. rrdset_flag_set(host->anomaly_rate_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  217. host->anomaly_rate_rd =
  218. rrddim_add(host->anomaly_rate_rs, "anomaly_rate", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
  219. }
  220. rrddim_set_by_pointer(host->anomaly_rate_rs, host->anomaly_rate_rd, AnomalyRate);
  221. rrdset_done(host->anomaly_rate_rs);
  222. }
  223. /*
  224. * Type anomaly rate
  225. */
  226. {
  227. if (!host->type_anomaly_rate_rs) {
  228. char id_buf[1024];
  229. char name_buf[1024];
  230. snprintfz(id_buf, 1024, "type_anomaly_rate_on_%s", localhost->machine_guid);
  231. snprintfz(name_buf, 1024, "type_anomaly_rate_on_%s", rrdhost_hostname(localhost));
  232. host->type_anomaly_rate_rs = rrdset_create(
  233. host->rh,
  234. "anomaly_detection", // type
  235. id_buf, // id
  236. name_buf, // name
  237. "anomaly_rate", // family
  238. "anomaly_detection.type_anomaly_rate", // ctx
  239. "Percentage of anomalous dimensions by type", // title
  240. "percentage", // units
  241. NETDATA_ML_PLUGIN, // plugin
  242. NETDATA_ML_MODULE_DETECTION, // module
  243. ML_CHART_PRIO_TYPE_ANOMALY_RATE, // priority
  244. localhost->rrd_update_every, // update_every
  245. RRDSET_TYPE_STACKED // chart_type
  246. );
  247. rrdset_flag_set(host->type_anomaly_rate_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  248. }
  249. for (auto &entry : host->type_anomaly_rate) {
  250. ml_type_anomaly_rate_t &type_anomaly_rate = entry.second;
  251. if (!type_anomaly_rate.rd)
  252. type_anomaly_rate.rd = rrddim_add(host->type_anomaly_rate_rs, string2str(entry.first), NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
  253. double ar = 0.0;
  254. size_t n = type_anomaly_rate.anomalous_dimensions + type_anomaly_rate.normal_dimensions;
  255. if (n)
  256. ar = static_cast<double>(type_anomaly_rate.anomalous_dimensions) / n;
  257. rrddim_set_by_pointer(host->type_anomaly_rate_rs, type_anomaly_rate.rd, ar * 10000.0);
  258. type_anomaly_rate.anomalous_dimensions = 0;
  259. type_anomaly_rate.normal_dimensions = 0;
  260. }
  261. rrdset_done(host->type_anomaly_rate_rs);
  262. }
  263. /*
  264. * Detector Events
  265. */
  266. {
  267. if (!host->detector_events_rs) {
  268. char id_buf[1024];
  269. char name_buf[1024];
  270. snprintfz(id_buf, 1024, "anomaly_detection_on_%s", localhost->machine_guid);
  271. snprintfz(name_buf, 1024, "anomaly_detection_on_%s", rrdhost_hostname(localhost));
  272. host->detector_events_rs = rrdset_create(
  273. host->rh,
  274. "anomaly_detection", // type
  275. id_buf, // id
  276. name_buf, // name
  277. "anomaly_detection", // family
  278. "anomaly_detection.detector_events", // ctx
  279. "Anomaly detection events", // title
  280. "status", // units
  281. NETDATA_ML_PLUGIN, // plugin
  282. NETDATA_ML_MODULE_DETECTION, // module
  283. ML_CHART_PRIO_DETECTOR_EVENTS, // priority
  284. localhost->rrd_update_every, // update_every
  285. RRDSET_TYPE_LINE // chart_type
  286. );
  287. rrdset_flag_set(host->detector_events_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  288. host->detector_events_above_threshold_rd =
  289. rrddim_add(host->detector_events_rs, "above_threshold", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  290. host->detector_events_new_anomaly_event_rd =
  291. rrddim_add(host->detector_events_rs, "new_anomaly_event", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  292. }
  293. /*
  294. * Compute the values of the dimensions based on the host rate chart
  295. */
  296. if (host->ml_running) {
  297. ONEWAYALLOC *OWA = onewayalloc_create(0);
  298. time_t Now = now_realtime_sec();
  299. time_t Before = Now - host->rh->rrd_update_every;
  300. time_t After = Before - Cfg.anomaly_detection_query_duration;
  301. RRDR_OPTIONS Options = static_cast<RRDR_OPTIONS>(0x00000000);
  302. RRDR *R = rrd2rrdr_legacy(
  303. OWA,
  304. host->anomaly_rate_rs,
  305. 1 /* points wanted */,
  306. After,
  307. Before,
  308. Cfg.anomaly_detection_grouping_method,
  309. 0 /* resampling time */,
  310. Options, "anomaly_rate",
  311. NULL /* group options */,
  312. 0, /* timeout */
  313. 0, /* tier */
  314. QUERY_SOURCE_ML,
  315. STORAGE_PRIORITY_SYNCHRONOUS
  316. );
  317. if (R) {
  318. if (R->d == 1 && R->n == 1 && R->rows == 1) {
  319. static thread_local bool prev_above_threshold = false;
  320. bool above_threshold = R->v[0] >= Cfg.host_anomaly_rate_threshold;
  321. bool new_anomaly_event = above_threshold && !prev_above_threshold;
  322. prev_above_threshold = above_threshold;
  323. rrddim_set_by_pointer(host->detector_events_rs,
  324. host->detector_events_above_threshold_rd, above_threshold);
  325. rrddim_set_by_pointer(host->detector_events_rs,
  326. host->detector_events_new_anomaly_event_rd, new_anomaly_event);
  327. rrdset_done(host->detector_events_rs);
  328. }
  329. rrdr_free(OWA, R);
  330. }
  331. onewayalloc_destroy(OWA);
  332. } else {
  333. rrddim_set_by_pointer(host->detector_events_rs,
  334. host->detector_events_above_threshold_rd, 0);
  335. rrddim_set_by_pointer(host->detector_events_rs,
  336. host->detector_events_new_anomaly_event_rd, 0);
  337. rrdset_done(host->detector_events_rs);
  338. }
  339. }
  340. }
  341. void ml_update_training_statistics_chart(ml_training_thread_t *training_thread, const ml_training_stats_t &ts) {
  342. /*
  343. * queue stats
  344. */
  345. {
  346. if (!training_thread->queue_stats_rs) {
  347. char id_buf[1024];
  348. char name_buf[1024];
  349. snprintfz(id_buf, 1024, "training_queue_%zu_stats", training_thread->id);
  350. snprintfz(name_buf, 1024, "training_queue_%zu_stats", training_thread->id);
  351. training_thread->queue_stats_rs = rrdset_create(
  352. localhost,
  353. "netdata", // type
  354. id_buf, // id
  355. name_buf, // name
  356. NETDATA_ML_CHART_FAMILY, // family
  357. "netdata.queue_stats", // ctx
  358. "Training queue stats", // title
  359. "items", // units
  360. NETDATA_ML_PLUGIN, // plugin
  361. NETDATA_ML_MODULE_TRAINING, // module
  362. NETDATA_ML_CHART_PRIO_QUEUE_STATS, // priority
  363. localhost->rrd_update_every, // update_every
  364. RRDSET_TYPE_LINE// chart_type
  365. );
  366. rrdset_flag_set(training_thread->queue_stats_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  367. training_thread->queue_stats_queue_size_rd =
  368. rrddim_add(training_thread->queue_stats_rs, "queue_size", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  369. training_thread->queue_stats_popped_items_rd =
  370. rrddim_add(training_thread->queue_stats_rs, "popped_items", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  371. }
  372. rrddim_set_by_pointer(training_thread->queue_stats_rs,
  373. training_thread->queue_stats_queue_size_rd, ts.queue_size);
  374. rrddim_set_by_pointer(training_thread->queue_stats_rs,
  375. training_thread->queue_stats_popped_items_rd, ts.num_popped_items);
  376. rrdset_done(training_thread->queue_stats_rs);
  377. }
  378. /*
  379. * training stats
  380. */
  381. {
  382. if (!training_thread->training_time_stats_rs) {
  383. char id_buf[1024];
  384. char name_buf[1024];
  385. snprintfz(id_buf, 1024, "training_queue_%zu_time_stats", training_thread->id);
  386. snprintfz(name_buf, 1024, "training_queue_%zu_time_stats", training_thread->id);
  387. training_thread->training_time_stats_rs = rrdset_create(
  388. localhost,
  389. "netdata", // type
  390. id_buf, // id
  391. name_buf, // name
  392. NETDATA_ML_CHART_FAMILY, // family
  393. "netdata.training_time_stats", // ctx
  394. "Training time stats", // title
  395. "milliseconds", // units
  396. NETDATA_ML_PLUGIN, // plugin
  397. NETDATA_ML_MODULE_TRAINING, // module
  398. NETDATA_ML_CHART_PRIO_TRAINING_TIME_STATS, // priority
  399. localhost->rrd_update_every, // update_every
  400. RRDSET_TYPE_LINE// chart_type
  401. );
  402. rrdset_flag_set(training_thread->training_time_stats_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  403. training_thread->training_time_stats_allotted_rd =
  404. rrddim_add(training_thread->training_time_stats_rs, "allotted", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
  405. training_thread->training_time_stats_consumed_rd =
  406. rrddim_add(training_thread->training_time_stats_rs, "consumed", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
  407. training_thread->training_time_stats_remaining_rd =
  408. rrddim_add(training_thread->training_time_stats_rs, "remaining", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
  409. }
  410. rrddim_set_by_pointer(training_thread->training_time_stats_rs,
  411. training_thread->training_time_stats_allotted_rd, ts.allotted_ut);
  412. rrddim_set_by_pointer(training_thread->training_time_stats_rs,
  413. training_thread->training_time_stats_consumed_rd, ts.consumed_ut);
  414. rrddim_set_by_pointer(training_thread->training_time_stats_rs,
  415. training_thread->training_time_stats_remaining_rd, ts.remaining_ut);
  416. rrdset_done(training_thread->training_time_stats_rs);
  417. }
  418. /*
  419. * training result stats
  420. */
  421. {
  422. if (!training_thread->training_results_rs) {
  423. char id_buf[1024];
  424. char name_buf[1024];
  425. snprintfz(id_buf, 1024, "training_queue_%zu_results", training_thread->id);
  426. snprintfz(name_buf, 1024, "training_queue_%zu_results", training_thread->id);
  427. training_thread->training_results_rs = rrdset_create(
  428. localhost,
  429. "netdata", // type
  430. id_buf, // id
  431. name_buf, // name
  432. NETDATA_ML_CHART_FAMILY, // family
  433. "netdata.training_results", // ctx
  434. "Training results", // title
  435. "events", // units
  436. NETDATA_ML_PLUGIN, // plugin
  437. NETDATA_ML_MODULE_TRAINING, // module
  438. NETDATA_ML_CHART_PRIO_TRAINING_RESULTS, // priority
  439. localhost->rrd_update_every, // update_every
  440. RRDSET_TYPE_LINE// chart_type
  441. );
  442. rrdset_flag_set(training_thread->training_results_rs, RRDSET_FLAG_ANOMALY_DETECTION);
  443. training_thread->training_results_ok_rd =
  444. rrddim_add(training_thread->training_results_rs, "ok", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  445. training_thread->training_results_invalid_query_time_range_rd =
  446. rrddim_add(training_thread->training_results_rs, "invalid-queries", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  447. training_thread->training_results_not_enough_collected_values_rd =
  448. rrddim_add(training_thread->training_results_rs, "not-enough-values", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  449. training_thread->training_results_null_acquired_dimension_rd =
  450. rrddim_add(training_thread->training_results_rs, "null-acquired-dimensions", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  451. training_thread->training_results_chart_under_replication_rd =
  452. rrddim_add(training_thread->training_results_rs, "chart-under-replication", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  453. }
  454. rrddim_set_by_pointer(training_thread->training_results_rs,
  455. training_thread->training_results_ok_rd, ts.training_result_ok);
  456. rrddim_set_by_pointer(training_thread->training_results_rs,
  457. training_thread->training_results_invalid_query_time_range_rd, ts.training_result_invalid_query_time_range);
  458. rrddim_set_by_pointer(training_thread->training_results_rs,
  459. training_thread->training_results_not_enough_collected_values_rd, ts.training_result_not_enough_collected_values);
  460. rrddim_set_by_pointer(training_thread->training_results_rs,
  461. training_thread->training_results_null_acquired_dimension_rd, ts.training_result_null_acquired_dimension);
  462. rrddim_set_by_pointer(training_thread->training_results_rs,
  463. training_thread->training_results_chart_under_replication_rd, ts.training_result_chart_under_replication);
  464. rrdset_done(training_thread->training_results_rs);
  465. }
  466. }
  467. void ml_update_global_statistics_charts(uint64_t models_consulted) {
  468. if (Cfg.enable_statistics_charts) {
  469. static RRDSET *st = NULL;
  470. static RRDDIM *rd = NULL;
  471. if (unlikely(!st)) {
  472. st = rrdset_create_localhost(
  473. "netdata" // type
  474. , "ml_models_consulted" // id
  475. , NULL // name
  476. , NETDATA_ML_CHART_FAMILY // family
  477. , NULL // context
  478. , "KMeans models used for prediction" // title
  479. , "models" // units
  480. , NETDATA_ML_PLUGIN // plugin
  481. , NETDATA_ML_MODULE_DETECTION // module
  482. , NETDATA_ML_CHART_PRIO_MACHINE_LEARNING_STATUS // priority
  483. , localhost->rrd_update_every // update_every
  484. , RRDSET_TYPE_AREA // chart_type
  485. );
  486. rd = rrddim_add(st, "num_models_consulted", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  487. }
  488. rrddim_set_by_pointer(st, rd, (collected_number) models_consulted);
  489. rrdset_done(st);
  490. }
  491. }