コード例 #1
0
ファイル: FGSearch.py プロジェクト: hanjinze/cloud-metrics
    def get_series(self):
        series = []
        try:
            for group, metrics in self.get_metric().iteritems():
                for metric, period in metrics.iteritems():
                    if len(metrics) > 1:
                        series_name = metric
                    else:
                        series_name = group
                    stat = {"name": series_name,
                            "data": period[self.period or self.groupby]}  # period.values()[0] }
                    series.append(stat)
        except:
            print sys.exc_info()
            FGUtility.debug(True)

            # Just try  01/08/2013
            for metric_name in self.metric:  # self.metric is list
                record = {}
                for group, v in self.get_metric().iteritems():
                    val = v[metric_name][
                        self.period or self.groupby or "Total"]
                    record[group] = val

                stat = {"name": metric_name,
                        "data": record}
                series.append(stat)

        return series
コード例 #2
0
    def set_output_path(self, path):
        try:
            FGUtility.ensure_dir(path + "/" + self.filename)
        except:
            path = "./"

        self.filepath = path
コード例 #3
0
    def collect_files(self):
        """
        this function gathers all eucalyptus log files that are located in
        all subdirectories starting from "from_path" and copies them into
        the specified backup directory. In addition all log file will be
        renamed based on the timestap in the last line of the log
        file. The fileame is date-time.cc.log where all items are
        separated with a "-". E.g. YYYY-MM-DD-HH-mm-ss-cc.log. If a
        logfile already exists with that name it will not be overwritten
        and the next file in the subdirectory will be attempted to be
        copied to backup.
        """
        if not FGUtility.ensure_dir(self.output_dir + "/"):
            print "to_path '" + self.output_dir + "' doesn't exist"
            return

        if not os.path.exists(self.input_dir):
            print "from_path '" + self.input_dir + "' doesn't exist"
            return

        for file in self.file_list():
            path = os.path.dirname(file)
            name = os.path.basename(file)
            new_name = os.path.basename(self.get_filename_from_date(path, name))
            new_location = os.path.join(self.output_dir, new_name)
            if not os.path.exists(new_location):
                print new_name
                shutil.copy2(file, new_location)
            else:
                print new_name + ", WARNING: file exists, copy ignored"
        return
コード例 #4
0
ファイル: FGConverter.py プロジェクト: hanjinze/cloud-metrics
 def _read_userinfo_of_nova_with_project_info(self):
     keystone = self.db
     keystone.dbname = self.dbname_keystone
     keystone.connect()
     userinfo = keystone.query(
         "select user_id, tenant_id, user.name as user_name, tenant.name as tenant_name \
             from user_tenant_membership, tenant, user \
             where user.id=user_tenant_membership.user_id \
             and tenant.id=user_tenant_membership.tenant_id"
     )  # select id, name from user")
     keystone.close()
     records = []
     for row in userinfo:
         try:
             res = FGUtility.retrieve_userinfo_ldap(row["user_name"])
             if not res:
                 res = {}
             res["ownerid"] = row["user_id"]
             res["username"] = row["user_name"]
             res["project"] = row["tenant_name"]
             res["hostname"] = self.hostname
             print res
             records.append(res)
         except:
             print sys.exc_info()
             raise
     return records
コード例 #5
0
ファイル: FGSearch.py プロジェクト: hanjinze/cloud-metrics
    def create_months_between_dates(self, from_date, to_date, val=None):
        """ Get months between two dates

            Args:
                from_date (datetime)
                to_date (datetime)
            Returns:
                dict
            Raises:
                n/a
        """

        try:
            months = self.get_months_between_dates(from_date, to_date)
            return {month: val for month in months}
        except:
            FGUtility.debug(str(sys.exc_info()))
コード例 #6
0
ファイル: FGSearch.py プロジェクト: hanjinze/cloud-metrics
    def create_dates_between_dates(self, from_date, to_date, val=None):
        """ Get dates between two dates

            Args:
                from_date (datetime)
                to_date (datetime)
            Returns:
                dict
            Raises:
                n/a
        """

        try:
            from_date = datetime(
                from_date.year, from_date.month, from_date.day)
            to_date = datetime(to_date.year, to_date.month, to_date.day)
            days = (to_date + timedelta(days=1) - from_date).days
            return {from_date + timedelta(days=n): val for n in range(days)}
        except:
            FGUtility.debug(str(sys.exc_info()))
コード例 #7
0
ファイル: FGSearch.py プロジェクト: hanjinze/cloud-metrics
    def get_dates_between_dates(self, from_date, to_date):
        """ Get dates between two dates

            Args:
                from_date (datetime)
                to_date (datetime)
            Returns:
                list
            Raises:
                n/a
        """

        try:
            from_date = datetime(
                from_date.year, from_date.month, from_date.day)
            to_date = datetime(to_date.year, to_date.month, to_date.day)
            days = (to_date + datetime.timedelta(days=1) - from_date).days
            return [from_date + timedelta(days=n) for n in range(days)]
        except:
            FGUtility.debug(str(sys.exc_info()))
コード例 #8
0
ファイル: FGCharts.py プロジェクト: futuregrid/cloud-metrics
    def __init__(self):
        self.chart = None
        self.chart_api = None
        self.type = None
        self.data = None
        self.data_name = "all"
        self.series = []
        self.data_beta = { "type":None, "name":None, "data":None } 
        self.xaxis = None
        self.yaxis = None
        self.output_path = "./"#None
        self.output_type = "html"
        self.title = "FG Charts"#None
        self.subtitle = ""#None
        self.filename = FGUtility.timeStamped("chart") + "." + self.output_type#None
        self.script_path = "global"#"local"

        self.sort = "bykey"
コード例 #9
0
 def set_output_path(self, directory):
     FGUtility.ensure_dir(directory + "/" + self.filename)
     self.filepath = directory