generated_metrics.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. // Code generated by mdatagen. DO NOT EDIT.
  2. package metadata
  3. import (
  4. "time"
  5. "go.opentelemetry.io/collector/component"
  6. "go.opentelemetry.io/collector/pdata/pcommon"
  7. "go.opentelemetry.io/collector/pdata/pmetric"
  8. "go.opentelemetry.io/collector/receiver"
  9. )
  10. // AttributeDirection specifies the a value direction attribute.
  11. type AttributeDirection int
  12. const (
  13. _ AttributeDirection = iota
  14. AttributeDirectionReceived
  15. AttributeDirectionSent
  16. )
  17. // String returns the string representation of the AttributeDirection.
  18. func (av AttributeDirection) String() string {
  19. switch av {
  20. case AttributeDirectionReceived:
  21. return "received"
  22. case AttributeDirectionSent:
  23. return "sent"
  24. }
  25. return ""
  26. }
  27. // MapAttributeDirection is a helper map of string to AttributeDirection attribute value.
  28. var MapAttributeDirection = map[string]AttributeDirection{
  29. "received": AttributeDirectionReceived,
  30. "sent": AttributeDirectionSent,
  31. }
  32. // AttributeState specifies the a value state attribute.
  33. type AttributeState int
  34. const (
  35. _ AttributeState = iota
  36. AttributeStateSynced
  37. AttributeStateUnsynced
  38. )
  39. // String returns the string representation of the AttributeState.
  40. func (av AttributeState) String() string {
  41. switch av {
  42. case AttributeStateSynced:
  43. return "synced"
  44. case AttributeStateUnsynced:
  45. return "unsynced"
  46. }
  47. return ""
  48. }
  49. // MapAttributeState is a helper map of string to AttributeState attribute value.
  50. var MapAttributeState = map[string]AttributeState{
  51. "synced": AttributeStateSynced,
  52. "unsynced": AttributeStateUnsynced,
  53. }
  54. type metricZookeeperConnectionActive struct {
  55. data pmetric.Metric // data buffer for generated metric.
  56. config MetricConfig // metric config provided by user.
  57. capacity int // max observed number of data points added to the metric.
  58. }
  59. // init fills zookeeper.connection.active metric with initial data.
  60. func (m *metricZookeeperConnectionActive) init() {
  61. m.data.SetName("zookeeper.connection.active")
  62. m.data.SetDescription("Number of active clients connected to a ZooKeeper server.")
  63. m.data.SetUnit("{connections}")
  64. m.data.SetEmptySum()
  65. m.data.Sum().SetIsMonotonic(false)
  66. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  67. }
  68. func (m *metricZookeeperConnectionActive) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  69. if !m.config.Enabled {
  70. return
  71. }
  72. dp := m.data.Sum().DataPoints().AppendEmpty()
  73. dp.SetStartTimestamp(start)
  74. dp.SetTimestamp(ts)
  75. dp.SetIntValue(val)
  76. }
  77. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  78. func (m *metricZookeeperConnectionActive) updateCapacity() {
  79. if m.data.Sum().DataPoints().Len() > m.capacity {
  80. m.capacity = m.data.Sum().DataPoints().Len()
  81. }
  82. }
  83. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  84. func (m *metricZookeeperConnectionActive) emit(metrics pmetric.MetricSlice) {
  85. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  86. m.updateCapacity()
  87. m.data.MoveTo(metrics.AppendEmpty())
  88. m.init()
  89. }
  90. }
  91. func newMetricZookeeperConnectionActive(cfg MetricConfig) metricZookeeperConnectionActive {
  92. m := metricZookeeperConnectionActive{config: cfg}
  93. if cfg.Enabled {
  94. m.data = pmetric.NewMetric()
  95. m.init()
  96. }
  97. return m
  98. }
  99. type metricZookeeperDataTreeEphemeralNodeCount struct {
  100. data pmetric.Metric // data buffer for generated metric.
  101. config MetricConfig // metric config provided by user.
  102. capacity int // max observed number of data points added to the metric.
  103. }
  104. // init fills zookeeper.data_tree.ephemeral_node.count metric with initial data.
  105. func (m *metricZookeeperDataTreeEphemeralNodeCount) init() {
  106. m.data.SetName("zookeeper.data_tree.ephemeral_node.count")
  107. m.data.SetDescription("Number of ephemeral nodes that a ZooKeeper server has in its data tree.")
  108. m.data.SetUnit("{nodes}")
  109. m.data.SetEmptySum()
  110. m.data.Sum().SetIsMonotonic(false)
  111. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  112. }
  113. func (m *metricZookeeperDataTreeEphemeralNodeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  114. if !m.config.Enabled {
  115. return
  116. }
  117. dp := m.data.Sum().DataPoints().AppendEmpty()
  118. dp.SetStartTimestamp(start)
  119. dp.SetTimestamp(ts)
  120. dp.SetIntValue(val)
  121. }
  122. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  123. func (m *metricZookeeperDataTreeEphemeralNodeCount) updateCapacity() {
  124. if m.data.Sum().DataPoints().Len() > m.capacity {
  125. m.capacity = m.data.Sum().DataPoints().Len()
  126. }
  127. }
  128. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  129. func (m *metricZookeeperDataTreeEphemeralNodeCount) emit(metrics pmetric.MetricSlice) {
  130. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  131. m.updateCapacity()
  132. m.data.MoveTo(metrics.AppendEmpty())
  133. m.init()
  134. }
  135. }
  136. func newMetricZookeeperDataTreeEphemeralNodeCount(cfg MetricConfig) metricZookeeperDataTreeEphemeralNodeCount {
  137. m := metricZookeeperDataTreeEphemeralNodeCount{config: cfg}
  138. if cfg.Enabled {
  139. m.data = pmetric.NewMetric()
  140. m.init()
  141. }
  142. return m
  143. }
  144. type metricZookeeperDataTreeSize struct {
  145. data pmetric.Metric // data buffer for generated metric.
  146. config MetricConfig // metric config provided by user.
  147. capacity int // max observed number of data points added to the metric.
  148. }
  149. // init fills zookeeper.data_tree.size metric with initial data.
  150. func (m *metricZookeeperDataTreeSize) init() {
  151. m.data.SetName("zookeeper.data_tree.size")
  152. m.data.SetDescription("Size of data in bytes that a ZooKeeper server has in its data tree.")
  153. m.data.SetUnit("By")
  154. m.data.SetEmptySum()
  155. m.data.Sum().SetIsMonotonic(false)
  156. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  157. }
  158. func (m *metricZookeeperDataTreeSize) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  159. if !m.config.Enabled {
  160. return
  161. }
  162. dp := m.data.Sum().DataPoints().AppendEmpty()
  163. dp.SetStartTimestamp(start)
  164. dp.SetTimestamp(ts)
  165. dp.SetIntValue(val)
  166. }
  167. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  168. func (m *metricZookeeperDataTreeSize) updateCapacity() {
  169. if m.data.Sum().DataPoints().Len() > m.capacity {
  170. m.capacity = m.data.Sum().DataPoints().Len()
  171. }
  172. }
  173. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  174. func (m *metricZookeeperDataTreeSize) emit(metrics pmetric.MetricSlice) {
  175. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  176. m.updateCapacity()
  177. m.data.MoveTo(metrics.AppendEmpty())
  178. m.init()
  179. }
  180. }
  181. func newMetricZookeeperDataTreeSize(cfg MetricConfig) metricZookeeperDataTreeSize {
  182. m := metricZookeeperDataTreeSize{config: cfg}
  183. if cfg.Enabled {
  184. m.data = pmetric.NewMetric()
  185. m.init()
  186. }
  187. return m
  188. }
  189. type metricZookeeperFileDescriptorLimit struct {
  190. data pmetric.Metric // data buffer for generated metric.
  191. config MetricConfig // metric config provided by user.
  192. capacity int // max observed number of data points added to the metric.
  193. }
  194. // init fills zookeeper.file_descriptor.limit metric with initial data.
  195. func (m *metricZookeeperFileDescriptorLimit) init() {
  196. m.data.SetName("zookeeper.file_descriptor.limit")
  197. m.data.SetDescription("Maximum number of file descriptors that a ZooKeeper server can open.")
  198. m.data.SetUnit("{file_descriptors}")
  199. m.data.SetEmptyGauge()
  200. }
  201. func (m *metricZookeeperFileDescriptorLimit) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  202. if !m.config.Enabled {
  203. return
  204. }
  205. dp := m.data.Gauge().DataPoints().AppendEmpty()
  206. dp.SetStartTimestamp(start)
  207. dp.SetTimestamp(ts)
  208. dp.SetIntValue(val)
  209. }
  210. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  211. func (m *metricZookeeperFileDescriptorLimit) updateCapacity() {
  212. if m.data.Gauge().DataPoints().Len() > m.capacity {
  213. m.capacity = m.data.Gauge().DataPoints().Len()
  214. }
  215. }
  216. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  217. func (m *metricZookeeperFileDescriptorLimit) emit(metrics pmetric.MetricSlice) {
  218. if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 {
  219. m.updateCapacity()
  220. m.data.MoveTo(metrics.AppendEmpty())
  221. m.init()
  222. }
  223. }
  224. func newMetricZookeeperFileDescriptorLimit(cfg MetricConfig) metricZookeeperFileDescriptorLimit {
  225. m := metricZookeeperFileDescriptorLimit{config: cfg}
  226. if cfg.Enabled {
  227. m.data = pmetric.NewMetric()
  228. m.init()
  229. }
  230. return m
  231. }
  232. type metricZookeeperFileDescriptorOpen struct {
  233. data pmetric.Metric // data buffer for generated metric.
  234. config MetricConfig // metric config provided by user.
  235. capacity int // max observed number of data points added to the metric.
  236. }
  237. // init fills zookeeper.file_descriptor.open metric with initial data.
  238. func (m *metricZookeeperFileDescriptorOpen) init() {
  239. m.data.SetName("zookeeper.file_descriptor.open")
  240. m.data.SetDescription("Number of file descriptors that a ZooKeeper server has open.")
  241. m.data.SetUnit("{file_descriptors}")
  242. m.data.SetEmptySum()
  243. m.data.Sum().SetIsMonotonic(false)
  244. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  245. }
  246. func (m *metricZookeeperFileDescriptorOpen) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  247. if !m.config.Enabled {
  248. return
  249. }
  250. dp := m.data.Sum().DataPoints().AppendEmpty()
  251. dp.SetStartTimestamp(start)
  252. dp.SetTimestamp(ts)
  253. dp.SetIntValue(val)
  254. }
  255. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  256. func (m *metricZookeeperFileDescriptorOpen) updateCapacity() {
  257. if m.data.Sum().DataPoints().Len() > m.capacity {
  258. m.capacity = m.data.Sum().DataPoints().Len()
  259. }
  260. }
  261. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  262. func (m *metricZookeeperFileDescriptorOpen) emit(metrics pmetric.MetricSlice) {
  263. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  264. m.updateCapacity()
  265. m.data.MoveTo(metrics.AppendEmpty())
  266. m.init()
  267. }
  268. }
  269. func newMetricZookeeperFileDescriptorOpen(cfg MetricConfig) metricZookeeperFileDescriptorOpen {
  270. m := metricZookeeperFileDescriptorOpen{config: cfg}
  271. if cfg.Enabled {
  272. m.data = pmetric.NewMetric()
  273. m.init()
  274. }
  275. return m
  276. }
  277. type metricZookeeperFollowerCount struct {
  278. data pmetric.Metric // data buffer for generated metric.
  279. config MetricConfig // metric config provided by user.
  280. capacity int // max observed number of data points added to the metric.
  281. }
  282. // init fills zookeeper.follower.count metric with initial data.
  283. func (m *metricZookeeperFollowerCount) init() {
  284. m.data.SetName("zookeeper.follower.count")
  285. m.data.SetDescription("The number of followers. Only exposed by the leader.")
  286. m.data.SetUnit("{followers}")
  287. m.data.SetEmptySum()
  288. m.data.Sum().SetIsMonotonic(false)
  289. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  290. m.data.Sum().DataPoints().EnsureCapacity(m.capacity)
  291. }
  292. func (m *metricZookeeperFollowerCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, stateAttributeValue string) {
  293. if !m.config.Enabled {
  294. return
  295. }
  296. dp := m.data.Sum().DataPoints().AppendEmpty()
  297. dp.SetStartTimestamp(start)
  298. dp.SetTimestamp(ts)
  299. dp.SetIntValue(val)
  300. dp.Attributes().PutStr("state", stateAttributeValue)
  301. }
  302. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  303. func (m *metricZookeeperFollowerCount) updateCapacity() {
  304. if m.data.Sum().DataPoints().Len() > m.capacity {
  305. m.capacity = m.data.Sum().DataPoints().Len()
  306. }
  307. }
  308. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  309. func (m *metricZookeeperFollowerCount) emit(metrics pmetric.MetricSlice) {
  310. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  311. m.updateCapacity()
  312. m.data.MoveTo(metrics.AppendEmpty())
  313. m.init()
  314. }
  315. }
  316. func newMetricZookeeperFollowerCount(cfg MetricConfig) metricZookeeperFollowerCount {
  317. m := metricZookeeperFollowerCount{config: cfg}
  318. if cfg.Enabled {
  319. m.data = pmetric.NewMetric()
  320. m.init()
  321. }
  322. return m
  323. }
  324. type metricZookeeperFsyncExceededThresholdCount struct {
  325. data pmetric.Metric // data buffer for generated metric.
  326. config MetricConfig // metric config provided by user.
  327. capacity int // max observed number of data points added to the metric.
  328. }
  329. // init fills zookeeper.fsync.exceeded_threshold.count metric with initial data.
  330. func (m *metricZookeeperFsyncExceededThresholdCount) init() {
  331. m.data.SetName("zookeeper.fsync.exceeded_threshold.count")
  332. m.data.SetDescription("Number of times fsync duration has exceeded warning threshold.")
  333. m.data.SetUnit("{events}")
  334. m.data.SetEmptySum()
  335. m.data.Sum().SetIsMonotonic(true)
  336. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  337. }
  338. func (m *metricZookeeperFsyncExceededThresholdCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  339. if !m.config.Enabled {
  340. return
  341. }
  342. dp := m.data.Sum().DataPoints().AppendEmpty()
  343. dp.SetStartTimestamp(start)
  344. dp.SetTimestamp(ts)
  345. dp.SetIntValue(val)
  346. }
  347. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  348. func (m *metricZookeeperFsyncExceededThresholdCount) updateCapacity() {
  349. if m.data.Sum().DataPoints().Len() > m.capacity {
  350. m.capacity = m.data.Sum().DataPoints().Len()
  351. }
  352. }
  353. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  354. func (m *metricZookeeperFsyncExceededThresholdCount) emit(metrics pmetric.MetricSlice) {
  355. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  356. m.updateCapacity()
  357. m.data.MoveTo(metrics.AppendEmpty())
  358. m.init()
  359. }
  360. }
  361. func newMetricZookeeperFsyncExceededThresholdCount(cfg MetricConfig) metricZookeeperFsyncExceededThresholdCount {
  362. m := metricZookeeperFsyncExceededThresholdCount{config: cfg}
  363. if cfg.Enabled {
  364. m.data = pmetric.NewMetric()
  365. m.init()
  366. }
  367. return m
  368. }
  369. type metricZookeeperLatencyAvg struct {
  370. data pmetric.Metric // data buffer for generated metric.
  371. config MetricConfig // metric config provided by user.
  372. capacity int // max observed number of data points added to the metric.
  373. }
  374. // init fills zookeeper.latency.avg metric with initial data.
  375. func (m *metricZookeeperLatencyAvg) init() {
  376. m.data.SetName("zookeeper.latency.avg")
  377. m.data.SetDescription("Average time in milliseconds for requests to be processed.")
  378. m.data.SetUnit("ms")
  379. m.data.SetEmptyGauge()
  380. }
  381. func (m *metricZookeeperLatencyAvg) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  382. if !m.config.Enabled {
  383. return
  384. }
  385. dp := m.data.Gauge().DataPoints().AppendEmpty()
  386. dp.SetStartTimestamp(start)
  387. dp.SetTimestamp(ts)
  388. dp.SetIntValue(val)
  389. }
  390. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  391. func (m *metricZookeeperLatencyAvg) updateCapacity() {
  392. if m.data.Gauge().DataPoints().Len() > m.capacity {
  393. m.capacity = m.data.Gauge().DataPoints().Len()
  394. }
  395. }
  396. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  397. func (m *metricZookeeperLatencyAvg) emit(metrics pmetric.MetricSlice) {
  398. if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 {
  399. m.updateCapacity()
  400. m.data.MoveTo(metrics.AppendEmpty())
  401. m.init()
  402. }
  403. }
  404. func newMetricZookeeperLatencyAvg(cfg MetricConfig) metricZookeeperLatencyAvg {
  405. m := metricZookeeperLatencyAvg{config: cfg}
  406. if cfg.Enabled {
  407. m.data = pmetric.NewMetric()
  408. m.init()
  409. }
  410. return m
  411. }
  412. type metricZookeeperLatencyMax struct {
  413. data pmetric.Metric // data buffer for generated metric.
  414. config MetricConfig // metric config provided by user.
  415. capacity int // max observed number of data points added to the metric.
  416. }
  417. // init fills zookeeper.latency.max metric with initial data.
  418. func (m *metricZookeeperLatencyMax) init() {
  419. m.data.SetName("zookeeper.latency.max")
  420. m.data.SetDescription("Maximum time in milliseconds for requests to be processed.")
  421. m.data.SetUnit("ms")
  422. m.data.SetEmptyGauge()
  423. }
  424. func (m *metricZookeeperLatencyMax) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  425. if !m.config.Enabled {
  426. return
  427. }
  428. dp := m.data.Gauge().DataPoints().AppendEmpty()
  429. dp.SetStartTimestamp(start)
  430. dp.SetTimestamp(ts)
  431. dp.SetIntValue(val)
  432. }
  433. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  434. func (m *metricZookeeperLatencyMax) updateCapacity() {
  435. if m.data.Gauge().DataPoints().Len() > m.capacity {
  436. m.capacity = m.data.Gauge().DataPoints().Len()
  437. }
  438. }
  439. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  440. func (m *metricZookeeperLatencyMax) emit(metrics pmetric.MetricSlice) {
  441. if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 {
  442. m.updateCapacity()
  443. m.data.MoveTo(metrics.AppendEmpty())
  444. m.init()
  445. }
  446. }
  447. func newMetricZookeeperLatencyMax(cfg MetricConfig) metricZookeeperLatencyMax {
  448. m := metricZookeeperLatencyMax{config: cfg}
  449. if cfg.Enabled {
  450. m.data = pmetric.NewMetric()
  451. m.init()
  452. }
  453. return m
  454. }
  455. type metricZookeeperLatencyMin struct {
  456. data pmetric.Metric // data buffer for generated metric.
  457. config MetricConfig // metric config provided by user.
  458. capacity int // max observed number of data points added to the metric.
  459. }
  460. // init fills zookeeper.latency.min metric with initial data.
  461. func (m *metricZookeeperLatencyMin) init() {
  462. m.data.SetName("zookeeper.latency.min")
  463. m.data.SetDescription("Minimum time in milliseconds for requests to be processed.")
  464. m.data.SetUnit("ms")
  465. m.data.SetEmptyGauge()
  466. }
  467. func (m *metricZookeeperLatencyMin) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  468. if !m.config.Enabled {
  469. return
  470. }
  471. dp := m.data.Gauge().DataPoints().AppendEmpty()
  472. dp.SetStartTimestamp(start)
  473. dp.SetTimestamp(ts)
  474. dp.SetIntValue(val)
  475. }
  476. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  477. func (m *metricZookeeperLatencyMin) updateCapacity() {
  478. if m.data.Gauge().DataPoints().Len() > m.capacity {
  479. m.capacity = m.data.Gauge().DataPoints().Len()
  480. }
  481. }
  482. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  483. func (m *metricZookeeperLatencyMin) emit(metrics pmetric.MetricSlice) {
  484. if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 {
  485. m.updateCapacity()
  486. m.data.MoveTo(metrics.AppendEmpty())
  487. m.init()
  488. }
  489. }
  490. func newMetricZookeeperLatencyMin(cfg MetricConfig) metricZookeeperLatencyMin {
  491. m := metricZookeeperLatencyMin{config: cfg}
  492. if cfg.Enabled {
  493. m.data = pmetric.NewMetric()
  494. m.init()
  495. }
  496. return m
  497. }
  498. type metricZookeeperPacketCount struct {
  499. data pmetric.Metric // data buffer for generated metric.
  500. config MetricConfig // metric config provided by user.
  501. capacity int // max observed number of data points added to the metric.
  502. }
  503. // init fills zookeeper.packet.count metric with initial data.
  504. func (m *metricZookeeperPacketCount) init() {
  505. m.data.SetName("zookeeper.packet.count")
  506. m.data.SetDescription("The number of ZooKeeper packets received or sent by a server.")
  507. m.data.SetUnit("{packets}")
  508. m.data.SetEmptySum()
  509. m.data.Sum().SetIsMonotonic(true)
  510. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  511. m.data.Sum().DataPoints().EnsureCapacity(m.capacity)
  512. }
  513. func (m *metricZookeeperPacketCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, directionAttributeValue string) {
  514. if !m.config.Enabled {
  515. return
  516. }
  517. dp := m.data.Sum().DataPoints().AppendEmpty()
  518. dp.SetStartTimestamp(start)
  519. dp.SetTimestamp(ts)
  520. dp.SetIntValue(val)
  521. dp.Attributes().PutStr("direction", directionAttributeValue)
  522. }
  523. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  524. func (m *metricZookeeperPacketCount) updateCapacity() {
  525. if m.data.Sum().DataPoints().Len() > m.capacity {
  526. m.capacity = m.data.Sum().DataPoints().Len()
  527. }
  528. }
  529. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  530. func (m *metricZookeeperPacketCount) emit(metrics pmetric.MetricSlice) {
  531. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  532. m.updateCapacity()
  533. m.data.MoveTo(metrics.AppendEmpty())
  534. m.init()
  535. }
  536. }
  537. func newMetricZookeeperPacketCount(cfg MetricConfig) metricZookeeperPacketCount {
  538. m := metricZookeeperPacketCount{config: cfg}
  539. if cfg.Enabled {
  540. m.data = pmetric.NewMetric()
  541. m.init()
  542. }
  543. return m
  544. }
  545. type metricZookeeperRequestActive struct {
  546. data pmetric.Metric // data buffer for generated metric.
  547. config MetricConfig // metric config provided by user.
  548. capacity int // max observed number of data points added to the metric.
  549. }
  550. // init fills zookeeper.request.active metric with initial data.
  551. func (m *metricZookeeperRequestActive) init() {
  552. m.data.SetName("zookeeper.request.active")
  553. m.data.SetDescription("Number of currently executing requests.")
  554. m.data.SetUnit("{requests}")
  555. m.data.SetEmptySum()
  556. m.data.Sum().SetIsMonotonic(false)
  557. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  558. }
  559. func (m *metricZookeeperRequestActive) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  560. if !m.config.Enabled {
  561. return
  562. }
  563. dp := m.data.Sum().DataPoints().AppendEmpty()
  564. dp.SetStartTimestamp(start)
  565. dp.SetTimestamp(ts)
  566. dp.SetIntValue(val)
  567. }
  568. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  569. func (m *metricZookeeperRequestActive) updateCapacity() {
  570. if m.data.Sum().DataPoints().Len() > m.capacity {
  571. m.capacity = m.data.Sum().DataPoints().Len()
  572. }
  573. }
  574. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  575. func (m *metricZookeeperRequestActive) emit(metrics pmetric.MetricSlice) {
  576. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  577. m.updateCapacity()
  578. m.data.MoveTo(metrics.AppendEmpty())
  579. m.init()
  580. }
  581. }
  582. func newMetricZookeeperRequestActive(cfg MetricConfig) metricZookeeperRequestActive {
  583. m := metricZookeeperRequestActive{config: cfg}
  584. if cfg.Enabled {
  585. m.data = pmetric.NewMetric()
  586. m.init()
  587. }
  588. return m
  589. }
  590. type metricZookeeperRuok struct {
  591. data pmetric.Metric // data buffer for generated metric.
  592. config MetricConfig // metric config provided by user.
  593. capacity int // max observed number of data points added to the metric.
  594. }
  595. // init fills zookeeper.ruok metric with initial data.
  596. func (m *metricZookeeperRuok) init() {
  597. m.data.SetName("zookeeper.ruok")
  598. m.data.SetDescription("Response from zookeeper ruok command")
  599. m.data.SetUnit("1")
  600. m.data.SetEmptyGauge()
  601. }
  602. func (m *metricZookeeperRuok) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  603. if !m.config.Enabled {
  604. return
  605. }
  606. dp := m.data.Gauge().DataPoints().AppendEmpty()
  607. dp.SetStartTimestamp(start)
  608. dp.SetTimestamp(ts)
  609. dp.SetIntValue(val)
  610. }
  611. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  612. func (m *metricZookeeperRuok) updateCapacity() {
  613. if m.data.Gauge().DataPoints().Len() > m.capacity {
  614. m.capacity = m.data.Gauge().DataPoints().Len()
  615. }
  616. }
  617. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  618. func (m *metricZookeeperRuok) emit(metrics pmetric.MetricSlice) {
  619. if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 {
  620. m.updateCapacity()
  621. m.data.MoveTo(metrics.AppendEmpty())
  622. m.init()
  623. }
  624. }
  625. func newMetricZookeeperRuok(cfg MetricConfig) metricZookeeperRuok {
  626. m := metricZookeeperRuok{config: cfg}
  627. if cfg.Enabled {
  628. m.data = pmetric.NewMetric()
  629. m.init()
  630. }
  631. return m
  632. }
  633. type metricZookeeperSyncPending struct {
  634. data pmetric.Metric // data buffer for generated metric.
  635. config MetricConfig // metric config provided by user.
  636. capacity int // max observed number of data points added to the metric.
  637. }
  638. // init fills zookeeper.sync.pending metric with initial data.
  639. func (m *metricZookeeperSyncPending) init() {
  640. m.data.SetName("zookeeper.sync.pending")
  641. m.data.SetDescription("The number of pending syncs from the followers. Only exposed by the leader.")
  642. m.data.SetUnit("{syncs}")
  643. m.data.SetEmptySum()
  644. m.data.Sum().SetIsMonotonic(false)
  645. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  646. }
  647. func (m *metricZookeeperSyncPending) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  648. if !m.config.Enabled {
  649. return
  650. }
  651. dp := m.data.Sum().DataPoints().AppendEmpty()
  652. dp.SetStartTimestamp(start)
  653. dp.SetTimestamp(ts)
  654. dp.SetIntValue(val)
  655. }
  656. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  657. func (m *metricZookeeperSyncPending) updateCapacity() {
  658. if m.data.Sum().DataPoints().Len() > m.capacity {
  659. m.capacity = m.data.Sum().DataPoints().Len()
  660. }
  661. }
  662. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  663. func (m *metricZookeeperSyncPending) emit(metrics pmetric.MetricSlice) {
  664. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  665. m.updateCapacity()
  666. m.data.MoveTo(metrics.AppendEmpty())
  667. m.init()
  668. }
  669. }
  670. func newMetricZookeeperSyncPending(cfg MetricConfig) metricZookeeperSyncPending {
  671. m := metricZookeeperSyncPending{config: cfg}
  672. if cfg.Enabled {
  673. m.data = pmetric.NewMetric()
  674. m.init()
  675. }
  676. return m
  677. }
  678. type metricZookeeperWatchCount struct {
  679. data pmetric.Metric // data buffer for generated metric.
  680. config MetricConfig // metric config provided by user.
  681. capacity int // max observed number of data points added to the metric.
  682. }
  683. // init fills zookeeper.watch.count metric with initial data.
  684. func (m *metricZookeeperWatchCount) init() {
  685. m.data.SetName("zookeeper.watch.count")
  686. m.data.SetDescription("Number of watches placed on Z-Nodes on a ZooKeeper server.")
  687. m.data.SetUnit("{watches}")
  688. m.data.SetEmptySum()
  689. m.data.Sum().SetIsMonotonic(false)
  690. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  691. }
  692. func (m *metricZookeeperWatchCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  693. if !m.config.Enabled {
  694. return
  695. }
  696. dp := m.data.Sum().DataPoints().AppendEmpty()
  697. dp.SetStartTimestamp(start)
  698. dp.SetTimestamp(ts)
  699. dp.SetIntValue(val)
  700. }
  701. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  702. func (m *metricZookeeperWatchCount) updateCapacity() {
  703. if m.data.Sum().DataPoints().Len() > m.capacity {
  704. m.capacity = m.data.Sum().DataPoints().Len()
  705. }
  706. }
  707. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  708. func (m *metricZookeeperWatchCount) emit(metrics pmetric.MetricSlice) {
  709. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  710. m.updateCapacity()
  711. m.data.MoveTo(metrics.AppendEmpty())
  712. m.init()
  713. }
  714. }
  715. func newMetricZookeeperWatchCount(cfg MetricConfig) metricZookeeperWatchCount {
  716. m := metricZookeeperWatchCount{config: cfg}
  717. if cfg.Enabled {
  718. m.data = pmetric.NewMetric()
  719. m.init()
  720. }
  721. return m
  722. }
  723. type metricZookeeperZnodeCount struct {
  724. data pmetric.Metric // data buffer for generated metric.
  725. config MetricConfig // metric config provided by user.
  726. capacity int // max observed number of data points added to the metric.
  727. }
  728. // init fills zookeeper.znode.count metric with initial data.
  729. func (m *metricZookeeperZnodeCount) init() {
  730. m.data.SetName("zookeeper.znode.count")
  731. m.data.SetDescription("Number of z-nodes that a ZooKeeper server has in its data tree.")
  732. m.data.SetUnit("{znodes}")
  733. m.data.SetEmptySum()
  734. m.data.Sum().SetIsMonotonic(false)
  735. m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
  736. }
  737. func (m *metricZookeeperZnodeCount) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) {
  738. if !m.config.Enabled {
  739. return
  740. }
  741. dp := m.data.Sum().DataPoints().AppendEmpty()
  742. dp.SetStartTimestamp(start)
  743. dp.SetTimestamp(ts)
  744. dp.SetIntValue(val)
  745. }
  746. // updateCapacity saves max length of data point slices that will be used for the slice capacity.
  747. func (m *metricZookeeperZnodeCount) updateCapacity() {
  748. if m.data.Sum().DataPoints().Len() > m.capacity {
  749. m.capacity = m.data.Sum().DataPoints().Len()
  750. }
  751. }
  752. // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points.
  753. func (m *metricZookeeperZnodeCount) emit(metrics pmetric.MetricSlice) {
  754. if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 {
  755. m.updateCapacity()
  756. m.data.MoveTo(metrics.AppendEmpty())
  757. m.init()
  758. }
  759. }
  760. func newMetricZookeeperZnodeCount(cfg MetricConfig) metricZookeeperZnodeCount {
  761. m := metricZookeeperZnodeCount{config: cfg}
  762. if cfg.Enabled {
  763. m.data = pmetric.NewMetric()
  764. m.init()
  765. }
  766. return m
  767. }
  768. // MetricsBuilder provides an interface for scrapers to report metrics while taking care of all the transformations
  769. // required to produce metric representation defined in metadata and user config.
  770. type MetricsBuilder struct {
  771. config MetricsBuilderConfig // config of the metrics builder.
  772. startTime pcommon.Timestamp // start time that will be applied to all recorded data points.
  773. metricsCapacity int // maximum observed number of metrics per resource.
  774. metricsBuffer pmetric.Metrics // accumulates metrics data before emitting.
  775. buildInfo component.BuildInfo // contains version information.
  776. metricZookeeperConnectionActive metricZookeeperConnectionActive
  777. metricZookeeperDataTreeEphemeralNodeCount metricZookeeperDataTreeEphemeralNodeCount
  778. metricZookeeperDataTreeSize metricZookeeperDataTreeSize
  779. metricZookeeperFileDescriptorLimit metricZookeeperFileDescriptorLimit
  780. metricZookeeperFileDescriptorOpen metricZookeeperFileDescriptorOpen
  781. metricZookeeperFollowerCount metricZookeeperFollowerCount
  782. metricZookeeperFsyncExceededThresholdCount metricZookeeperFsyncExceededThresholdCount
  783. metricZookeeperLatencyAvg metricZookeeperLatencyAvg
  784. metricZookeeperLatencyMax metricZookeeperLatencyMax
  785. metricZookeeperLatencyMin metricZookeeperLatencyMin
  786. metricZookeeperPacketCount metricZookeeperPacketCount
  787. metricZookeeperRequestActive metricZookeeperRequestActive
  788. metricZookeeperRuok metricZookeeperRuok
  789. metricZookeeperSyncPending metricZookeeperSyncPending
  790. metricZookeeperWatchCount metricZookeeperWatchCount
  791. metricZookeeperZnodeCount metricZookeeperZnodeCount
  792. }
  793. // metricBuilderOption applies changes to default metrics builder.
  794. type metricBuilderOption func(*MetricsBuilder)
  795. // WithStartTime sets startTime on the metrics builder.
  796. func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption {
  797. return func(mb *MetricsBuilder) {
  798. mb.startTime = startTime
  799. }
  800. }
  801. func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSettings, options ...metricBuilderOption) *MetricsBuilder {
  802. mb := &MetricsBuilder{
  803. config: mbc,
  804. startTime: pcommon.NewTimestampFromTime(time.Now()),
  805. metricsBuffer: pmetric.NewMetrics(),
  806. buildInfo: settings.BuildInfo,
  807. metricZookeeperConnectionActive: newMetricZookeeperConnectionActive(mbc.Metrics.ZookeeperConnectionActive),
  808. metricZookeeperDataTreeEphemeralNodeCount: newMetricZookeeperDataTreeEphemeralNodeCount(mbc.Metrics.ZookeeperDataTreeEphemeralNodeCount),
  809. metricZookeeperDataTreeSize: newMetricZookeeperDataTreeSize(mbc.Metrics.ZookeeperDataTreeSize),
  810. metricZookeeperFileDescriptorLimit: newMetricZookeeperFileDescriptorLimit(mbc.Metrics.ZookeeperFileDescriptorLimit),
  811. metricZookeeperFileDescriptorOpen: newMetricZookeeperFileDescriptorOpen(mbc.Metrics.ZookeeperFileDescriptorOpen),
  812. metricZookeeperFollowerCount: newMetricZookeeperFollowerCount(mbc.Metrics.ZookeeperFollowerCount),
  813. metricZookeeperFsyncExceededThresholdCount: newMetricZookeeperFsyncExceededThresholdCount(mbc.Metrics.ZookeeperFsyncExceededThresholdCount),
  814. metricZookeeperLatencyAvg: newMetricZookeeperLatencyAvg(mbc.Metrics.ZookeeperLatencyAvg),
  815. metricZookeeperLatencyMax: newMetricZookeeperLatencyMax(mbc.Metrics.ZookeeperLatencyMax),
  816. metricZookeeperLatencyMin: newMetricZookeeperLatencyMin(mbc.Metrics.ZookeeperLatencyMin),
  817. metricZookeeperPacketCount: newMetricZookeeperPacketCount(mbc.Metrics.ZookeeperPacketCount),
  818. metricZookeeperRequestActive: newMetricZookeeperRequestActive(mbc.Metrics.ZookeeperRequestActive),
  819. metricZookeeperRuok: newMetricZookeeperRuok(mbc.Metrics.ZookeeperRuok),
  820. metricZookeeperSyncPending: newMetricZookeeperSyncPending(mbc.Metrics.ZookeeperSyncPending),
  821. metricZookeeperWatchCount: newMetricZookeeperWatchCount(mbc.Metrics.ZookeeperWatchCount),
  822. metricZookeeperZnodeCount: newMetricZookeeperZnodeCount(mbc.Metrics.ZookeeperZnodeCount),
  823. }
  824. for _, op := range options {
  825. op(mb)
  826. }
  827. return mb
  828. }
  829. // NewResourceBuilder returns a new resource builder that should be used to build a resource associated with for the emitted metrics.
  830. func (mb *MetricsBuilder) NewResourceBuilder() *ResourceBuilder {
  831. return NewResourceBuilder(mb.config.ResourceAttributes)
  832. }
  833. // updateCapacity updates max length of metrics and resource attributes that will be used for the slice capacity.
  834. func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) {
  835. if mb.metricsCapacity < rm.ScopeMetrics().At(0).Metrics().Len() {
  836. mb.metricsCapacity = rm.ScopeMetrics().At(0).Metrics().Len()
  837. }
  838. }
  839. // ResourceMetricsOption applies changes to provided resource metrics.
  840. type ResourceMetricsOption func(pmetric.ResourceMetrics)
  841. // WithResource sets the provided resource on the emitted ResourceMetrics.
  842. // It's recommended to use ResourceBuilder to create the resource.
  843. func WithResource(res pcommon.Resource) ResourceMetricsOption {
  844. return func(rm pmetric.ResourceMetrics) {
  845. res.CopyTo(rm.Resource())
  846. }
  847. }
  848. // WithStartTimeOverride overrides start time for all the resource metrics data points.
  849. // This option should be only used if different start time has to be set on metrics coming from different resources.
  850. func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption {
  851. return func(rm pmetric.ResourceMetrics) {
  852. var dps pmetric.NumberDataPointSlice
  853. metrics := rm.ScopeMetrics().At(0).Metrics()
  854. for i := 0; i < metrics.Len(); i++ {
  855. switch metrics.At(i).Type() {
  856. case pmetric.MetricTypeGauge:
  857. dps = metrics.At(i).Gauge().DataPoints()
  858. case pmetric.MetricTypeSum:
  859. dps = metrics.At(i).Sum().DataPoints()
  860. }
  861. for j := 0; j < dps.Len(); j++ {
  862. dps.At(j).SetStartTimestamp(start)
  863. }
  864. }
  865. }
  866. }
  867. // EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for
  868. // recording another set of data points as part of another resource. This function can be helpful when one scraper
  869. // needs to emit metrics from several resources. Otherwise calling this function is not required,
  870. // just `Emit` function can be called instead.
  871. // Resource attributes should be provided as ResourceMetricsOption arguments.
  872. func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) {
  873. rm := pmetric.NewResourceMetrics()
  874. ils := rm.ScopeMetrics().AppendEmpty()
  875. ils.Scope().SetName("otelcol/zookeeperreceiver")
  876. ils.Scope().SetVersion(mb.buildInfo.Version)
  877. ils.Metrics().EnsureCapacity(mb.metricsCapacity)
  878. mb.metricZookeeperConnectionActive.emit(ils.Metrics())
  879. mb.metricZookeeperDataTreeEphemeralNodeCount.emit(ils.Metrics())
  880. mb.metricZookeeperDataTreeSize.emit(ils.Metrics())
  881. mb.metricZookeeperFileDescriptorLimit.emit(ils.Metrics())
  882. mb.metricZookeeperFileDescriptorOpen.emit(ils.Metrics())
  883. mb.metricZookeeperFollowerCount.emit(ils.Metrics())
  884. mb.metricZookeeperFsyncExceededThresholdCount.emit(ils.Metrics())
  885. mb.metricZookeeperLatencyAvg.emit(ils.Metrics())
  886. mb.metricZookeeperLatencyMax.emit(ils.Metrics())
  887. mb.metricZookeeperLatencyMin.emit(ils.Metrics())
  888. mb.metricZookeeperPacketCount.emit(ils.Metrics())
  889. mb.metricZookeeperRequestActive.emit(ils.Metrics())
  890. mb.metricZookeeperRuok.emit(ils.Metrics())
  891. mb.metricZookeeperSyncPending.emit(ils.Metrics())
  892. mb.metricZookeeperWatchCount.emit(ils.Metrics())
  893. mb.metricZookeeperZnodeCount.emit(ils.Metrics())
  894. for _, op := range rmo {
  895. op(rm)
  896. }
  897. if ils.Metrics().Len() > 0 {
  898. mb.updateCapacity(rm)
  899. rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty())
  900. }
  901. }
  902. // Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for
  903. // recording another set of metrics. This function will be responsible for applying all the transformations required to
  904. // produce metric representation defined in metadata and user config, e.g. delta or cumulative.
  905. func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics {
  906. mb.EmitForResource(rmo...)
  907. metrics := mb.metricsBuffer
  908. mb.metricsBuffer = pmetric.NewMetrics()
  909. return metrics
  910. }
  911. // RecordZookeeperConnectionActiveDataPoint adds a data point to zookeeper.connection.active metric.
  912. func (mb *MetricsBuilder) RecordZookeeperConnectionActiveDataPoint(ts pcommon.Timestamp, val int64) {
  913. mb.metricZookeeperConnectionActive.recordDataPoint(mb.startTime, ts, val)
  914. }
  915. // RecordZookeeperDataTreeEphemeralNodeCountDataPoint adds a data point to zookeeper.data_tree.ephemeral_node.count metric.
  916. func (mb *MetricsBuilder) RecordZookeeperDataTreeEphemeralNodeCountDataPoint(ts pcommon.Timestamp, val int64) {
  917. mb.metricZookeeperDataTreeEphemeralNodeCount.recordDataPoint(mb.startTime, ts, val)
  918. }
  919. // RecordZookeeperDataTreeSizeDataPoint adds a data point to zookeeper.data_tree.size metric.
  920. func (mb *MetricsBuilder) RecordZookeeperDataTreeSizeDataPoint(ts pcommon.Timestamp, val int64) {
  921. mb.metricZookeeperDataTreeSize.recordDataPoint(mb.startTime, ts, val)
  922. }
  923. // RecordZookeeperFileDescriptorLimitDataPoint adds a data point to zookeeper.file_descriptor.limit metric.
  924. func (mb *MetricsBuilder) RecordZookeeperFileDescriptorLimitDataPoint(ts pcommon.Timestamp, val int64) {
  925. mb.metricZookeeperFileDescriptorLimit.recordDataPoint(mb.startTime, ts, val)
  926. }
  927. // RecordZookeeperFileDescriptorOpenDataPoint adds a data point to zookeeper.file_descriptor.open metric.
  928. func (mb *MetricsBuilder) RecordZookeeperFileDescriptorOpenDataPoint(ts pcommon.Timestamp, val int64) {
  929. mb.metricZookeeperFileDescriptorOpen.recordDataPoint(mb.startTime, ts, val)
  930. }
  931. // RecordZookeeperFollowerCountDataPoint adds a data point to zookeeper.follower.count metric.
  932. func (mb *MetricsBuilder) RecordZookeeperFollowerCountDataPoint(ts pcommon.Timestamp, val int64, stateAttributeValue AttributeState) {
  933. mb.metricZookeeperFollowerCount.recordDataPoint(mb.startTime, ts, val, stateAttributeValue.String())
  934. }
  935. // RecordZookeeperFsyncExceededThresholdCountDataPoint adds a data point to zookeeper.fsync.exceeded_threshold.count metric.
  936. func (mb *MetricsBuilder) RecordZookeeperFsyncExceededThresholdCountDataPoint(ts pcommon.Timestamp, val int64) {
  937. mb.metricZookeeperFsyncExceededThresholdCount.recordDataPoint(mb.startTime, ts, val)
  938. }
  939. // RecordZookeeperLatencyAvgDataPoint adds a data point to zookeeper.latency.avg metric.
  940. func (mb *MetricsBuilder) RecordZookeeperLatencyAvgDataPoint(ts pcommon.Timestamp, val int64) {
  941. mb.metricZookeeperLatencyAvg.recordDataPoint(mb.startTime, ts, val)
  942. }
  943. // RecordZookeeperLatencyMaxDataPoint adds a data point to zookeeper.latency.max metric.
  944. func (mb *MetricsBuilder) RecordZookeeperLatencyMaxDataPoint(ts pcommon.Timestamp, val int64) {
  945. mb.metricZookeeperLatencyMax.recordDataPoint(mb.startTime, ts, val)
  946. }
  947. // RecordZookeeperLatencyMinDataPoint adds a data point to zookeeper.latency.min metric.
  948. func (mb *MetricsBuilder) RecordZookeeperLatencyMinDataPoint(ts pcommon.Timestamp, val int64) {
  949. mb.metricZookeeperLatencyMin.recordDataPoint(mb.startTime, ts, val)
  950. }
  951. // RecordZookeeperPacketCountDataPoint adds a data point to zookeeper.packet.count metric.
  952. func (mb *MetricsBuilder) RecordZookeeperPacketCountDataPoint(ts pcommon.Timestamp, val int64, directionAttributeValue AttributeDirection) {
  953. mb.metricZookeeperPacketCount.recordDataPoint(mb.startTime, ts, val, directionAttributeValue.String())
  954. }
  955. // RecordZookeeperRequestActiveDataPoint adds a data point to zookeeper.request.active metric.
  956. func (mb *MetricsBuilder) RecordZookeeperRequestActiveDataPoint(ts pcommon.Timestamp, val int64) {
  957. mb.metricZookeeperRequestActive.recordDataPoint(mb.startTime, ts, val)
  958. }
  959. // RecordZookeeperRuokDataPoint adds a data point to zookeeper.ruok metric.
  960. func (mb *MetricsBuilder) RecordZookeeperRuokDataPoint(ts pcommon.Timestamp, val int64) {
  961. mb.metricZookeeperRuok.recordDataPoint(mb.startTime, ts, val)
  962. }
  963. // RecordZookeeperSyncPendingDataPoint adds a data point to zookeeper.sync.pending metric.
  964. func (mb *MetricsBuilder) RecordZookeeperSyncPendingDataPoint(ts pcommon.Timestamp, val int64) {
  965. mb.metricZookeeperSyncPending.recordDataPoint(mb.startTime, ts, val)
  966. }
  967. // RecordZookeeperWatchCountDataPoint adds a data point to zookeeper.watch.count metric.
  968. func (mb *MetricsBuilder) RecordZookeeperWatchCountDataPoint(ts pcommon.Timestamp, val int64) {
  969. mb.metricZookeeperWatchCount.recordDataPoint(mb.startTime, ts, val)
  970. }
  971. // RecordZookeeperZnodeCountDataPoint adds a data point to zookeeper.znode.count metric.
  972. func (mb *MetricsBuilder) RecordZookeeperZnodeCountDataPoint(ts pcommon.Timestamp, val int64) {
  973. mb.metricZookeeperZnodeCount.recordDataPoint(mb.startTime, ts, val)
  974. }
  975. // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted,
  976. // and metrics builder should update its startTime and reset it's internal state accordingly.
  977. func (mb *MetricsBuilder) Reset(options ...metricBuilderOption) {
  978. mb.startTime = pcommon.NewTimestampFromTime(time.Now())
  979. for _, op := range options {
  980. op(mb)
  981. }
  982. }