proc_mdstat.c 25 KB

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