import diamond.collector import datetime import os class DatastoreCollector(diamond.collector.Collector): #class DatastoreCollector(object): def get_size(self): now = datetime.datetime.now() start_path = '/opt/ang/var/datastore/ang/data/daily/' + now.strftime("%Y/%m")+'' total_size = 0 for dirpath, dirnames, filenames in os.walk(start_path, topdown=True, followlinks=False): for f in filenames: fp = os.path.join(dirpath, f) if not os.path.islink(fp): total_size += os.path.getsize(fp) return total_size def collect(self): metric_name = "size" self.publish(metric_name,self.get_size()) if __name__ == "__main__": ds = DatastoreCollector() print ds.get_size()