proc_mdstat.c 24 KB

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