本文整理汇总了Python中dao.Dao.save_server_data方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.save_server_data方法的具体用法?Python Dao.save_server_data怎么用?Python Dao.save_server_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.save_server_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServerMap
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import save_server_data [as 别名]
class ServerMap(object):
def __init__(self):
self.dao = Dao()
sys.path.append("servermap/plugins")
self.reload()
def load_servers(self):
for server in self.config.get("servers"):
hostname = server.get("hostname")
self.dao.save_server_data(**server)
def load_dimensions(self):
for dimension in self.dimensions:
self.dao.save_dimension_data(**dimension.metadata())
def load_metrics(self):
for dimension in self.dimensions:
for metric in dimension.metric_metadata():
self.dao.save_metric_data(dimension_name=dimension.metadata().get("dimension_name"), **metric)
def reload(self):
self.dimensions = load_plugin("servermap_dimension_*")
for dimension in self.dimensions:
reload(dimension)
with open("config.json") as f:
self.config = json.loads(f.read())
self.load_servers()
self.load_dimensions()
self.load_metrics()
def main(self):
self.get_data()
def get_data(self):
for dimension in self.dimensions:
for server in self.dao.get_servers():
# TODO: threading
try:
for metric in dimension.get_metrics(server):
datapoint = {
"dimension_name": dimension.metadata().get("dimension_name"),
"host": server.get("host"),
"metric_name": metric[0],
"value": metric[1],
"timestamp": metric[2]
}
self.dao.save_datapoint_data(**datapoint)
except Exception as e:
logging.error(str(e))