Browse Source

BaseStorage: send metric with primary-mac instead of nodeid

This is a TODO for later, as the primary mac is considered to be stable
but everything else takes the nodeid as the primary reference. Thus,
Graphite should do the same.
Helge Jung 8 years ago
parent
commit
5243139196
2 changed files with 18 additions and 4 deletions
  1. 13 0
      ffstatus/__init__.py
  2. 5 4
      ffstatus/basestorage.py

+ 13 - 0
ffstatus/__init__.py

@@ -33,6 +33,19 @@ def mac2id(mac):
     return mac.lower().replace(':', '')
 
 
+def guess_mac_from_nodeid(nodeid):
+    if len(nodeid) != 12:
+        return None
+    return ':'.join([
+        nodeid[0:2],
+        nodeid[2:4],
+        nodeid[4:6],
+        nodeid[6:8],
+        nodeid[8:10],
+        nodeid[10:12],
+    ])
+
+
 def dict_merge(a, b, overwrite_lists=True):
     '''recursively merges dict's. not just simple a['key'] = b['key'], if
     both a and bhave a key who's value is a dict then dict_merge is called

+ 5 - 4
ffstatus/basestorage.py

@@ -251,9 +251,10 @@ class BaseStorage(object):
                 item['node_id'] = itemid
 
             # remove node's MACs from clients list
+            item_mac = item.get('mac') or ffstatus.guess_mac_from_nodeid(itemid)
             clients = [x for x in item.get('clients', [])]
-            if 'mac' in item and item['mac'] in clients:
-                clients.remove(item['mac'])
+            if item_mac is not None and item_mac in clients:
+                clients.remove(item_mac)
             for mac in item.get('macs', []):
                 if mac in clients:
                     clients.remove(mac)
@@ -269,9 +270,9 @@ class BaseStorage(object):
 
             diff_added = [x for x in new_clients if x not in prev_clients]
             diff_removed = [x for x in prev_clients if x not in new_clients]
-            self.__send_metric("nodes." + itemid + ".clients_added",
+            self.__send_metric("nodes." + item_mac + ".clients_added",
                                len(diff_added), ts)
-            self.__send_metric("nodes." + itemid + ".clients_removed",
+            self.__send_metric("nodes." + item_mac + ".clients_removed",
                                len(diff_removed), ts)
 
             # finally, set each new data