proc_mdstat.c 24 KB

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