zfs_common.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "zfs_common.h"
  3. struct arcstats arcstats = { 0 };
  4. void generate_charts_arcstats(const char *plugin, const char *module, int show_zero_charts, int update_every) {
  5. static int do_arc_size = -1, do_l2_size = -1, do_reads = -1, do_l2bytes = -1, do_ahits = -1, do_dhits = -1, \
  6. do_phits = -1, do_mhits = -1, do_l2hits = -1, do_list_hits = -1;
  7. if(unlikely(do_arc_size == -1))
  8. do_arc_size = do_l2_size = do_reads = do_l2bytes = do_ahits = do_dhits = do_phits = do_mhits \
  9. = do_l2hits = do_list_hits = show_zero_charts;
  10. // ARC reads
  11. unsigned long long aread = arcstats.hits + arcstats.misses;
  12. // Demand reads
  13. unsigned long long dhit = arcstats.demand_data_hits + arcstats.demand_metadata_hits;
  14. unsigned long long dmiss = arcstats.demand_data_misses + arcstats.demand_metadata_misses;
  15. unsigned long long dread = dhit + dmiss;
  16. // Prefetch reads
  17. unsigned long long phit = arcstats.prefetch_data_hits + arcstats.prefetch_metadata_hits;
  18. unsigned long long pmiss = arcstats.prefetch_data_misses + arcstats.prefetch_metadata_misses;
  19. unsigned long long pread = phit + pmiss;
  20. // Metadata reads
  21. unsigned long long mhit = arcstats.prefetch_metadata_hits + arcstats.demand_metadata_hits;
  22. unsigned long long mmiss = arcstats.prefetch_metadata_misses + arcstats.demand_metadata_misses;
  23. unsigned long long mread = mhit + mmiss;
  24. // l2 reads
  25. unsigned long long l2hit = arcstats.l2_hits;
  26. unsigned long long l2miss = arcstats.l2_misses;
  27. unsigned long long l2read = l2hit + l2miss;
  28. // --------------------------------------------------------------------
  29. if(do_arc_size == CONFIG_BOOLEAN_YES || arcstats.size || arcstats.c || arcstats.c_min || arcstats.c_max) {
  30. do_arc_size = CONFIG_BOOLEAN_YES;
  31. static RRDSET *st_arc_size = NULL;
  32. static RRDDIM *rd_arc_size = NULL;
  33. static RRDDIM *rd_arc_target_size = NULL;
  34. static RRDDIM *rd_arc_target_min_size = NULL;
  35. static RRDDIM *rd_arc_target_max_size = NULL;
  36. if (unlikely(!st_arc_size)) {
  37. st_arc_size = rrdset_create_localhost(
  38. "zfs"
  39. , "arc_size"
  40. , NULL
  41. , ZFS_FAMILY_SIZE
  42. , NULL
  43. , "ZFS ARC Size"
  44. , "MiB"
  45. , plugin
  46. , module
  47. , NETDATA_CHART_PRIO_ZFS_ARC_SIZE
  48. , update_every
  49. , RRDSET_TYPE_AREA
  50. );
  51. rd_arc_size = rrddim_add(st_arc_size, "size", "arcsz", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
  52. rd_arc_target_size = rrddim_add(st_arc_size, "target", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
  53. rd_arc_target_min_size = rrddim_add(st_arc_size, "min", "min (hard limit)", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
  54. rd_arc_target_max_size = rrddim_add(st_arc_size, "max", "max (high water)", 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
  55. }
  56. rrddim_set_by_pointer(st_arc_size, rd_arc_size, arcstats.size);
  57. rrddim_set_by_pointer(st_arc_size, rd_arc_target_size, arcstats.c);
  58. rrddim_set_by_pointer(st_arc_size, rd_arc_target_min_size, arcstats.c_min);
  59. rrddim_set_by_pointer(st_arc_size, rd_arc_target_max_size, arcstats.c_max);
  60. rrdset_done(st_arc_size);
  61. }
  62. // --------------------------------------------------------------------
  63. if(likely(arcstats.l2exist) && (do_l2_size == CONFIG_BOOLEAN_YES || arcstats.l2_size || arcstats.l2_asize)) {
  64. do_l2_size = CONFIG_BOOLEAN_YES;
  65. static RRDSET *st_l2_size = NULL;
  66. static RRDDIM *rd_l2_size = NULL;
  67. static RRDDIM *rd_l2_asize = NULL;
  68. if (unlikely(!st_l2_size)) {
  69. st_l2_size = rrdset_create_localhost(
  70. "zfs"
  71. , "l2_size"
  72. , NULL
  73. , ZFS_FAMILY_SIZE
  74. , NULL
  75. , "ZFS L2 ARC Size"
  76. , "MiB"
  77. , plugin
  78. , module
  79. , NETDATA_CHART_PRIO_ZFS_L2_SIZE
  80. , update_every
  81. , RRDSET_TYPE_AREA
  82. );
  83. rd_l2_asize = rrddim_add(st_l2_size, "actual", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
  84. rd_l2_size = rrddim_add(st_l2_size, "size", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
  85. }
  86. rrddim_set_by_pointer(st_l2_size, rd_l2_size, arcstats.l2_size);
  87. rrddim_set_by_pointer(st_l2_size, rd_l2_asize, arcstats.l2_asize);
  88. rrdset_done(st_l2_size);
  89. }
  90. // --------------------------------------------------------------------
  91. if(likely(do_reads == CONFIG_BOOLEAN_YES || aread || dread || pread || mread || l2read)) {
  92. do_reads = CONFIG_BOOLEAN_YES;
  93. static RRDSET *st_reads = NULL;
  94. static RRDDIM *rd_aread = NULL;
  95. static RRDDIM *rd_dread = NULL;
  96. static RRDDIM *rd_pread = NULL;
  97. static RRDDIM *rd_mread = NULL;
  98. static RRDDIM *rd_l2read = NULL;
  99. if (unlikely(!st_reads)) {
  100. st_reads = rrdset_create_localhost(
  101. "zfs"
  102. , "reads"
  103. , NULL
  104. , ZFS_FAMILY_ACCESSES
  105. , NULL
  106. , "ZFS Reads"
  107. , "reads/s"
  108. , plugin
  109. , module
  110. , NETDATA_CHART_PRIO_ZFS_READS
  111. , update_every
  112. , RRDSET_TYPE_AREA
  113. );
  114. rd_aread = rrddim_add(st_reads, "areads", "arc", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  115. rd_dread = rrddim_add(st_reads, "dreads", "demand", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  116. rd_pread = rrddim_add(st_reads, "preads", "prefetch", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  117. rd_mread = rrddim_add(st_reads, "mreads", "metadata", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  118. if(arcstats.l2exist)
  119. rd_l2read = rrddim_add(st_reads, "l2reads", "l2", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  120. }
  121. rrddim_set_by_pointer(st_reads, rd_aread, aread);
  122. rrddim_set_by_pointer(st_reads, rd_dread, dread);
  123. rrddim_set_by_pointer(st_reads, rd_pread, pread);
  124. rrddim_set_by_pointer(st_reads, rd_mread, mread);
  125. if(arcstats.l2exist)
  126. rrddim_set_by_pointer(st_reads, rd_l2read, l2read);
  127. rrdset_done(st_reads);
  128. }
  129. // --------------------------------------------------------------------
  130. if(likely(arcstats.l2exist && (do_l2bytes == CONFIG_BOOLEAN_YES || arcstats.l2_read_bytes || arcstats.l2_write_bytes))) {
  131. do_l2bytes = CONFIG_BOOLEAN_YES;
  132. static RRDSET *st_l2bytes = NULL;
  133. static RRDDIM *rd_l2_read_bytes = NULL;
  134. static RRDDIM *rd_l2_write_bytes = NULL;
  135. if (unlikely(!st_l2bytes)) {
  136. st_l2bytes = rrdset_create_localhost(
  137. "zfs"
  138. , "bytes"
  139. , NULL
  140. , ZFS_FAMILY_ACCESSES
  141. , NULL
  142. , "ZFS ARC L2 Read/Write Rate"
  143. , "KiB/s"
  144. , plugin
  145. , module
  146. , NETDATA_CHART_PRIO_ZFS_IO
  147. , update_every
  148. , RRDSET_TYPE_AREA
  149. );
  150. rd_l2_read_bytes = rrddim_add(st_l2bytes, "read", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL);
  151. rd_l2_write_bytes = rrddim_add(st_l2bytes, "write", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL);
  152. }
  153. rrddim_set_by_pointer(st_l2bytes, rd_l2_read_bytes, arcstats.l2_read_bytes);
  154. rrddim_set_by_pointer(st_l2bytes, rd_l2_write_bytes, arcstats.l2_write_bytes);
  155. rrdset_done(st_l2bytes);
  156. }
  157. // --------------------------------------------------------------------
  158. if(likely(do_ahits == CONFIG_BOOLEAN_YES || arcstats.hits || arcstats.misses)) {
  159. do_ahits = CONFIG_BOOLEAN_YES;
  160. static RRDSET *st_ahits = NULL;
  161. static RRDDIM *rd_ahits = NULL;
  162. static RRDDIM *rd_amisses = NULL;
  163. if (unlikely(!st_ahits)) {
  164. st_ahits = rrdset_create_localhost(
  165. "zfs"
  166. , "hits"
  167. , NULL
  168. , ZFS_FAMILY_EFFICIENCY
  169. , NULL
  170. , "ZFS ARC Hits"
  171. , "percentage"
  172. , plugin
  173. , module
  174. , NETDATA_CHART_PRIO_ZFS_HITS
  175. , update_every
  176. , RRDSET_TYPE_STACKED
  177. );
  178. rd_ahits = rrddim_add(st_ahits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  179. rd_amisses = rrddim_add(st_ahits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  180. }
  181. rrddim_set_by_pointer(st_ahits, rd_ahits, arcstats.hits);
  182. rrddim_set_by_pointer(st_ahits, rd_amisses, arcstats.misses);
  183. rrdset_done(st_ahits);
  184. static RRDSET *st_ahits_rate = NULL;
  185. static RRDDIM *rd_ahits_rate = NULL;
  186. static RRDDIM *rd_amisses_rate = NULL;
  187. if (unlikely(!st_ahits_rate)) {
  188. st_ahits_rate = rrdset_create_localhost(
  189. "zfs"
  190. , "hits_rate"
  191. , NULL
  192. , ZFS_FAMILY_EFFICIENCY
  193. , NULL
  194. , "ZFS ARC Hits Rate"
  195. , "events/s"
  196. , plugin
  197. , module
  198. , NETDATA_CHART_PRIO_ZFS_HITS + 1
  199. , update_every
  200. , RRDSET_TYPE_STACKED
  201. );
  202. rd_ahits_rate = rrddim_add(st_ahits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  203. rd_amisses_rate = rrddim_add(st_ahits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  204. }
  205. rrddim_set_by_pointer(st_ahits_rate, rd_ahits_rate, arcstats.hits);
  206. rrddim_set_by_pointer(st_ahits_rate, rd_amisses_rate, arcstats.misses);
  207. rrdset_done(st_ahits_rate);
  208. }
  209. // --------------------------------------------------------------------
  210. if(likely(do_dhits == CONFIG_BOOLEAN_YES || dhit || dmiss)) {
  211. do_dhits = CONFIG_BOOLEAN_YES;
  212. static RRDSET *st_dhits = NULL;
  213. static RRDDIM *rd_dhits = NULL;
  214. static RRDDIM *rd_dmisses = NULL;
  215. if (unlikely(!st_dhits)) {
  216. st_dhits = rrdset_create_localhost(
  217. "zfs"
  218. , "dhits"
  219. , NULL
  220. , ZFS_FAMILY_EFFICIENCY
  221. , NULL
  222. , "ZFS Demand Hits"
  223. , "percentage"
  224. , plugin
  225. , module
  226. , NETDATA_CHART_PRIO_ZFS_DHITS
  227. , update_every
  228. , RRDSET_TYPE_STACKED
  229. );
  230. rd_dhits = rrddim_add(st_dhits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  231. rd_dmisses = rrddim_add(st_dhits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  232. }
  233. rrddim_set_by_pointer(st_dhits, rd_dhits, dhit);
  234. rrddim_set_by_pointer(st_dhits, rd_dmisses, dmiss);
  235. rrdset_done(st_dhits);
  236. static RRDSET *st_dhits_rate = NULL;
  237. static RRDDIM *rd_dhits_rate = NULL;
  238. static RRDDIM *rd_dmisses_rate = NULL;
  239. if (unlikely(!st_dhits_rate)) {
  240. st_dhits_rate = rrdset_create_localhost(
  241. "zfs"
  242. , "dhits_rate"
  243. , NULL
  244. , ZFS_FAMILY_EFFICIENCY
  245. , NULL
  246. , "ZFS Demand Hits Rate"
  247. , "events/s"
  248. , plugin
  249. , module
  250. , NETDATA_CHART_PRIO_ZFS_DHITS + 1
  251. , update_every
  252. , RRDSET_TYPE_STACKED
  253. );
  254. rd_dhits_rate = rrddim_add(st_dhits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  255. rd_dmisses_rate = rrddim_add(st_dhits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  256. }
  257. rrddim_set_by_pointer(st_dhits_rate, rd_dhits_rate, dhit);
  258. rrddim_set_by_pointer(st_dhits_rate, rd_dmisses_rate, dmiss);
  259. rrdset_done(st_dhits_rate);
  260. }
  261. // --------------------------------------------------------------------
  262. if(likely(do_phits == CONFIG_BOOLEAN_YES || phit || pmiss)) {
  263. do_phits = CONFIG_BOOLEAN_YES;
  264. static RRDSET *st_phits = NULL;
  265. static RRDDIM *rd_phits = NULL;
  266. static RRDDIM *rd_pmisses = NULL;
  267. if (unlikely(!st_phits)) {
  268. st_phits = rrdset_create_localhost(
  269. "zfs"
  270. , "phits"
  271. , NULL
  272. , ZFS_FAMILY_EFFICIENCY
  273. , NULL
  274. , "ZFS Prefetch Hits"
  275. , "percentage"
  276. , plugin
  277. , module
  278. , NETDATA_CHART_PRIO_ZFS_PHITS
  279. , update_every
  280. , RRDSET_TYPE_STACKED
  281. );
  282. rd_phits = rrddim_add(st_phits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  283. rd_pmisses = rrddim_add(st_phits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  284. }
  285. rrddim_set_by_pointer(st_phits, rd_phits, phit);
  286. rrddim_set_by_pointer(st_phits, rd_pmisses, pmiss);
  287. rrdset_done(st_phits);
  288. static RRDSET *st_phits_rate = NULL;
  289. static RRDDIM *rd_phits_rate = NULL;
  290. static RRDDIM *rd_pmisses_rate = NULL;
  291. if (unlikely(!st_phits_rate)) {
  292. st_phits_rate = rrdset_create_localhost(
  293. "zfs"
  294. , "phits_rate"
  295. , NULL
  296. , ZFS_FAMILY_EFFICIENCY
  297. , NULL
  298. , "ZFS Prefetch Hits Rate"
  299. , "events/s"
  300. , plugin
  301. , module
  302. , NETDATA_CHART_PRIO_ZFS_PHITS + 1
  303. , update_every
  304. , RRDSET_TYPE_STACKED
  305. );
  306. rd_phits_rate = rrddim_add(st_phits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  307. rd_pmisses_rate = rrddim_add(st_phits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  308. }
  309. rrddim_set_by_pointer(st_phits_rate, rd_phits_rate, phit);
  310. rrddim_set_by_pointer(st_phits_rate, rd_pmisses_rate, pmiss);
  311. rrdset_done(st_phits_rate);
  312. }
  313. // --------------------------------------------------------------------
  314. if(likely(do_mhits == CONFIG_BOOLEAN_YES || mhit || mmiss)) {
  315. do_mhits = CONFIG_BOOLEAN_YES;
  316. static RRDSET *st_mhits = NULL;
  317. static RRDDIM *rd_mhits = NULL;
  318. static RRDDIM *rd_mmisses = NULL;
  319. if (unlikely(!st_mhits)) {
  320. st_mhits = rrdset_create_localhost(
  321. "zfs"
  322. , "mhits"
  323. , NULL
  324. , ZFS_FAMILY_EFFICIENCY
  325. , NULL
  326. , "ZFS Metadata Hits"
  327. , "percentage"
  328. , plugin
  329. , module
  330. , NETDATA_CHART_PRIO_ZFS_MHITS
  331. , update_every
  332. , RRDSET_TYPE_STACKED
  333. );
  334. rd_mhits = rrddim_add(st_mhits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  335. rd_mmisses = rrddim_add(st_mhits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  336. }
  337. rrddim_set_by_pointer(st_mhits, rd_mhits, mhit);
  338. rrddim_set_by_pointer(st_mhits, rd_mmisses, mmiss);
  339. rrdset_done(st_mhits);
  340. static RRDSET *st_mhits_rate = NULL;
  341. static RRDDIM *rd_mhits_rate = NULL;
  342. static RRDDIM *rd_mmisses_rate = NULL;
  343. if (unlikely(!st_mhits_rate)) {
  344. st_mhits_rate = rrdset_create_localhost(
  345. "zfs"
  346. , "mhits_rate"
  347. , NULL
  348. , ZFS_FAMILY_EFFICIENCY
  349. , NULL
  350. , "ZFS Metadata Hits Rate"
  351. , "events/s"
  352. , plugin
  353. , module
  354. , NETDATA_CHART_PRIO_ZFS_MHITS + 1
  355. , update_every
  356. , RRDSET_TYPE_STACKED
  357. );
  358. rd_mhits_rate = rrddim_add(st_mhits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  359. rd_mmisses_rate = rrddim_add(st_mhits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  360. }
  361. rrddim_set_by_pointer(st_mhits_rate, rd_mhits_rate, mhit);
  362. rrddim_set_by_pointer(st_mhits_rate, rd_mmisses_rate, mmiss);
  363. rrdset_done(st_mhits_rate);
  364. }
  365. // --------------------------------------------------------------------
  366. if(likely(arcstats.l2exist && (do_l2hits == CONFIG_BOOLEAN_YES || l2hit || l2miss))) {
  367. do_l2hits = CONFIG_BOOLEAN_YES;
  368. static RRDSET *st_l2hits = NULL;
  369. static RRDDIM *rd_l2hits = NULL;
  370. static RRDDIM *rd_l2misses = NULL;
  371. if (unlikely(!st_l2hits)) {
  372. st_l2hits = rrdset_create_localhost(
  373. "zfs"
  374. , "l2hits"
  375. , NULL
  376. , ZFS_FAMILY_EFFICIENCY
  377. , NULL
  378. , "ZFS L2 Hits"
  379. , "percentage"
  380. , plugin
  381. , module
  382. , NETDATA_CHART_PRIO_ZFS_L2HITS
  383. , update_every
  384. , RRDSET_TYPE_STACKED
  385. );
  386. rd_l2hits = rrddim_add(st_l2hits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  387. rd_l2misses = rrddim_add(st_l2hits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  388. }
  389. rrddim_set_by_pointer(st_l2hits, rd_l2hits, l2hit);
  390. rrddim_set_by_pointer(st_l2hits, rd_l2misses, l2miss);
  391. rrdset_done(st_l2hits);
  392. static RRDSET *st_l2hits_rate = NULL;
  393. static RRDDIM *rd_l2hits_rate = NULL;
  394. static RRDDIM *rd_l2misses_rate = NULL;
  395. if (unlikely(!st_l2hits_rate)) {
  396. st_l2hits_rate = rrdset_create_localhost(
  397. "zfs"
  398. , "l2hits_rate"
  399. , NULL
  400. , ZFS_FAMILY_EFFICIENCY
  401. , NULL
  402. , "ZFS L2 Hits Rate"
  403. , "events/s"
  404. , plugin
  405. , module
  406. , NETDATA_CHART_PRIO_ZFS_L2HITS + 1
  407. , update_every
  408. , RRDSET_TYPE_STACKED
  409. );
  410. rd_l2hits_rate = rrddim_add(st_l2hits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  411. rd_l2misses_rate = rrddim_add(st_l2hits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  412. }
  413. rrddim_set_by_pointer(st_l2hits_rate, rd_l2hits_rate, l2hit);
  414. rrddim_set_by_pointer(st_l2hits_rate, rd_l2misses_rate, l2miss);
  415. rrdset_done(st_l2hits_rate);
  416. }
  417. // --------------------------------------------------------------------
  418. if(likely(do_list_hits == CONFIG_BOOLEAN_YES || arcstats.mfu_hits \
  419. || arcstats.mru_hits \
  420. || arcstats.mfu_ghost_hits \
  421. || arcstats.mru_ghost_hits)) {
  422. do_list_hits = CONFIG_BOOLEAN_YES;
  423. static RRDSET *st_list_hits = NULL;
  424. static RRDDIM *rd_mfu = NULL;
  425. static RRDDIM *rd_mru = NULL;
  426. static RRDDIM *rd_mfug = NULL;
  427. static RRDDIM *rd_mrug = NULL;
  428. if (unlikely(!st_list_hits)) {
  429. st_list_hits = rrdset_create_localhost(
  430. "zfs"
  431. , "list_hits"
  432. , NULL
  433. , ZFS_FAMILY_EFFICIENCY
  434. , NULL
  435. , "ZFS List Hits"
  436. , "hits/s"
  437. , plugin
  438. , module
  439. , NETDATA_CHART_PRIO_ZFS_LIST_HITS
  440. , update_every
  441. , RRDSET_TYPE_AREA
  442. );
  443. rd_mfu = rrddim_add(st_list_hits, "mfu", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  444. rd_mfug = rrddim_add(st_list_hits, "mfug", "mfu ghost", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  445. rd_mru = rrddim_add(st_list_hits, "mru", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  446. rd_mrug = rrddim_add(st_list_hits, "mrug", "mru ghost", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  447. }
  448. rrddim_set_by_pointer(st_list_hits, rd_mfu, arcstats.mfu_hits);
  449. rrddim_set_by_pointer(st_list_hits, rd_mru, arcstats.mru_hits);
  450. rrddim_set_by_pointer(st_list_hits, rd_mfug, arcstats.mfu_ghost_hits);
  451. rrddim_set_by_pointer(st_list_hits, rd_mrug, arcstats.mru_ghost_hits);
  452. rrdset_done(st_list_hits);
  453. }
  454. }
  455. void generate_charts_arc_summary(const char *plugin, const char *module, int show_zero_charts, int update_every) {
  456. static int do_arc_size_breakdown = -1, do_memory = -1, do_important_ops = -1, do_actual_hits = -1, \
  457. do_demand_data_hits = -1, do_prefetch_data_hits = -1, do_hash_elements = -1, do_hash_chains = -1;
  458. if(unlikely(do_arc_size_breakdown == -1))
  459. do_arc_size_breakdown = do_memory = do_important_ops = do_actual_hits = do_demand_data_hits \
  460. = do_prefetch_data_hits = do_hash_elements = do_hash_chains = show_zero_charts;
  461. unsigned long long arc_accesses_total = arcstats.hits + arcstats.misses;
  462. unsigned long long real_hits = arcstats.mfu_hits + arcstats.mru_hits;
  463. unsigned long long real_misses = arc_accesses_total - real_hits;
  464. //unsigned long long anon_hits = arcstats.hits - (arcstats.mfu_hits + arcstats.mru_hits + arcstats.mfu_ghost_hits + arcstats.mru_ghost_hits);
  465. unsigned long long arc_size = arcstats.size;
  466. unsigned long long mru_size = arcstats.p;
  467. //unsigned long long target_min_size = arcstats.c_min;
  468. //unsigned long long target_max_size = arcstats.c_max;
  469. unsigned long long target_size = arcstats.c;
  470. //unsigned long long target_size_ratio = (target_max_size / target_min_size);
  471. unsigned long long mfu_size;
  472. if(arc_size > target_size)
  473. mfu_size = arc_size - mru_size;
  474. else
  475. mfu_size = target_size - mru_size;
  476. // --------------------------------------------------------------------
  477. if(likely(do_arc_size_breakdown == CONFIG_BOOLEAN_YES || mru_size || mfu_size)) {
  478. do_arc_size_breakdown = CONFIG_BOOLEAN_YES;
  479. static RRDSET *st_arc_size_breakdown = NULL;
  480. static RRDDIM *rd_most_recent = NULL;
  481. static RRDDIM *rd_most_frequent = NULL;
  482. if (unlikely(!st_arc_size_breakdown)) {
  483. st_arc_size_breakdown = rrdset_create_localhost(
  484. "zfs"
  485. , "arc_size_breakdown"
  486. , NULL
  487. , ZFS_FAMILY_EFFICIENCY
  488. , NULL
  489. , "ZFS ARC Size Breakdown"
  490. , "percentage"
  491. , plugin
  492. , module
  493. , NETDATA_CHART_PRIO_ZFS_ARC_SIZE_BREAKDOWN
  494. , update_every
  495. , RRDSET_TYPE_STACKED
  496. );
  497. rd_most_recent = rrddim_add(st_arc_size_breakdown, "recent", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL);
  498. rd_most_frequent = rrddim_add(st_arc_size_breakdown, "frequent", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL);
  499. }
  500. rrddim_set_by_pointer(st_arc_size_breakdown, rd_most_recent, mru_size);
  501. rrddim_set_by_pointer(st_arc_size_breakdown, rd_most_frequent, mfu_size);
  502. rrdset_done(st_arc_size_breakdown);
  503. }
  504. // --------------------------------------------------------------------
  505. if(likely(do_memory == CONFIG_BOOLEAN_YES || arcstats.memory_direct_count \
  506. || arcstats.memory_throttle_count \
  507. || arcstats.memory_indirect_count)) {
  508. do_memory = CONFIG_BOOLEAN_YES;
  509. static RRDSET *st_memory = NULL;
  510. #ifndef __FreeBSD__
  511. static RRDDIM *rd_direct = NULL;
  512. #endif
  513. static RRDDIM *rd_throttled = NULL;
  514. #ifndef __FreeBSD__
  515. static RRDDIM *rd_indirect = NULL;
  516. #endif
  517. if (unlikely(!st_memory)) {
  518. st_memory = rrdset_create_localhost(
  519. "zfs"
  520. , "memory_ops"
  521. , NULL
  522. , ZFS_FAMILY_OPERATIONS
  523. , NULL
  524. , "ZFS Memory Operations"
  525. , "operations/s"
  526. , plugin
  527. , module
  528. , NETDATA_CHART_PRIO_ZFS_MEMORY_OPS
  529. , update_every
  530. , RRDSET_TYPE_LINE
  531. );
  532. #ifndef __FreeBSD__
  533. rd_direct = rrddim_add(st_memory, "direct", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  534. #endif
  535. rd_throttled = rrddim_add(st_memory, "throttled", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  536. #ifndef __FreeBSD__
  537. rd_indirect = rrddim_add(st_memory, "indirect", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  538. #endif
  539. }
  540. #ifndef __FreeBSD__
  541. rrddim_set_by_pointer(st_memory, rd_direct, arcstats.memory_direct_count);
  542. #endif
  543. rrddim_set_by_pointer(st_memory, rd_throttled, arcstats.memory_throttle_count);
  544. #ifndef __FreeBSD__
  545. rrddim_set_by_pointer(st_memory, rd_indirect, arcstats.memory_indirect_count);
  546. #endif
  547. rrdset_done(st_memory);
  548. }
  549. // --------------------------------------------------------------------
  550. if(likely(do_important_ops == CONFIG_BOOLEAN_YES || arcstats.deleted \
  551. || arcstats.evict_skip \
  552. || arcstats.mutex_miss \
  553. || arcstats.hash_collisions)) {
  554. do_important_ops = CONFIG_BOOLEAN_YES;
  555. static RRDSET *st_important_ops = NULL;
  556. static RRDDIM *rd_deleted = NULL;
  557. static RRDDIM *rd_mutex_misses = NULL;
  558. static RRDDIM *rd_evict_skips = NULL;
  559. static RRDDIM *rd_hash_collisions = NULL;
  560. if (unlikely(!st_important_ops)) {
  561. st_important_ops = rrdset_create_localhost(
  562. "zfs"
  563. , "important_ops"
  564. , NULL
  565. , ZFS_FAMILY_OPERATIONS
  566. , NULL
  567. , "ZFS Important Operations"
  568. , "operations/s"
  569. , plugin
  570. , module
  571. , NETDATA_CHART_PRIO_ZFS_IMPORTANT_OPS
  572. , update_every
  573. , RRDSET_TYPE_LINE
  574. );
  575. rd_evict_skips = rrddim_add(st_important_ops, "eskip", "evict skip", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  576. rd_deleted = rrddim_add(st_important_ops, "deleted", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  577. rd_mutex_misses = rrddim_add(st_important_ops, "mtxmis", "mutex miss", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  578. rd_hash_collisions = rrddim_add(st_important_ops, "hash_collisions", "hash collisions", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  579. }
  580. rrddim_set_by_pointer(st_important_ops, rd_deleted, arcstats.deleted);
  581. rrddim_set_by_pointer(st_important_ops, rd_evict_skips, arcstats.evict_skip);
  582. rrddim_set_by_pointer(st_important_ops, rd_mutex_misses, arcstats.mutex_miss);
  583. rrddim_set_by_pointer(st_important_ops, rd_hash_collisions, arcstats.hash_collisions);
  584. rrdset_done(st_important_ops);
  585. }
  586. // --------------------------------------------------------------------
  587. if(likely(do_actual_hits == CONFIG_BOOLEAN_YES || real_hits || real_misses)) {
  588. do_actual_hits = CONFIG_BOOLEAN_YES;
  589. static RRDSET *st_actual_hits = NULL;
  590. static RRDDIM *rd_actual_hits = NULL;
  591. static RRDDIM *rd_actual_misses = NULL;
  592. if (unlikely(!st_actual_hits)) {
  593. st_actual_hits = rrdset_create_localhost(
  594. "zfs"
  595. , "actual_hits"
  596. , NULL
  597. , ZFS_FAMILY_EFFICIENCY
  598. , NULL
  599. , "ZFS Actual Cache Hits"
  600. , "percentage"
  601. , plugin
  602. , module
  603. , NETDATA_CHART_PRIO_ZFS_ACTUAL_HITS
  604. , update_every
  605. , RRDSET_TYPE_STACKED
  606. );
  607. rd_actual_hits = rrddim_add(st_actual_hits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  608. rd_actual_misses = rrddim_add(st_actual_hits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  609. }
  610. rrddim_set_by_pointer(st_actual_hits, rd_actual_hits, real_hits);
  611. rrddim_set_by_pointer(st_actual_hits, rd_actual_misses, real_misses);
  612. rrdset_done(st_actual_hits);
  613. static RRDSET *st_actual_hits_rate = NULL;
  614. static RRDDIM *rd_actual_hits_rate = NULL;
  615. static RRDDIM *rd_actual_misses_rate = NULL;
  616. if (unlikely(!st_actual_hits_rate)) {
  617. st_actual_hits_rate = rrdset_create_localhost(
  618. "zfs"
  619. , "actual_hits_rate"
  620. , NULL
  621. , ZFS_FAMILY_EFFICIENCY
  622. , NULL
  623. , "ZFS Actual Cache Hits Rate"
  624. , "events/s"
  625. , plugin
  626. , module
  627. , NETDATA_CHART_PRIO_ZFS_ACTUAL_HITS + 1
  628. , update_every
  629. , RRDSET_TYPE_STACKED
  630. );
  631. rd_actual_hits_rate = rrddim_add(st_actual_hits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  632. rd_actual_misses_rate = rrddim_add(st_actual_hits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  633. }
  634. rrddim_set_by_pointer(st_actual_hits_rate, rd_actual_hits_rate, real_hits);
  635. rrddim_set_by_pointer(st_actual_hits_rate, rd_actual_misses_rate, real_misses);
  636. rrdset_done(st_actual_hits_rate);
  637. }
  638. // --------------------------------------------------------------------
  639. if(likely(do_demand_data_hits == CONFIG_BOOLEAN_YES || arcstats.demand_data_hits || arcstats.demand_data_misses)) {
  640. do_demand_data_hits = CONFIG_BOOLEAN_YES;
  641. static RRDSET *st_demand_data_hits = NULL;
  642. static RRDDIM *rd_demand_data_hits = NULL;
  643. static RRDDIM *rd_demand_data_misses = NULL;
  644. if (unlikely(!st_demand_data_hits)) {
  645. st_demand_data_hits = rrdset_create_localhost(
  646. "zfs"
  647. , "demand_data_hits"
  648. , NULL
  649. , ZFS_FAMILY_EFFICIENCY
  650. , NULL
  651. , "ZFS Data Demand Efficiency"
  652. , "percentage"
  653. , plugin
  654. , module
  655. , NETDATA_CHART_PRIO_ZFS_DEMAND_DATA_HITS
  656. , update_every
  657. , RRDSET_TYPE_STACKED
  658. );
  659. rd_demand_data_hits = rrddim_add(st_demand_data_hits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  660. rd_demand_data_misses = rrddim_add(st_demand_data_hits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  661. }
  662. rrddim_set_by_pointer(st_demand_data_hits, rd_demand_data_hits, arcstats.demand_data_hits);
  663. rrddim_set_by_pointer(st_demand_data_hits, rd_demand_data_misses, arcstats.demand_data_misses);
  664. rrdset_done(st_demand_data_hits);
  665. static RRDSET *st_demand_data_hits_rate = NULL;
  666. static RRDDIM *rd_demand_data_hits_rate = NULL;
  667. static RRDDIM *rd_demand_data_misses_rate = NULL;
  668. if (unlikely(!st_demand_data_hits_rate)) {
  669. st_demand_data_hits_rate = rrdset_create_localhost(
  670. "zfs"
  671. , "demand_data_hits_rate"
  672. , NULL
  673. , ZFS_FAMILY_EFFICIENCY
  674. , NULL
  675. , "ZFS Data Demand Efficiency Rate"
  676. , "events/s"
  677. , plugin
  678. , module
  679. , NETDATA_CHART_PRIO_ZFS_DEMAND_DATA_HITS + 1
  680. , update_every
  681. , RRDSET_TYPE_STACKED
  682. );
  683. rd_demand_data_hits_rate = rrddim_add(st_demand_data_hits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  684. rd_demand_data_misses_rate = rrddim_add(st_demand_data_hits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  685. }
  686. rrddim_set_by_pointer(st_demand_data_hits_rate, rd_demand_data_hits_rate, arcstats.demand_data_hits);
  687. rrddim_set_by_pointer(st_demand_data_hits_rate, rd_demand_data_misses_rate, arcstats.demand_data_misses);
  688. rrdset_done(st_demand_data_hits_rate);
  689. }
  690. // --------------------------------------------------------------------
  691. if(likely(do_prefetch_data_hits == CONFIG_BOOLEAN_YES || arcstats.prefetch_data_hits \
  692. || arcstats.prefetch_data_misses)) {
  693. do_prefetch_data_hits = CONFIG_BOOLEAN_YES;
  694. static RRDSET *st_prefetch_data_hits = NULL;
  695. static RRDDIM *rd_prefetch_data_hits = NULL;
  696. static RRDDIM *rd_prefetch_data_misses = NULL;
  697. if (unlikely(!st_prefetch_data_hits)) {
  698. st_prefetch_data_hits = rrdset_create_localhost(
  699. "zfs"
  700. , "prefetch_data_hits"
  701. , NULL
  702. , ZFS_FAMILY_EFFICIENCY
  703. , NULL
  704. , "ZFS Data Prefetch Efficiency"
  705. , "percentage"
  706. , plugin
  707. , module
  708. , NETDATA_CHART_PRIO_ZFS_PREFETCH_DATA_HITS
  709. , update_every
  710. , RRDSET_TYPE_STACKED
  711. );
  712. rd_prefetch_data_hits = rrddim_add(st_prefetch_data_hits, "hits", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  713. rd_prefetch_data_misses = rrddim_add(st_prefetch_data_hits, "misses", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
  714. }
  715. rrddim_set_by_pointer(st_prefetch_data_hits, rd_prefetch_data_hits, arcstats.prefetch_data_hits);
  716. rrddim_set_by_pointer(st_prefetch_data_hits, rd_prefetch_data_misses, arcstats.prefetch_data_misses);
  717. rrdset_done(st_prefetch_data_hits);
  718. static RRDSET *st_prefetch_data_hits_rate = NULL;
  719. static RRDDIM *rd_prefetch_data_hits_rate = NULL;
  720. static RRDDIM *rd_prefetch_data_misses_rate = NULL;
  721. if (unlikely(!st_prefetch_data_hits_rate)) {
  722. st_prefetch_data_hits_rate = rrdset_create_localhost(
  723. "zfs"
  724. , "prefetch_data_hits_rate"
  725. , NULL
  726. , ZFS_FAMILY_EFFICIENCY
  727. , NULL
  728. , "ZFS Data Prefetch Efficiency Rate"
  729. , "events/s"
  730. , plugin
  731. , module
  732. , NETDATA_CHART_PRIO_ZFS_PREFETCH_DATA_HITS + 1
  733. , update_every
  734. , RRDSET_TYPE_STACKED
  735. );
  736. rd_prefetch_data_hits_rate = rrddim_add(st_prefetch_data_hits_rate, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  737. rd_prefetch_data_misses_rate = rrddim_add(st_prefetch_data_hits_rate, "misses", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  738. }
  739. rrddim_set_by_pointer(st_prefetch_data_hits_rate, rd_prefetch_data_hits_rate, arcstats.prefetch_data_hits);
  740. rrddim_set_by_pointer(st_prefetch_data_hits_rate, rd_prefetch_data_misses_rate, arcstats.prefetch_data_misses);
  741. rrdset_done(st_prefetch_data_hits_rate);
  742. }
  743. // --------------------------------------------------------------------
  744. if(likely(do_hash_elements == CONFIG_BOOLEAN_YES || arcstats.hash_elements || arcstats.hash_elements_max)) {
  745. do_hash_elements = CONFIG_BOOLEAN_YES;
  746. static RRDSET *st_hash_elements = NULL;
  747. static RRDDIM *rd_hash_elements_current = NULL;
  748. static RRDDIM *rd_hash_elements_max = NULL;
  749. if (unlikely(!st_hash_elements)) {
  750. st_hash_elements = rrdset_create_localhost(
  751. "zfs"
  752. , "hash_elements"
  753. , NULL
  754. , ZFS_FAMILY_HASH
  755. , NULL
  756. , "ZFS ARC Hash Elements"
  757. , "elements"
  758. , plugin
  759. , module
  760. , NETDATA_CHART_PRIO_ZFS_HASH_ELEMENTS
  761. , update_every
  762. , RRDSET_TYPE_LINE
  763. );
  764. rd_hash_elements_current = rrddim_add(st_hash_elements, "current", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  765. rd_hash_elements_max = rrddim_add(st_hash_elements, "max", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  766. }
  767. rrddim_set_by_pointer(st_hash_elements, rd_hash_elements_current, arcstats.hash_elements);
  768. rrddim_set_by_pointer(st_hash_elements, rd_hash_elements_max, arcstats.hash_elements_max);
  769. rrdset_done(st_hash_elements);
  770. }
  771. // --------------------------------------------------------------------
  772. if(likely(do_hash_chains == CONFIG_BOOLEAN_YES || arcstats.hash_chains || arcstats.hash_chain_max)) {
  773. do_hash_chains = CONFIG_BOOLEAN_YES;
  774. static RRDSET *st_hash_chains = NULL;
  775. static RRDDIM *rd_hash_chains_current = NULL;
  776. static RRDDIM *rd_hash_chains_max = NULL;
  777. if (unlikely(!st_hash_chains)) {
  778. st_hash_chains = rrdset_create_localhost(
  779. "zfs"
  780. , "hash_chains"
  781. , NULL
  782. , ZFS_FAMILY_HASH
  783. , NULL
  784. , "ZFS ARC Hash Chains"
  785. , "chains"
  786. , plugin
  787. , module
  788. , NETDATA_CHART_PRIO_ZFS_HASH_CHAINS
  789. , update_every
  790. , RRDSET_TYPE_LINE
  791. );
  792. rd_hash_chains_current = rrddim_add(st_hash_chains, "current", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  793. rd_hash_chains_max = rrddim_add(st_hash_chains, "max", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
  794. }
  795. rrddim_set_by_pointer(st_hash_chains, rd_hash_chains_current, arcstats.hash_chains);
  796. rrddim_set_by_pointer(st_hash_chains, rd_hash_chains_max, arcstats.hash_chain_max);
  797. rrdset_done(st_hash_chains);
  798. }
  799. // --------------------------------------------------------------------
  800. }