Skip to content

Commit 9439462

Browse files
committed
Update stats structs to support ES 2.0; Add Thread Pool stats
* Addresses #8 * Update README to note changes in ES 2.0 * Add stats for thread pool
1 parent 5cf9872 commit 9439462

File tree

3 files changed

+95
-36
lines changed

3 files changed

+95
-36
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
VERSION := 0.2.1
14+
VERSION := 0.3.0
1515
TARGET := elasticsearch_exporter
1616

1717
include Makefile.COMMON

elasticsearch_exporter.go

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,27 @@ type VecInfo struct {
2626

2727
var (
2828
gaugeMetrics = map[string]string{
29-
"indices_fielddata_memory_size_bytes": "Field data cache memory usage in bytes",
30-
"indices_filter_cache_memory_size_bytes": "Filter cache memory usage in bytes",
31-
"indices_docs": "Count of documents on this node",
32-
"indices_docs_deleted": "Count of deleted documents on this node",
33-
"indices_store_size_bytes": "Current size of stored index data in bytes",
34-
"indices_segments_memory_bytes": "Current memory size of segments in bytes",
35-
"indices_segments_count": "Count of index segments on this node",
36-
"process_cpu_percent": "Percent CPU used by process",
37-
"process_mem_resident_size_bytes": "Resident memory in use by process in bytes",
38-
"process_mem_share_size_bytes": "Shared memory in use by process in bytes",
39-
"process_mem_virtual_size_bytes": "Total virtual memory used in bytes",
40-
"process_open_files_count": "Open file descriptors",
29+
"indices_fielddata_memory_size_bytes": "Field data cache memory usage in bytes",
30+
"indices_filter_cache_memory_size_bytes": "Filter cache memory usage in bytes",
31+
"indices_query_cache_memory_size_bytes": "Query cache memory usage in bytes",
32+
"indices_request_cache_memory_size_bytes": "Request cache memory usage in bytes",
33+
"indices_docs": "Count of documents on this node",
34+
"indices_docs_deleted": "Count of deleted documents on this node",
35+
"indices_store_size_bytes": "Current size of stored index data in bytes",
36+
"indices_segments_memory_bytes": "Current memory size of segments in bytes",
37+
"indices_segments_count": "Count of index segments on this node",
38+
"process_cpu_percent": "Percent CPU used by process",
39+
"process_mem_resident_size_bytes": "Resident memory in use by process in bytes",
40+
"process_mem_share_size_bytes": "Shared memory in use by process in bytes",
41+
"process_mem_virtual_size_bytes": "Total virtual memory used in bytes",
42+
"process_open_files_count": "Open file descriptors",
43+
"process_max_files_count": "Max file descriptors for process",
4144
}
4245
counterMetrics = map[string]string{
4346
"indices_fielddata_evictions": "Evictions from field data",
4447
"indices_filter_cache_evictions": "Evictions from filter cache",
48+
"indices_query_cache_evictions": "Evictions from query cache",
49+
"indices_request_cache_evictions": "Evictions from request cache",
4550
"indices_flush_total": "Total flushes",
4651
"indices_flush_time_ms_total": "Cumulative flush time in milliseconds",
4752
"transport_rx_packets_total": "Count of packets received",
@@ -71,6 +76,14 @@ var (
7176
help: "Process CPU time in seconds",
7277
labels: []string{"type"},
7378
},
79+
"thread_pool_completed_count": &VecInfo{
80+
help: "Thread Pool operations completed",
81+
labels: []string{"type"},
82+
},
83+
"thread_pool_rejected_count": &VecInfo{
84+
help: "Thread Pool operations rejected",
85+
labels: []string{"type"},
86+
},
7487
}
7588

7689
gaugeVecMetrics = map[string]*VecInfo{
@@ -94,6 +107,22 @@ var (
94107
help: "JVM memory max",
95108
labels: []string{"area"},
96109
},
110+
"thread_pool_active_count": &VecInfo{
111+
help: "Thread Pool threads active",
112+
labels: []string{"type"},
113+
},
114+
"thread_pool_largest_count": &VecInfo{
115+
help: "Thread Pool largest threads count",
116+
labels: []string{"type"},
117+
},
118+
"thread_pool_queue_count": &VecInfo{
119+
help: "Thread Pool operations queued",
120+
labels: []string{"type"},
121+
},
122+
"thread_pool_threads_count": &VecInfo{
123+
help: "Thread Pool current threads count",
124+
labels: []string{"type"},
125+
},
97126
}
98127
)
99128

@@ -110,7 +139,7 @@ type Exporter struct {
110139
counters map[string]*prometheus.CounterVec
111140
counterVecs map[string]*prometheus.CounterVec
112141

113-
allNodes bool
142+
allNodes bool
114143

115144
client *http.Client
116145
}
@@ -169,7 +198,7 @@ func NewExporter(uri string, timeout time.Duration, allNodes bool) *Exporter {
169198
gauges: gauges,
170199
gaugeVecs: gaugeVecs,
171200

172-
allNodes: allNodes,
201+
allNodes: allNodes,
173202

174203
client: &http.Client{
175204
Transport: &http.Transport{
@@ -234,7 +263,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
234263
vec.Reset()
235264
}
236265

237-
defer func() { ch <- e.up }()
266+
defer func() { ch <- e.up }()
238267

239268
resp, err := e.client.Get(e.URI)
240269
if err != nil {
@@ -278,6 +307,17 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
278307
e.gaugeVecs["breakers_limit_size_bytes"].WithLabelValues(allStats.ClusterName, stats.Host, breaker).Set(float64(bstats.LimitSize))
279308
}
280309

310+
// Thread Pool stats
311+
for pool, pstats := range stats.ThreadPool {
312+
e.counterVecs["thread_pool_completed_count"].WithLabelValues(allStats.ClusterName, stats.Host, pool).Set(float64(pstats.Completed))
313+
e.counterVecs["thread_pool_rejected_count"].WithLabelValues(allStats.ClusterName, stats.Host, pool).Set(float64(pstats.Rejected))
314+
315+
e.gaugeVecs["thread_pool_active_count"].WithLabelValues(allStats.ClusterName, stats.Host, pool).Set(float64(pstats.Active))
316+
e.gaugeVecs["thread_pool_threads_count"].WithLabelValues(allStats.ClusterName, stats.Host, pool).Set(float64(pstats.Active))
317+
e.gaugeVecs["thread_pool_largest_count"].WithLabelValues(allStats.ClusterName, stats.Host, pool).Set(float64(pstats.Active))
318+
e.gaugeVecs["thread_pool_queue_count"].WithLabelValues(allStats.ClusterName, stats.Host, pool).Set(float64(pstats.Active))
319+
}
320+
281321
// JVM Memory Stats
282322
e.gaugeVecs["jvm_memory_committed_bytes"].WithLabelValues(allStats.ClusterName, stats.Host, "heap").Set(float64(stats.JVM.Mem.HeapCommitted))
283323
e.gaugeVecs["jvm_memory_used_bytes"].WithLabelValues(allStats.ClusterName, stats.Host, "heap").Set(float64(stats.JVM.Mem.HeapUsed))
@@ -287,9 +327,16 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
287327

288328
// Indices Stats
289329
e.gauges["indices_fielddata_memory_size_bytes"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.FieldData.MemorySize))
330+
e.counters["indices_fielddata_evictions"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.FieldData.Evictions))
331+
290332
e.gauges["indices_filter_cache_memory_size_bytes"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.FilterCache.MemorySize))
291333
e.counters["indices_filter_cache_evictions"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.FilterCache.Evictions))
292-
e.counters["indices_fielddata_evictions"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.FieldData.Evictions))
334+
335+
e.gauges["indices_query_cache_memory_size_bytes"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.QueryCache.MemorySize))
336+
e.counters["indices_query_cache_evictions"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.QueryCache.Evictions))
337+
338+
e.gauges["indices_request_cache_memory_size_bytes"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.QueryCache.MemorySize))
339+
e.counters["indices_request_cache_evictions"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.QueryCache.Evictions))
293340

