master
go 103 lines 2.99 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package cassandra
4
5 // https://cassandra.apache.org/doc/latest/cassandra/operating/metrics.html#table-metrics
6 // https://www.datadoghq.com/blog/how-to-collect-cassandra-metrics/
7 // https://docs.opennms.com/horizon/29/deployment/time-series-storage/newts/cassandra-jmx.html
8
9 func newCassandraMetrics() *cassandraMetrics {
10 return &cassandraMetrics{
11 threadPools: make(map[string]*threadPoolMetrics),
12 }
13 }
14
15 type cassandraMetrics struct {
16 clientReqTotalLatencyReads metricValue
17 clientReqTotalLatencyWrites metricValue
18 clientReqLatencyReads metricValue
19 clientReqLatencyWrites metricValue
20 clientReqTimeoutsReads metricValue
21 clientReqTimeoutsWrites metricValue
22 clientReqUnavailablesReads metricValue
23 clientReqUnavailablesWrites metricValue
24 clientReqFailuresReads metricValue
25 clientReqFailuresWrites metricValue
26
27 clientReqReadLatencyP50 metricValue
28 clientReqReadLatencyP75 metricValue
29 clientReqReadLatencyP95 metricValue
30 clientReqReadLatencyP98 metricValue
31 clientReqReadLatencyP99 metricValue
32 clientReqReadLatencyP999 metricValue
33 clientReqWriteLatencyP50 metricValue
34 clientReqWriteLatencyP75 metricValue
35 clientReqWriteLatencyP95 metricValue
36 clientReqWriteLatencyP98 metricValue
37 clientReqWriteLatencyP99 metricValue
38 clientReqWriteLatencyP999 metricValue
39
40 rowCacheHits metricValue
41 rowCacheMisses metricValue
42 rowCacheCapacity metricValue
43 rowCacheSize metricValue
44 keyCacheHits metricValue
45 keyCacheMisses metricValue
46 keyCacheCapacity metricValue
47 keyCacheSize metricValue
48
49 // https://cassandra.apache.org/doc/latest/cassandra/operating/metrics.html#dropped-metrics
50 droppedMessages metricValue
51
52 // https://cassandra.apache.org/doc/latest/cassandra/operating/metrics.html#storage-metrics
53 storageLoad metricValue
54 storageExceptions metricValue
55
56 // https://cassandra.apache.org/doc/latest/cassandra/operating/metrics.html#compaction-metrics
57 compactionBytesCompacted metricValue
58 compactionPendingTasks metricValue
59 compactionCompletedTasks metricValue
60
61 // https://cassandra.apache.org/doc/latest/cassandra/operating/metrics.html#memory
62 jvmMemoryHeapUsed metricValue
63 jvmMemoryNonHeapUsed metricValue
64 // https://cassandra.apache.org/doc/latest/cassandra/operating/metrics.html#garbagecollector
65 jvmGCParNewCount metricValue
66 jvmGCParNewTime metricValue
67 jvmGCCMSCount metricValue
68 jvmGCCMSTime metricValue
69
70 threadPools map[string]*threadPoolMetrics
71 }
72
73 type threadPoolMetrics struct {
74 name string
75 hasCharts bool
76
77 activeTasks metricValue
78 pendingTasks metricValue
79 blockedTasks metricValue
80 totalBlockedTasks metricValue
81 }
82
83 type metricValue struct {
84 isSet bool
85 value float64
86 }
87
88 func (mv *metricValue) add(v float64) {
89 mv.isSet = true
90 mv.value += v
91 }
92
93 func (mv *metricValue) write(mx map[string]int64, key string) {
94 if mv.isSet {
95 mx[key] = int64(mv.value)
96 }
97 }
98
99 func (mv *metricValue) write1k(mx map[string]int64, key string) {
100 if mv.isSet {
101 mx[key] = int64(mv.value * 1000)
102 }
103 }