Trees | Indices | Help |
---|
|
1 from collections import defaultdict 2 3 from sqlalchemy.orm.exc import NoResultFound 4 5 from coprs import app 6 from coprs import db 7 from coprs.models import CounterStat 8 from coprs import helpers 9 from coprs.helpers import REPO_DL_STAT_FMT, CHROOT_REPO_MD_DL_STAT_FMT, string_dt_to_unixtime, \ 10 CHROOT_RPMS_DL_STAT_FMT, PROJECT_RPMS_DL_STAT_FMT, is_ip_from_builder_net 11 from coprs.helpers import CounterStatType 12 from coprs.rmodels import TimedStatEvents16 17 @classmethod7619 """ 20 :param name: counter name 21 :return: 22 """ 23 return CounterStat.query.filter(CounterStat.name == name)24 25 @classmethod27 return ( 28 CounterStat.query 29 .filter(CounterStat.counter_type == counter_type) 30 .filter(CounterStat.name.in_(names_list)) 31 )32 33 @classmethod 38 39 @classmethod41 """ 42 Warning: dirty method: does commit if missing stat record. 43 """ 44 try: 45 csl = CounterStatLogic.get(name).one() 46 csl.counter = CounterStat.counter + 1 47 except NoResultFound: 48 csl = CounterStatLogic.add(name, counter_type) 49 csl.counter = 1 50 51 db.session.add(csl) 52 return csl53 54 @classmethod56 # chroot -> stat_name 57 chroot_by_stat_name = {} 58 for chroot in copr.active_chroots: 59 kwargs = { 60 "copr_user": copr.user.name, 61 "copr_project_name": copr.name, 62 "copr_name_release": chroot.name_release 63 } 64 chroot_by_stat_name[REPO_DL_STAT_FMT.format(**kwargs)] = chroot.name_release 65 66 # [{counter: <value>, name: <stat_name>}, ...] 67 stats = cls.get_multiply_same_type(counter_type=helpers.CounterStatType.REPO_DL, 68 names_list=chroot_by_stat_name.keys()) 69 70 # need: {chroot -> value, ... } 71 repo_dl_stats = defaultdict(int) 72 for stat in stats: 73 repo_dl_stats[chroot_by_stat_name[stat.name]] = stat.counter 74 75 return repo_dl_stats79 """ 80 :param rc: connection to redis 81 :type rc: StrictRedis 82 83 :param ls_data: log stash record 84 :type ls_data: dict 85 """ 86 dt_unixtime = string_dt_to_unixtime(ls_data["@timestamp"]) 87 app.logger.debug("got ls_data: {}".format(ls_data)) 88 89 # don't count statistics from builders 90 if "clientip" in ls_data: 91 if is_ip_from_builder_net(ls_data["clientip"]): 92 return 93 94 if "tags" not in ls_data: 95 return 96 97 tags = set(ls_data["tags"]) 98 if "frontend" in tags and "repo_dl": 99 name = REPO_DL_STAT_FMT.format(**ls_data) 100 CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL) 101 db.session.commit() 102 103 if "backend" in tags and "repomdxml" in tags: 104 if "copr_user" in ls_data: 105 key = CHROOT_REPO_MD_DL_STAT_FMT.format(**ls_data) 106 TimedStatEvents.add_event(rc, key, timestamp=dt_unixtime) 107 108 if "backend" in tags and "rpm" in tags: 109 key_chroot = CHROOT_RPMS_DL_STAT_FMT.format(**ls_data) 110 key_project = PROJECT_RPMS_DL_STAT_FMT.format(**ls_data) 111 TimedStatEvents.add_event(rc, key_chroot, timestamp=dt_unixtime) 112 TimedStatEvents.add_event(rc, key_project, timestamp=dt_unixtime)113
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Dec 5 22:37:25 2016 | http://epydoc.sourceforge.net |