Add bgwriter info
Facetoe committed
Oct 3, 2016 at 18:41 UTC
9ed56f71f505703e130f474b4e725dd25a1f9ad2
1 file changed
+27
-9
python.d/postgres.chart.py
+27
-9
@@ -1,13 +1,9 @@
1
# -*- coding: utf-8 -*-
2
-# Description: example netdata python.d module
3
-# Author: Pawel Krupa (paulfantom)
2
3
import psycopg2
4
from base import SimpleService
5
from psycopg2.extras import DictCursor
6
9
-NAME = "test"
10
-
7
# default module values
8
update_every = 1
9
priority = 90000
@@ -22,7 +18,7 @@ retries = 60
18
# 'port': 5432
19
# }
20
25
-ORDER = ["Tuples", "Scans"]
21
+ORDER = ["Tuples", "Scans", "BGWriter"]
22
CHARTS = {
23
"Tuples": {
24
'options': ["tuples", "PostgreSQL tuple access", "Tuples / sec", "tuples", "postgres.tuples", "line"],
@@ -30,7 +26,7 @@ CHARTS = {
26
["inserted", "inserted", "incremental", 1, 1],
27
["seqread", "seqread", "incremental", 1, 1],
28
["hotupdated", "hotupdated", "incremental", 1, 1],
33
- ["deleted", "deleted", "incremental", -1, 1],
29
+ ["deleted", "deleted", "incremental", 1, 1],
30
["updated", "updated", "incremental", 1, 1],
31
["idxfetch", "idxfetch", "incremental", 1, 1],
32
]},
@@ -39,6 +35,14 @@ CHARTS = {
35
'lines': [
36
["sequential", "sequential", "incremental", 1, 1],
37
["index", "index", "incremental", 1, 1],
38
+ ]},
39
+ "BGWriter": {
40
+ 'options': ["bgwriter", "BG Writer Activity", "Buffers / sec", "bgwriter", "postgres.bgwriter", "line"],
41
+ 'lines': [
42
+ ["buffers_alloc", "buffers_alloc", "incremental", 1, 1],
43
+ ["buffers_clean", "buffers_clean", "incremental", 1, 1],
44
+ ["buffers_checkpoint", "buffers_checkpoint", "incremental", 1, 1],
45
+ ["buffers_backend", "buffers_backend", "incremental", 1, 1],
46
]}
47
}
48
@@ -73,7 +77,9 @@ class Service(SimpleService):
77
def _get_data(self):
78
cursor = self.connection.cursor(cursor_factory=DictCursor)
79
cursor.execute("""
76
- SELECT COALESCE(sum(seq_tup_read),0) AS seqread,
80
+ SELECT
81
+ -- Tuples
82
+ COALESCE(sum(seq_tup_read),0) AS seqread,
83
COALESCE(sum(idx_tup_fetch),0) AS idxfetch,
84
COALESCE(sum(n_tup_ins),0) AS inserted,
85
COALESCE(sum(n_tup_upd),0) AS updated,
@@ -85,7 +91,19 @@ class Service(SimpleService):
91
COALESCE(sum(idx_scan),0) AS index
92
FROM pg_stat_user_tables
93
""")
88
- data = {k: float(v) for k, v in cursor.fetchone().items()}
94
+ graph_data = {k: float(v) for k, v in cursor.fetchone().items()}
95
+
96
+ cursor.execute("""
97
+ SELECT
98
+ buffers_checkpoint,
99
+ buffers_clean,
100
+ buffers_backend,
101
+ buffers_alloc
102
+ FROM
103
+ pg_stat_bgwriter
104
+ """)
105
+ graph_data.update(dict(cursor.fetchone()))
106
+
107
self.connection.commit()
108
cursor.close()
91
- return data
109
+ return graph_data