-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathes_gc_count
More file actions
executable file
·72 lines (58 loc) · 1.97 KB
/
es_gc_count
File metadata and controls
executable file
·72 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################
# Munin plugin for Elasticsearch monitoring #
# by Andrii Gakhov <andrii.gakhov@gmail.com> #
##############################################
import json
import urllib3
from munin import MuninPlugin
class ESGarbageCollectionCountPlugin(MuninPlugin):
category = 'Elasticsearch'
args = '--base 1000 --lower-limit 0'
vlabel = 'Number of garbage collections'
info = 'Show garbage collection counts'
@property
def title(self):
return 'Elasticsearch Garbage Collection count'
@property
def fields(self):
fields = [
('total', dict(
label='total',
type='GAUGE',
)),
('young', dict(
label='young generation',
type='GAUGE',
)),
('old', dict(
label='old generation',
type='GAUGE',
))
]
return fields
def __init__(self):
super(ESGarbageCollectionCountPlugin, self).__init__()
self.es_host = 'http://localhost:9200'
self.http = urllib3.PoolManager()
def execute(self):
return self._get_gc_stats()
def _get_gc_stats(self):
url = '{}/_nodes/_local/jvm/stats'.format(self.es_host)
response = self.http.request('GET', url)
if response.status != 200:
return None
data = json.loads(response.data)
if not data.get('nodes', {}).values():
return None
stats = data['nodes'].values()[0].get('jvm', {}).get('gc', {})
return {
'total': stats.get('collection_count'),
'new': stats.get('collectors', {}).get(
'ParNew', {}).get('collection_count'),
'old': stats.get('collectors', {}).get(
'ConcurrentMarkSweep', {}).get('collection_count'),
}
if __name__ == '__main__':
ESGarbageCollectionCountPlugin().run()