294341
e.gauges["indices_docs"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.Docs.Count))
295342
e.gauges["indices_docs_deleted"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Indices.Docs.Deleted))
@@ -326,6 +373,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
326373
e.gauges["process_mem_virtual_size_bytes"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Process.Memory.TotalVirtual))
327374
e.gauges["process_open_files_count"].WithLabelValues(allStats.ClusterName, stats.Host).Set(float64(stats.Process.OpenFD))
328375

376+
e.counterVecs["process_cpu_time_seconds_sum"].WithLabelValues(allStats.ClusterName, stats.Host, "total").Set(float64(stats.Process.CPU.Total / 1000))
329377
e.counterVecs["process_cpu_time_seconds_sum"].WithLabelValues(allStats.ClusterName, stats.Host, "sys").Set(float64(stats.Process.CPU.Sys / 1000))
330378
e.counterVecs["process_cpu_time_seconds_sum"].WithLabelValues(allStats.ClusterName, stats.Host, "user").Set(float64(stats.Process.CPU.User / 1000))
331379
}
@@ -359,7 +407,6 @@ func main() {
359407
)
360408
flag.Parse()
361409

362-
363410
if *esAllNodes {
364411
*esURI = *esURI + "/_nodes/stats"
365412
} else {

struct.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package main
22

3+
import "encoding/json"
4+
35
// Elasticsearch Node Stats Structs
46

57
type NodeStatsResponse struct {
@@ -95,17 +97,19 @@ type NodeStatsTCPResponse struct {
9597
}
9698

9799
type NodeStatsIndicesResponse struct {
98-
Docs NodeStatsIndicesDocsResponse
99-
Store NodeStatsIndicesStoreResponse
100-
Indexing NodeStatsIndicesIndexingResponse
101-
Merges NodeStatsIndicesMergesResponse
102-
Get NodeStatsIndicesGetResponse
103-
Search NodeStatsIndicesSearchResponse
104-
FieldData NodeStatsIndicesFieldDataResponse
105-
FilterCache NodeStatsIndicesFieldDataResponse `json:"filter_cache"`
106-
Flush NodeStatsIndicesFlushResponse
107-
Segments NodeStatsIndicesSegmentsResponse
108-
Refresh NodeStatsIndicesRefreshResponse
100+
Docs NodeStatsIndicesDocsResponse
101+
Store NodeStatsIndicesStoreResponse
102+
Indexing NodeStatsIndicesIndexingResponse
103+
Merges NodeStatsIndicesMergesResponse
104+
Get NodeStatsIndicesGetResponse
105+
Search NodeStatsIndicesSearchResponse
106+
FieldData NodeStatsIndicesCacheResponse `json:"fielddata"`
107+
FilterCache NodeStatsIndicesCacheResponse `json:"filter_cache"`
108+
QueryCache NodeStatsIndicesCacheResponse `json:"query_cache"`
109+
RequestCache NodeStatsIndicesCacheResponse `json:"request_cache"`
110+
Flush NodeStatsIndicesFlushResponse
111+
Segments NodeStatsIndicesSegmentsResponse
112+
Refresh NodeStatsIndicesRefreshResponse
109113
}
110114

111115
type NodeStatsIndicesDocsResponse struct {
@@ -172,18 +176,25 @@ type NodeStatsIndicesFlushResponse struct {
172176
Time int64 `json:"total_time_in_millis"`
173177
}
174178

175-
type NodeStatsIndicesFieldDataResponse struct {
179+
type NodeStatsIndicesCacheResponse struct {
176180
Evictions int64 `json:"evictions"`
177181
MemorySize int64 `json:"memory_size_in_bytes"`
182+
CacheCount int64 `json:"cache_count"`
183+
CacheSize int64 `json:"cache_size"`
184+
HitCount int64 `json:"hit_count"`
185+
MissCount int64 `json:"miss_count"`
186+
TotalCount int64 `json:"total_count"`
178187
}
179188

180189
type NodeStatsOSResponse struct {
181-
Timestamp int64 `json:"timestamp"`
182-
Uptime int64 `json:"uptime_in_millis"`
183-
LoadAvg []float64 `json:"load_average"`
184-
CPU NodeStatsOSCPUResponse `json:"cpu"`
185-
Mem NodeStatsOSMemResponse `json:"mem"`
186-
Swap NodeStatsOSSwapResponse `json:"swap"`
190+
Timestamp int64 `json:"timestamp"`
191+
Uptime int64 `json:"uptime_in_millis"`
192+
// LoadAvg was an array of per-cpu values pre-2.0, and is a string in 2.0
193+
// Leaving this here in case we want to implement parsing logic later
194+
LoadAvg json.RawMessage `json:"load_average"`
195+
CPU NodeStatsOSCPUResponse `json:"cpu"`
196+
Mem NodeStatsOSMemResponse `json:"mem"`
197+
Swap NodeStatsOSSwapResponse `json:"swap"`
187198
}
188199

189200
type NodeStatsOSMemResponse struct {
@@ -208,6 +219,7 @@ type NodeStatsOSCPUResponse struct {
208219
type NodeStatsProcessResponse struct {
209220
Timestamp int64 `json:"timestamp"`
210221
OpenFD int64 `json:"open_file_descriptors"`
222+
MaxFD int64 `json:"max_file_descriptors"`
211223
CPU NodeStatsProcessCPUResponse `json:"cpu"`
212224
Memory NodeStatsProcessMemResponse `json:"mem"`
213225
}

0 commit comments

Comments
 (0)