-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneo4jMonRels.chart.py
50 lines (32 loc) · 1.53 KB
/
neo4jMonRels.chart.py
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
# -*- coding: utf-8 -*-
# Description: example netdata python.d module for monitoring Neo4j
# Author: Jerome Baton, copied from Pawel Krupa (paulfantom)
from base import SimpleService
from neo4j.v1 import GraphDatabase
class Service(SimpleService):
update_every = 30
priority = 9000
retries = 1
def __init__(self, configuration=None, name=None):
super(self.__class__,self).__init__(configuration=configuration, name=name)
def check(self):
return True
def create(self):
self.chart("neo4j.neo4jmonrels", '', 'Monitors the number of nodes per relation name', 'Nodes #','Nodes# per Relation', 'line', self.priority, self.update_every)
host = self.configuration.get('host')
boltport = self.configuration.get('boltport','7687')
uri = "bolt://" + host + ":" + boltport
self.neodriver = GraphDatabase.driver(uri, auth=(self.configuration.get('user'), self.configuration.get('pwd') ))
return True
def update(self, interval):
self.begin("neo4j.neo4jmonrels", interval)
neosession = self.neodriver.session()
with neosession.begin_transaction() as tx:
for neorecord in tx.run("MATCH (n)-[r]-(m) RETURN type(r) as label, count(r) AS cnt ORDER BY cnt DESC LIMIT 5"):
self.dimension( neorecord["label"] )
self.set( neorecord["label"], neorecord["cnt"] )
tx.close()
neosession.close()
self.end()
self.commit()
return True