proc_mdstat.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "plugin_proc.h"
  3. #define PLUGIN_PROC_MODULE_MDSTAT_NAME "/proc/mdstat"
  4. struct raid {
  5. int redundant;
  6. char *name;
  7. uint32_t hash;
  8. char *level;
  9. RRDDIM *rd_health;
  10. unsigned long long failed_disks;
  11. RRDSET *st_disks;
  12. RRDDIM *rd_down;
  13. RRDDIM *rd_inuse;
  14. unsigned long long total_disks;
  15. unsigned long long inuse_disks;
  16. RRDSET *st_operation;
  17. RRDDIM *rd_check;
  18. RRDDIM *rd_resync;
  19. RRDDIM *rd_recovery;
  20. RRDDIM *rd_reshape;
  21. unsigned long long check;
  22. unsigned long long resync;
  23. unsigned long long recovery;
  24. unsigned long long reshape;
  25. RRDSET *st_finish;
  26. RRDDIM *rd_finish_in;
  27. unsigned long long finish_in;
  28. RRDSET *st_speed;
  29. RRDDIM *rd_speed;
  30. unsigned long long speed;
  31. char *mismatch_cnt_filename;
  32. RRDSET *st_mismatch_cnt;
  33. RRDDIM *rd_mismatch_cnt;
  34. unsigned long long mismatch_cnt;
  35. RRDSET *st_nonredundant;
  36. RRDDIM *rd_nonredundant;
  37. };
  38. struct old_raid {
  39. int redundant;
  40. char *name;
  41. uint32_t hash;
  42. int found;
  43. };
  44. static inline char *remove_trailing_chars(char *s, char c)
  45. {
  46. while (*s) {
  47. if (unlikely(*s == c)) {
  48. *s = '\0';
  49. }
  50. s++;
  51. }
  52. return s;
  53. }
  54. static inline void make_chart_obsolete(char *name, const char *id_modifier)
  55. {
  56. char id[50 + 1];
  57. RRDSET *st = NULL;
  58. if (likely(name && id_modifier)) {
  59. snprintfz(id, 50, "mdstat.%s_%s", name, id_modifier);
  60. st = rrdset_find_active_byname_localhost(id);
  61. if (likely(st))
  62. rrdset_is_obsolete(st);
  63. }
  64. }
  65. static void add_labels_to_mdstat(struct raid *raid, RRDSET *st) {
  66. rrdlabels_add(st->rrdlabels, "device", raid->name, RRDLABEL_SRC_AUTO);
  67. rrdlabels_add(st->rrdlabels, "raid_level", raid->level, RRDLABEL_SRC_AUTO);
  68. }
  69. int do_proc_mdstat(int update_every, usec_t dt)
  70. {
  71. (void)dt;
  72. static procfile *ff = NULL;
  73. static int do_health = -1, do_nonredundant = -1, do_disks = -1, do_operations = -1, do_mismatch = -1,
  74. do_mismatch_config = -1;
  75. static int make_charts_obsolete = -1;
  76. static char *mdstat_filename = NULL, *mismatch_cnt_filename = NULL;
  77. static struct raid *raids = NULL;
  78. static size_t raids_allocated = 0;
  79. size_t raids_num = 0, raid_idx = 0, redundant_num = 0;
  80. static struct old_raid *old_raids = NULL;
  81. static size_t old_raids_allocated = 0;
  82. size_t old_raid_idx = 0;
  83. if (unlikely(do_health == -1)) {
  84. do_health =
  85. config_get_boolean("plugin:proc:/proc/mdstat", "faulty devices", CONFIG_BOOLEAN_YES);
  86. do_nonredundant =
  87. config_get_boolean("plugin:proc:/proc/mdstat", "nonredundant arrays availability", CONFIG_BOOLEAN_YES);
  88. do_mismatch_config =
  89. config_get_boolean_ondemand("plugin:proc:/proc/mdstat", "mismatch count", CONFIG_BOOLEAN_AUTO);
  90. do_disks =
  91. config_get_boolean("plugin:proc:/proc/mdstat", "disk stats", CONFIG_BOOLEAN_YES);
  92. do_operations =
  93. config_get_boolean("plugin:proc:/proc/mdstat", "operation status", CONFIG_BOOLEAN_YES);
  94. make_charts_obsolete =
  95. config_get_boolean("plugin:proc:/proc/mdstat", "make charts obsolete", CONFIG_BOOLEAN_YES);
  96. char filename[FILENAME_MAX + 1];
  97. snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/mdstat");
  98. mdstat_filename = config_get("plugin:proc:/proc/mdstat", "filename to monitor", filename);
  99. snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/block/%s/md/mismatch_cnt");
  100. mismatch_cnt_filename = config_get("plugin:proc:/proc/mdstat", "mismatch_cnt filename to monitor", filename);
  101. }
  102. if (unlikely(!ff)) {
  103. ff = procfile_open(mdstat_filename, " \t:", PROCFILE_FLAG_DEFAULT);
  104. if (unlikely(!ff))
  105. return 1;
  106. }
  107. ff = procfile_readall(ff);
  108. if (unlikely(!ff))
  109. return 0; // we return 0, so that we will retry opening it next time
  110. size_t lines = procfile_lines(ff);
  111. size_t words = 0;
  112. if (unlikely(lines < 2)) {
  113. collector_error("Cannot read /proc/mdstat. Expected 2 or more lines, read %zu.", lines);
  114. return 1;
  115. }
  116. // find how many raids are there
  117. size_t l;
  118. raids_num = 0;
  119. for (l = 1; l < lines - 2; l++) {
  120. if (unlikely(procfile_lineword(ff, l, 1)[0] == 'a')) // check if the raid is active
  121. raids_num++;
  122. }
  123. if (unlikely(!raids_num && !old_raids_allocated))
  124. return 0; // we return 0, so that we will retry searching for raids next time
  125. // allocate the memory we need;
  126. if (unlikely(raids_num != raids_allocated)) {
  127. for (raid_idx = 0; raid_idx < raids_allocated; raid_idx++) {
  128. struct raid *raid = &raids[raid_idx];
  129. freez(raid->name);
  130. freez(raid->level);
  131. freez(raid->mismatch_cnt_filename);
  132. }
  133. if (raids_num) {
  134. raids = (struct raid *)reallocz(raids, raids_num * sizeof(struct raid));
  135. memset(raids, 0, raids_num * sizeof(struct raid));
  136. } else {
  137. freez(raids);
  138. raids = NULL;
  139. }
  140. raids_allocated = raids_num;
  141. }
  142. // loop through all lines except the first and the last ones
  143. for (l = 1, raid_idx = 0; l < (lines - 2) && raid_idx < raids_num; l++) {
  144. struct raid *raid = &raids[raid_idx];
  145. raid->redundant = 0;
  146. words = procfile_linewords(ff, l);
  147. if (unlikely(words < 3))
  148. continue;
  149. if (unlikely(procfile_lineword(ff, l, 1)[0] != 'a'))
  150. continue;
  151. if (unlikely(!raid->name)) {
  152. raid->name = strdupz(procfile_lineword(ff, l, 0));
  153. raid->hash = simple_hash(raid->name);
  154. raid->level = strdupz(procfile_lineword(ff, l, 2));
  155. } else if (unlikely(strcmp(raid->name, procfile_lineword(ff, l, 0)))) {
  156. freez(raid->name);
  157. freez(raid->mismatch_cnt_filename);
  158. freez(raid->level);
  159. memset(raid, 0, sizeof(struct raid));
  160. raid->name = strdupz(procfile_lineword(ff, l, 0));
  161. raid->hash = simple_hash(raid->name);
  162. raid->level = strdupz(procfile_lineword(ff, l, 2));
  163. }
  164. if (unlikely(!raid->name || !raid->name[0]))
  165. continue;
  166. raid_idx++;
  167. // check if raid has disk status
  168. l++;
  169. words = procfile_linewords(ff, l);
  170. if (words < 2 || procfile_lineword(ff, l, words - 1)[0] != '[')
  171. continue;
  172. // split inuse and total number of disks
  173. if (likely(do_health || do_disks)) {
  174. char *s = NULL, *str_total = NULL, *str_inuse = NULL;
  175. s = procfile_lineword(ff, l, words - 2);
  176. if (unlikely(s[0] != '[')) {
  177. collector_error("Cannot read /proc/mdstat raid health status. Unexpected format: missing opening bracket.");
  178. continue;
  179. }
  180. str_total = ++s;
  181. while (*s) {
  182. if (unlikely(*s == '/')) {
  183. *s = '\0';
  184. str_inuse = s + 1;
  185. } else if (unlikely(*s == ']')) {
  186. *s = '\0';
  187. break;
  188. }
  189. s++;
  190. }
  191. if (unlikely(str_total[0] == '\0' || !str_inuse || str_inuse[0] == '\0')) {
  192. collector_error("Cannot read /proc/mdstat raid health status. Unexpected format.");
  193. continue;
  194. }
  195. raid->inuse_disks = str2ull(str_inuse);
  196. raid->total_disks = str2ull(str_total);
  197. raid->failed_disks = raid->total_disks - raid->inuse_disks;
  198. }
  199. raid->redundant = 1;
  200. redundant_num++;
  201. l++;
  202. // check if any operation is performed on the raid
  203. if (likely(do_operations)) {
  204. char *s = NULL;
  205. raid->check = 0;
  206. raid->resync = 0;
  207. raid->recovery = 0;
  208. raid->reshape = 0;
  209. raid->finish_in = 0;
  210. raid->speed = 0;
  211. words = procfile_linewords(ff, l);
  212. if (likely(words < 2))
  213. continue;
  214. if (unlikely(procfile_lineword(ff, l, 0)[0] != '['))
  215. continue;
  216. if (unlikely(words < 7)) {
  217. collector_error("Cannot read /proc/mdstat line. Expected 7 params, read %zu.", words);
  218. continue;
  219. }
  220. char *word;
  221. word = procfile_lineword(ff, l, 3);
  222. remove_trailing_chars(word, '%');
  223. unsigned long long percentage = (unsigned long long)(str2ndd(word, NULL) * 100);
  224. // possible operations: check, resync, recovery, reshape
  225. // 4-th character is unique for each operation so it is checked
  226. switch (procfile_lineword(ff, l, 1)[3]) {
  227. case 'c': // check
  228. raid->check = percentage;
  229. break;
  230. case 'y': // resync
  231. raid->resync = percentage;
  232. break;
  233. case 'o': // recovery
  234. raid->recovery = percentage;
  235. break;
  236. case 'h': // reshape
  237. raid->reshape = percentage;
  238. break;
  239. }
  240. word = procfile_lineword(ff, l, 5);
  241. s = remove_trailing_chars(word, 'm'); // remove trailing "min"
  242. word += 7; // skip leading "finish="
  243. if (likely(s > word))
  244. raid->finish_in = (unsigned long long)(str2ndd(word, NULL) * 60);
  245. word = procfile_lineword(ff, l, 6);
  246. s = remove_trailing_chars(word, 'K'); // remove trailing "K/sec"
  247. word += 6; // skip leading "speed="
  248. if (likely(s > word))
  249. raid->speed = str2ull(word);
  250. }
  251. }
  252. // read mismatch_cnt files
  253. if (do_mismatch == -1) {
  254. if (do_mismatch_config == CONFIG_BOOLEAN_AUTO) {
  255. if (raids_num > 50)
  256. do_mismatch = CONFIG_BOOLEAN_NO;
  257. else
  258. do_mismatch = CONFIG_BOOLEAN_YES;
  259. } else
  260. do_mismatch = do_mismatch_config;
  261. }
  262. if (likely(do_mismatch)) {
  263. for (raid_idx = 0; raid_idx < raids_num; raid_idx++) {
  264. char filename[FILENAME_MAX + 1];
  265. struct raid *raid = &raids[raid_idx];
  266. if (likely(raid->redundant)) {
  267. if (unlikely(!raid->mismatch_cnt_filename)) {
  268. snprintfz(filename, FILENAME_MAX, mismatch_cnt_filename, raid->name);
  269. raid->mismatch_cnt_filename = strdupz(filename);
  270. }
  271. if (unlikely(read_single_number_file(raid->mismatch_cnt_filename, &raid->mismatch_cnt))) {
  272. collector_error("Cannot read file '%s'", raid->mismatch_cnt_filename);
  273. do_mismatch = CONFIG_BOOLEAN_NO;
  274. collector_error("Monitoring for mismatch count has been disabled");
  275. break;
  276. }
  277. }
  278. }
  279. }
  280. // check for disappeared raids
  281. for (old_raid_idx = 0; old_raid_idx < old_raids_allocated; old_raid_idx++) {
  282. struct old_raid *old_raid = &old_raids[old_raid_idx];
  283. int found = 0;
  284. for (raid_idx = 0; raid_idx < raids_num; raid_idx++) {
  285. struct raid *raid = &raids[raid_idx];
  286. if (unlikely(
  287. raid->hash == old_raid->hash && !strcmp(raid->name, old_raid->name) &&
  288. raid->redundant == old_raid->redundant))
  289. found = 1;
  290. }
  291. old_raid->found = found;
  292. }
  293. int raid_disappeared = 0;
  294. for (old_raid_idx = 0; old_raid_idx < old_raids_allocated; old_raid_idx++) {
  295. struct old_raid *old_raid = &old_raids[old_raid_idx];
  296. if (unlikely(!old_raid->found)) {
  297. if (likely(make_charts_obsolete)) {
  298. make_chart_obsolete(old_raid->name, "disks");
  299. make_chart_obsolete(old_raid->name, "mismatch");
  300. make_chart_obsolete(old_raid->name, "operation");
  301. make_chart_obsolete(old_raid->name, "finish");
  302. make_chart_obsolete(old_raid->name, "speed");
  303. make_chart_obsolete(old_raid->name, "availability");
  304. }
  305. raid_disappeared = 1;
  306. }
  307. }
  308. // allocate memory for nonredundant arrays
  309. if (unlikely(raid_disappeared || old_raids_allocated != raids_num)) {
  310. for (old_raid_idx = 0; old_raid_idx < old_raids_allocated; old_raid_idx++) {
  311. freez(old_raids[old_raid_idx].name);
  312. }
  313. if (likely(raids_num)) {
  314. old_raids = reallocz(old_raids, sizeof(struct old_raid) * raids_num);
  315. memset(old_raids, 0, sizeof(struct old_raid) * raids_num);
  316. } else {
  317. freez(old_raids);
  318. old_raids = NULL;
  319. }
  320. old_raids_allocated = raids_num;
  321. for (old_raid_idx = 0; old_raid_idx < old_raids_allocated; old_raid_idx++) {
  322. struct old_raid *old_raid = &old_raids[old_raid_idx];
  323. struct raid *raid = &raids[old_raid_idx];
  324. old_raid->name = strdupz(raid->name);
  325. old_raid->hash = raid->hash;
  326. old_raid->redundant = raid->redundant;
  327. }
  328. }
  329. if (likely(do_health && redundant_num)) {
  330. static RRDSET *st_mdstat_health = NULL;
  331. if (unlikely(!st_mdstat_health)) {
  332. st_mdstat_health = rrdset_create_localhost(
  333. "mdstat",
  334. "mdstat_health",
  335. NULL,
  336. "health",
  337. "md.health",
  338. "Faulty Devices In MD",
  339. "failed disks",
  340. PLUGIN_PROC_NAME,
  341. PLUGIN_PROC_MODULE_MDSTAT_NAME,
  342. NETDATA_CHART_PRIO_MDSTAT_HEALTH,
  343. update_every,
  344. RRDSET_TYPE_LINE);
  345. rrdset_isnot_obsolete(st_mdstat_health);
  346. }
  347. if (!redundant_num) {
  348. if (likely(make_charts_obsolete))
  349. make_chart_obsolete("mdstat", "health");
  350. } else {
  351. for (raid_idx = 0; raid_idx < raids_num; raid_idx++) {
  352. struct raid *raid = &raids[raid_idx];
  353. if (likely(raid->redundant)) {
  354. if (unlikely(!raid->rd_health && !(raid->rd_health = rrddim_find_active(st_mdstat_health, raid->name))))
  355. raid->rd_health = rrddim_add(st_mdstat_health, raid->name, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  356. rrddim_set_by_pointer(st_mdstat_health, raid->rd_health, raid->failed_disks);
  357. }
  358. }
  359. rrdset_done(st_mdstat_health);
  360. }
  361. }
  362. for (raid_idx = 0; raid_idx < raids_num; raid_idx++) {
  363. struct raid *raid = &raids[raid_idx];
  364. char id[50 + 1];
  365. char family[50 + 1];
  366. if (likely(raid->redundant)) {
  367. if (likely(do_disks)) {
  368. snprintfz(id, 50, "%s_disks", raid->name);
  369. if (unlikely(!raid->st_disks && !(raid->st_disks = rrdset_find_active_byname_localhost(id)))) {
  370. snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
  371. raid->st_disks = rrdset_create_localhost(
  372. "mdstat",
  373. id,
  374. NULL,
  375. family,
  376. "md.disks",
  377. "Disks Stats",
  378. "disks",
  379. PLUGIN_PROC_NAME,
  380. PLUGIN_PROC_MODULE_MDSTAT_NAME,
  381. NETDATA_CHART_PRIO_MDSTAT_DISKS + raid_idx * 10,
  382. update_every,
  383. RRDSET_TYPE_STACKED);
  384. rrdset_isnot_obsolete(raid->st_disks);
  385. add_labels_to_mdstat(raid, raid->st_disks);
  386. }
  387. if (unlikely(!raid->rd_inuse && !(raid->rd_inuse = rrddim_find_active(raid->st_disks, "inuse"))))
  388. raid->rd_inuse = rrddim_add(raid->st_disks, "inuse", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  389. if (unlikely(!raid->rd_down && !(raid->rd_down = rrddim_find_active(raid->st_disks, "down"))))
  390. raid->rd_down = rrddim_add(raid->st_disks, "down", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  391. rrddim_set_by_pointer(raid->st_disks, raid->rd_inuse, raid->inuse_disks);
  392. rrddim_set_by_pointer(raid->st_disks, raid->rd_down, raid->failed_disks);
  393. rrdset_done(raid->st_disks);
  394. }
  395. if (likely(do_mismatch)) {
  396. snprintfz(id, 50, "%s_mismatch", raid->name);
  397. if (unlikely(!raid->st_mismatch_cnt && !(raid->st_mismatch_cnt = rrdset_find_active_byname_localhost(id)))) {
  398. snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
  399. raid->st_mismatch_cnt = rrdset_create_localhost(
  400. "mdstat",
  401. id,
  402. NULL,
  403. family,
  404. "md.mismatch_cnt",
  405. "Mismatch Count",
  406. "unsynchronized blocks",
  407. PLUGIN_PROC_NAME,
  408. PLUGIN_PROC_MODULE_MDSTAT_NAME,
  409. NETDATA_CHART_PRIO_MDSTAT_MISMATCH + raid_idx * 10,
  410. update_every,
  411. RRDSET_TYPE_LINE);
  412. rrdset_isnot_obsolete(raid->st_mismatch_cnt);
  413. add_labels_to_mdstat(raid, raid->st_mismatch_cnt);
  414. }
  415. if (unlikely(!raid->rd_mismatch_cnt && !(raid->rd_mismatch_cnt = rrddim_find_active(raid->st_mismatch_cnt, "count"))))
  416. raid->rd_mismatch_cnt = rrddim_add(raid->st_mismatch_cnt, "count", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  417. rrddim_set_by_pointer(raid->st_mismatch_cnt, raid->rd_mismatch_cnt, raid->mismatch_cnt);
  418. rrdset_done(raid->st_mismatch_cnt);
  419. }
  420. if (likely(do_operations)) {
  421. snprintfz(id, 50, "%s_operation", raid->name);
  422. if (unlikely(!raid->st_operation && !(raid->st_operation = rrdset_find_active_byname_localhost(id)))) {
  423. snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
  424. raid->st_operation = rrdset_create_localhost(
  425. "mdstat",
  426. id,
  427. NULL,
  428. family,
  429. "md.status",
  430. "Current Status",
  431. "percent",
  432. PLUGIN_PROC_NAME,
  433. PLUGIN_PROC_MODULE_MDSTAT_NAME,
  434. NETDATA_CHART_PRIO_MDSTAT_OPERATION + raid_idx * 10,
  435. update_every,
  436. RRDSET_TYPE_LINE);
  437. rrdset_isnot_obsolete(raid->st_operation);
  438. add_labels_to_mdstat(raid, raid->st_operation);
  439. }
  440. if(unlikely(!raid->rd_check && !(raid->rd_check = rrddim_find_active(raid->st_operation, "check"))))
  441. raid->rd_check = rrddim_add(raid->st_operation, "check", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
  442. if(unlikely(!raid->rd_resync && !(raid->rd_resync = rrddim_find_active(raid->st_operation, "resync"))))
  443. raid->rd_resync = rrddim_add(raid->st_operation, "resync", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
  444. if(unlikely(!raid->rd_recovery && !(raid->rd_recovery = rrddim_find_active(raid->st_operation, "recovery"))))
  445. raid->rd_recovery = rrddim_add(raid->st_operation, "recovery", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
  446. if(unlikely(!raid->rd_reshape && !(raid->rd_reshape = rrddim_find_active(raid->st_operation, "reshape"))))
  447. raid->rd_reshape = rrddim_add(raid->st_operation, "reshape", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
  448. rrddim_set_by_pointer(raid->st_operation, raid->rd_check, raid->check);
  449. rrddim_set_by_pointer(raid->st_operation, raid->rd_resync, raid->resync);
  450. rrddim_set_by_pointer(raid->st_operation, raid->rd_recovery, raid->recovery);
  451. rrddim_set_by_pointer(raid->st_operation, raid->rd_reshape, raid->reshape);
  452. rrdset_done(raid->st_operation);
  453. snprintfz(id, 50, "%s_finish", raid->name);
  454. if (unlikely(!raid->st_finish && !(raid->st_finish = rrdset_find_active_byname_localhost(id)))) {
  455. snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
  456. raid->st_finish = rrdset_create_localhost(
  457. "mdstat",
  458. id,
  459. NULL,
  460. family,
  461. "md.expected_time_until_operation_finish",
  462. "Approximate Time Until Finish",
  463. "seconds",
  464. PLUGIN_PROC_NAME,
  465. PLUGIN_PROC_MODULE_MDSTAT_NAME,
  466. NETDATA_CHART_PRIO_MDSTAT_FINISH + raid_idx * 10,
  467. update_every, RRDSET_TYPE_LINE);
  468. rrdset_isnot_obsolete(raid->st_finish);
  469. add_labels_to_mdstat(raid, raid->st_finish);
  470. }
  471. if(unlikely(!raid->rd_finish_in && !(raid->rd_finish_in = rrddim_find_active(raid->st_finish, "finish_in"))))
  472. raid->rd_finish_in = rrddim_add(raid->st_finish, "finish_in", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  473. rrddim_set_by_pointer(raid->st_finish, raid->rd_finish_in, raid->finish_in);
  474. rrdset_done(raid->st_finish);
  475. snprintfz(id, 50, "%s_speed", raid->name);
  476. if (unlikely(!raid->st_speed && !(raid->st_speed = rrdset_find_active_byname_localhost(id)))) {
  477. snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
  478. raid->st_speed = rrdset_create_localhost(
  479. "mdstat",
  480. id,
  481. NULL,
  482. family,
  483. "md.operation_speed",
  484. "Operation Speed",
  485. "KiB/s",
  486. PLUGIN_PROC_NAME,
  487. PLUGIN_PROC_MODULE_MDSTAT_NAME,
  488. NETDATA_CHART_PRIO_MDSTAT_SPEED + raid_idx * 10,
  489. update_every,
  490. RRDSET_TYPE_LINE);
  491. rrdset_isnot_obsolete(raid->st_speed);
  492. add_labels_to_mdstat(raid, raid->st_speed);
  493. }
  494. if (unlikely(!raid->rd_speed && !(raid->rd_speed = rrddim_find_active(raid->st_speed, "speed"))))
  495. raid->rd_speed = rrddim_add(raid->st_speed, "speed", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  496. rrddim_set_by_pointer(raid->st_speed, raid->rd_speed, raid->speed);
  497. rrdset_done(raid->st_speed);
  498. }
  499. } else {
  500. if (likely(do_nonredundant)) {
  501. snprintfz(id, 50, "%s_availability", raid->name);
  502. if (unlikely(!raid->st_nonredundant && !(raid->st_nonredundant = rrdset_find_active_localhost(id)))) {
  503. snprintfz(family, 50, "%s (%s)", raid->name, raid->level);
  504. raid->st_nonredundant = rrdset_create_localhost(
  505. "mdstat",
  506. id,
  507. NULL,
  508. family,
  509. "md.nonredundant",
  510. "Nonredundant Array Availability",
  511. "boolean",
  512. PLUGIN_PROC_NAME,
  513. PLUGIN_PROC_MODULE_MDSTAT_NAME,
  514. NETDATA_CHART_PRIO_MDSTAT_NONREDUNDANT + raid_idx * 10,
  515. update_every,
  516. RRDSET_TYPE_LINE);
  517. rrdset_isnot_obsolete(raid->st_nonredundant);
  518. add_labels_to_mdstat(raid, raid->st_nonredundant);
  519. }
  520. if (unlikely(!raid->rd_nonredundant && !(raid->rd_nonredundant = rrddim_find_active(raid->st_nonredundant, "available"))))
  521. raid->rd_nonredundant = rrddim_add(raid->st_nonredundant, "available", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  522. rrddim_set_by_pointer(raid->st_nonredundant, raid->rd_nonredundant, 1);
  523. rrdset_done(raid->st_nonredundant);
  524. }
  525. }
  526. }
  527. return 0;
  528. }