graphana integration
diff --git a/sensors/grafana.py b/sensors/grafana.py
new file mode 100644
index 0000000..9823fac
--- /dev/null
+++ b/sensors/grafana.py
@@ -0,0 +1,47 @@
+import json
+
+
+query = """
+select value from "{series}"
+where $timeFilter and
+host='{host}' and device='{device}'
+order asc
+"""
+
+
+def make_dashboard_file(config):
+    series = ['writes_completed', 'sectors_written']
+    dashboards = []
+
+    for serie in series:
+        dashboard = dict(title=serie, type='graph',
+                         span=12, fill=1, linewidth=2,
+                         tooltip={'shared': True})
+
+        targets = []
+
+        for ip, devs in config.items():
+            for device in devs:
+                params = {
+                    'series': serie,
+                    'host': ip,
+                    'device': device
+                }
+
+                target = dict(
+                    target="disk io",
+                    query=query.replace("\n", " ").format(**params).strip(),
+                    interval="",
+                    alias="{0} io {1}".format(ip, device),
+                    rawQuery=True
+                )
+                targets.append(target)
+
+        dashboard['targets'] = targets
+        dashboards.append(dashboard)
+
+    fc = open("grafana_template.js").read()
+    return fc % (json.dumps(dashboards),)
+
+
+print make_dashboard_file({'192.168.0.104': ['sda1', 'rbd1']})
diff --git a/sensors/grafana_template.js b/sensors/grafana_template.js
index 08f8f99..7c57924 100644
--- a/sensors/grafana_template.js
+++ b/sensors/grafana_template.js
@@ -23,9 +23,7 @@
 var ARGS;
 
 // Intialize a skeleton with nothing but a rows array and service object
-dashboard = {
-  rows : [],
-};
+dashboard = {rows : []};
 
 // Set a title
 dashboard.title = 'Tests dash';
@@ -34,47 +32,15 @@
 // time can be overriden in the url using from/to parameteres, but this is
 // handled automatically in grafana core during dashboard initialization
 dashboard.time = {
-  from: "now-5m",
-  to: "now"
+    from: "now-5m",
+    to: "now"
 };
 
-var rows = 1;
-var seriesName = 'argName';
-
-if(!_.isUndefined(ARGS.rows)) {
-  rows = parseInt(ARGS.rows, 10);
-}
-
-if(!_.isUndefined(ARGS.name)) {
-  seriesName = ARGS.name;
-}
-
-for (var i = 0; i < rows; i++) {
-
-  dashboard.rows.push({
+dashboard.rows.push({
     title: 'Chart',
     height: '300px',
-    panels: [
-      {
-        title: 'Events',
-        type: 'graph',
-        span: 12,
-        fill: 1,
-        linewidth: 2,
-        targets: [
-              {"target": "disk io",
-               "query": "select value from \"sectors_written\" where $timeFilter and host='192.168.0.104' and device='sda1' order asc",
-               "interval": "",
-               "alias": "host io sw",
-               "rawQuery": true}       
-        ],
-        tooltip: {
-          shared: true
-        }
-      }
-    ]
-  });
-}
+    panels: %s
+});
 
 
 return dashboard;
diff --git a/sensors/receiver.py b/sensors/receiver.py
index 369a65f..8903f24 100644
--- a/sensors/receiver.py
+++ b/sensors/receiver.py
@@ -9,35 +9,33 @@
 infldb_url = "influxdb://perf:perf@192.168.152.42:8086/perf"
 conn = connect(infldb_url)
 
-sw_per_ip = {}
-count = 4
-expected = ['192.168.0.104', '192.168.152.41',
-            '192.168.152.39', '192.168.152.40']
+# sw_per_ip = {}
+# count = 4
+# expected = sorted(monitor_config.keys())
+
+# if 'sda1.sectors_written' in data:
+#     val = data['sda1.sectors_written']
+# elif 'sdb.sectors_written' in data:
+#     val = data['sdb.sectors_written']
+# else:
+#     val = 0
+
+# sw_per_ip[ip] = sw_per_ip.get(ip, 0) + val
+# count -= 1
+
+# if 0 == count:
+#     try:
+#         vals = [sw_per_ip[ip] for ip in expected]
+#         print ("{:>6}" * len(expected)).format(*vals)
+#         sw_per_ip = {}
+#         count = 4
+#     except KeyError:
+#         pass
 
 with start_monitoring(uri, monitor_config) as queue:
     while True:
         try:
             (ip, port), data = queue.get(True, 1)
-
-            if 'sda1.sectors_written' in data:
-                val = data['sda1.sectors_written']
-            elif 'sdb.sectors_written' in data:
-                val = data['sdb.sectors_written']
-            else:
-                val = 0
-
-            sw_per_ip[ip] = sw_per_ip.get(ip, 0) + val
-            count -= 1
-
-            if 0 == count:
-                try:
-                    vals = [sw_per_ip[ip] for ip in expected]
-                    print ("{:>6}" * 4).format(*vals)
-                    sw_per_ip = {}
-                    count = 4
-                except KeyError:
-                    pass
-
             add_data(conn, ip, [data])
         except Empty:
             pass