• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tsdb.get_range函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.app.tsdb.get_range函数的典型用法代码示例。如果您正苦于以下问题:Python get_range函数的具体用法?Python get_range怎么用?Python get_range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_range函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_attrs

    def get_attrs(self, item_list, user):
        attrs = super(StreamGroupSerializer, self).get_attrs(item_list, user)

        # we need to compute stats at 1d (1h resolution), and 14d
        group_ids = [g.id for g in item_list]
        now = timezone.now()
        hourly_stats = tsdb.get_range(
            model=tsdb.models.group,
            keys=group_ids,
            end=now,
            start=now - timedelta(days=1),
            rollup=3600,
        )
        daily_stats = tsdb.get_range(
            model=tsdb.models.group,
            keys=group_ids,
            end=now,
            start=now - timedelta(days=14),
            rollup=3600 * 24,
        )

        for item in item_list:
            attrs[item].update({
                'hourly_stats': hourly_stats[item.id],
                'daily_stats': daily_stats[item.id],
            })
        return attrs
开发者ID:KinKir,项目名称:sentry,代码行数:27,代码来源:group.py


示例2: get

    def get(self, request, project):
        try:
            environment_id = self._get_environment_id_from_request(
                request,
                project.organization_id,
            )
        except Environment.DoesNotExist:
            raise ResourceDoesNotExist

        group_ids = request.GET.getlist('id')
        if not group_ids:
            return Response(status=204)

        group_list = Group.objects.filter(project=project, id__in=group_ids)
        group_ids = [g.id for g in group_list]

        if not group_ids:
            return Response(status=204)

        data = tsdb.get_range(
            model=tsdb.models.group, keys=group_ids, **self._parse_args(
                request,
                environment_id,
            )
        )

        return Response({six.text_type(k): v for k, v in data.items()})
开发者ID:Kayle009,项目名称:sentry,代码行数:27,代码来源:project_group_stats.py


示例3: get

    def get(self, request, project_id):
        """
        Retrieve event counts for a project

        **Draft:** This endpoint may change in the future without notice.

        Return a set of points representing a normalized timestamp and the
        number of events seen in the period.

            {method} {path}?since=1421092384.822244&until=1434052399.443363

        Query ranges are limited to Sentry's configured time-series resolutions.

        Parameters:

        - since: a timestamp to set the start of the query
        - until: a timestamp to set the end of the query
        - resolution: an explicit resolution to search for (i.e. 10s)

        **Note:** resolution should not be used unless you're familiar with Sentry
        internals as it's restricted to pre-defined values.
        """
        project = Project.objects.get_from_cache(id=project_id)

        assert_perm(project, request.user, request.auth)

        data = tsdb.get_range(model=tsdb.models.project, keys=[project.id], **self._parse_args(request))[project.id]

        return Response(data)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:29,代码来源:project_stats.py


示例4: get

    def get(self, request, team_id):
        team = Team.objects.get(id=team_id)

        assert_perm(team, request.user, request.auth)

        projects = Project.objects.get_for_user(
            team=team,
            user=request.user,
        )

        if not projects:
            return Response([])

        data = tsdb.get_range(
            model=tsdb.models.project,
            keys=[p.id for p in projects],
            **self._parse_args(request)
        ).values()

        summarized = []
        for n in range(len(data[0])):
            total = sum(d[n][1] for d in data)
            summarized.append((data[0][n][0], total))

        return Response(summarized)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:25,代码来源:team_stats.py


示例5: get

    def get(self, request, group):
        data = tsdb.get_range(
            model=tsdb.models.group,
            keys=[group.id],
            **self._parse_args(request)
        )[group.id]

        return Response(data)
开发者ID:280185386,项目名称:sentry,代码行数:8,代码来源:group_stats.py


示例6: check_project_alerts

def check_project_alerts(project_id, **kwargs):
    """
    Given 'when' and 'count', which should signify recent times we compare it to
    historical data for this project and if over a given threshold, create an
    alert.
    """
    from sentry.app import tsdb
    from sentry.constants import DEFAULT_ALERT_PROJECT_THRESHOLD
    from sentry.models import ProjectOption, Alert

    threshold, min_events = ProjectOption.objects.get_value(
        project_id, 'alert:threshold', DEFAULT_ALERT_PROJECT_THRESHOLD)

    if not threshold and min_events:
        return

    end = datetime.now().replace(tzinfo=utc) - timedelta(seconds=10)
    start = end - timedelta(minutes=5)

    results = [v for _, v in tsdb.get_range(
        tsdb.models.project,
        [project_id],
        start=start,
        end=end,
        rollup=10,
    )[project_id]]

    half_intervals = int(len(results) / 2)
    previous_data, current_data = results[:half_intervals], results[half_intervals:]

    if not current_data:
        return

    current_avg = sum(current_data) / len(current_data)

    # if there first few points within previous data are empty, assume that the
    # project hasn't been active long enough for rates to be valid
    if not any(previous_data[:3]):
        return

    if min_events > current_avg:
        return

    mean = math.mean(previous_data)
    dev = math.mad(previous_data)
    previous_avg = (mean + dev * 2)

    pct_increase = (current_avg / previous_avg * 100) - 100

    logger.info('Rate of events for project %d changed from %.2f to %2.f',
        project_id, previous_avg, current_avg)

    if pct_increase > threshold and current_avg > previous_avg:
        Alert.maybe_alert(
            project_id=project_id,
            message='Rate of events increased from %.2f to %.2f' % (previous_avg, current_avg),
        )
开发者ID:BlueMoebius,项目名称:sentry,代码行数:57,代码来源:check_alerts.py


示例7: organizations

def organizations(metrics, since, until):
    """
    Fetch metrics for organizations.
    """
    from django.utils import timezone
    from sentry.app import tsdb
    from sentry.models import Organization

    stdout = click.get_text_stream('stdout')
    stderr = click.get_text_stream('stderr')

    def aggregate(series):
        return sum(value for timestamp, value in series)

    metrics = OrderedDict((name, getattr(tsdb.models, name)) for name in metrics)
    if not metrics:
        return

    if until is None:
        until = timezone.now()

    if since is None:
        since = until - timedelta(minutes=60)

    if until < since:
        raise click.ClickException('invalid time range provided: {} to {}'.format(since, until))

    stderr.write(
        'Dumping {} from {} to {}...\n'.format(
            ', '.join(metrics.keys()),
            since,
            until,
        ),
    )

    objects = Organization.objects.all()

    for chunk in chunked(objects, 100):
        instances = OrderedDict((instance.pk, instance) for instance in chunk)

        results = {}
        for metric in metrics.values():
            results[metric] = tsdb.get_range(metric, instances.keys(), since, until)

        for key, instance in six.iteritems(instances):
            values = []
            for metric in metrics.values():
                values.append(aggregate(results[metric][key]))

            stdout.write(
                '{} {} {}\n'.format(
                    instance.id,
                    instance.slug,
                    ' '.join(map(six.binary_type, values)),
                ),
            )
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:56,代码来源:tsdb.py


示例8: get

    def get(self, request):
        key = request.GET['key']

        data = tsdb.get_range(
            model=tsdb.models.internal,
            keys=[key],
            **self._parse_args(request)
        )[key]

        return Response(data)
开发者ID:280185386,项目名称:sentry,代码行数:10,代码来源:internal_stats.py


示例9: get

    def get(self, request, organization_slug):
        organization = Organization.objects.get_from_cache(
            slug=organization_slug,
        )

        assert_perm(organization, request.user, request.auth)

        group = request.GET.get('group')
        if not group:
            keys = [organization.id]
        elif group == 'project':
            team_list = Team.objects.get_for_user(
                organization=organization,
                user=request.user,
            )

            project_list = []
            for team in team_list:
                project_list.extend(Project.objects.get_for_user(
                    team=team,
                    user=request.user,
                ))
            keys = [p.id for p in project_list]
        else:
            raise ValueError('Invalid group: %s' % group)

        if not keys:
            return Response([])

        stat = request.GET.get('stat', 'received')
        if stat == 'received':
            if group == 'project':
                stat_model = tsdb.models.project_total_received
            else:
                stat_model = tsdb.models.organization_total_received
        elif stat == 'rejected':
            if group == 'project':
                stat_model = tsdb.models.project_total_rejected
            else:
                stat_model = tsdb.models.organization_total_rejected
        else:
            raise ValueError('Invalid stat: %s' % stat)

        data = tsdb.get_range(
            model=stat_model,
            keys=keys,
            **self._parse_args(request)
        )

        if not group:
            data = data[organization.id]

        return Response(data)
开发者ID:PostPCEra,项目名称:sentry,代码行数:53,代码来源:organization_stats.py


示例10: prepare_project_series

def prepare_project_series(start__stop, project, rollup=60 * 60 * 24):
    start, stop = start__stop
    resolution, series = tsdb.get_optimal_rollup_series(start, stop, rollup)
    assert resolution == rollup, 'resolution does not match requested value'
    clean = functools.partial(clean_series, start, stop, rollup)
    return merge_series(
        reduce(
            merge_series,
            map(
                clean,
                tsdb.get_range(
                    tsdb.models.group,
                    list(
                        project.group_set.filter(
                            status=GroupStatus.RESOLVED,
                            resolved_at__gte=start,
                            resolved_at__lt=stop,
                        ).values_list('id', flat=True),
                    ),
                    start,
                    stop,
                    rollup=rollup,
                ).values(),
            ),
            clean([(timestamp, 0) for timestamp in series]),
        ),
        clean(
            tsdb.get_range(
                tsdb.models.project,
                [project.id],
                start,
                stop,
                rollup=rollup,
            )[project.id],
        ),
        lambda resolved, total: (
            resolved,
            total - resolved,  # unresolved
        ),
    )
开发者ID:Kayle009,项目名称:sentry,代码行数:40,代码来源:reports.py


示例11: get

    def get(self, request, project):
        group_ids = request.GET.getlist('id')
        if not group_ids:
            return Response(status=204)

        group_list = Group.objects.filter(project=project, id__in=group_ids)
        group_ids = [g.id for g in group_list]

        if not group_ids:
            return Response(status=204)

        data = tsdb.get_range(model=tsdb.models.group, keys=group_ids, **self._parse_args(request))

        return Response({six.text_type(k): v for k, v in data.items()})
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:14,代码来源:project_group_stats.py


示例12: get

    def get(self, request, group_id):
        group = Group.objects.get(
            id=group_id,
        )

        assert_perm(group, request.user, request.auth)

        data = tsdb.get_range(
            model=tsdb.models.group,
            keys=[group.id],
            **self._parse_args(request)
        )[group.id]

        return Response(data)
开发者ID:CrazyLionHeart,项目名称:sentry,代码行数:14,代码来源:group_stats.py


示例13: get

    def get(self, request, project_id):
        project = Project.objects.get(
            id=project_id,
        )

        assert_perm(project, request.user)

        data = tsdb.get_range(
            model=tsdb.models.project,
            keys=[project.id],
            **self._parse_args(request)
        )[project.id]

        return Response(data)
开发者ID:catufunwa,项目名称:sentry,代码行数:14,代码来源:project_stats.py


示例14: get

    def get(self, request, team):
        """
        Retrieve Event Counts for a Team
        ````````````````````````````````

        .. caution::
           This endpoint may change in the future without notice.

        Return a set of points representing a normalized timestamp and the
        number of events seen in the period.

        Query ranges are limited to Sentry's configured time-series
        resolutions.

        :pparam string organization_slug: the slug of the organization.
        :pparam string team_slug: the slug of the team.
        :qparam string stat: the name of the stat to query (``"received"``,
                             ``"rejected"``)
        :qparam timestamp since: a timestamp to set the start of the query
                                 in seconds since UNIX epoch.
        :qparam timestamp until: a timestamp to set the end of the query
                                 in seconds since UNIX epoch.
        :qparam string resolution: an explicit resolution to search
                                   for (eg: ``10s``).  This should not be
                                   used unless you are familiar with Sentry's
                                   internals as it's restricted to pre-defined
                                   values.
        :auth: required
        """
        projects = Project.objects.get_for_user(
            team=team,
            user=request.user,
        )

        if not projects:
            return Response([])

        data = list(tsdb.get_range(
            model=tsdb.models.project,
            keys=[p.id for p in projects],
            **self._parse_args(request)
        ).values())

        summarized = []
        for n in range(len(data[0])):
            total = sum(d[n][1] for d in data)
            summarized.append((data[0][n][0], total))

        return Response(summarized)
开发者ID:ForkRepo,项目名称:sentry,代码行数:49,代码来源:team_stats.py


示例15: with_event_counts

def with_event_counts(project_list):
    from sentry.app import tsdb

    end = timezone.now()
    start = end - datetime.timedelta(days=1)

    tsdb_results = tsdb.get_range(
        model=tsdb.models.project,
        keys=[p.id for p in project_list],
        start=start,
        end=end,
    )

    for project in project_list:
        yield project, sum(t[1] for t in tsdb_results[project.id])
开发者ID:CrazyLionHeart,项目名称:sentry,代码行数:15,代码来源:sentry_admin_helpers.py


示例16: get

    def get(self, request, project):
        """
        Retrieve Event Counts for a Project
        ```````````````````````````````````

        .. caution::
           This endpoint may change in the future without notice.

        Return a set of points representing a normalized timestamp and the
        number of events seen in the period.

        Query ranges are limited to Sentry's configured time-series
        resolutions.

        :pparam string organization_slug: the slug of the organization.
        :pparam string project_slug: the slug of the project.
        :qparam string stat: the name of the stat to query (``"received"``,
                             ``"rejected"``, ``"blacklisted"``, ``generated``)
        :qparam timestamp since: a timestamp to set the start of the query
                                 in seconds since UNIX epoch.
        :qparam timestamp until: a timestamp to set the end of the query
                                 in seconds since UNIX epoch.
        :qparam string resolution: an explicit resolution to search
                                   for (eg: ``10s``).  This should not be
                                   used unless you are familiar with Sentry's
                                   internals as it's restricted to pre-defined
                                   values.
        :auth: required
        """
        stat = request.GET.get('stat', 'received')
        if stat == 'received':
            stat_model = tsdb.models.project_total_received
        elif stat == 'rejected':
            stat_model = tsdb.models.project_total_rejected
        elif stat == 'blacklisted':
            stat_model = tsdb.models.project_total_blacklisted
        elif stat == 'generated':
            stat_model = tsdb.models.project
        else:
            raise ValueError('Invalid stat: %s' % stat)

        data = tsdb.get_range(
            model=stat_model,
            keys=[project.id],
            **self._parse_args(request)
        )[project.id]

        return Response(data)
开发者ID:280185386,项目名称:sentry,代码行数:48,代码来源:project_stats.py


示例17: get_stats

def get_stats(request, organization, team=None, project=None):
    minutes = int(request.REQUEST.get('minutes', 15))

    if not team and project:
        project_list = [project]
    elif team:
        project_list = Project.objects.get_for_user(team=team, user=request.user)
    else:
        return HttpResponse(status=400)

    cutoff = timedelta(minutes=minutes)

    end = timezone.now()
    start = end - cutoff

    # TODO(dcramer): this is used in an unreleased feature. reimplement it using
    # new API and tsdb
    results = tsdb.get_range(
        model=tsdb.models.project,
        keys=[p.id for p in project_list],
        start=start,
        end=end,
    )
    num_events = 0
    for project, points in results.iteritems():
        num_events += sum(p[1] for p in points)

    # XXX: This is too slow if large amounts of groups are resolved
    # TODO(dcramer); move this into tsdb
    num_resolved = Group.objects.filter(
        project__in=project_list,
        status=GroupStatus.RESOLVED,
        resolved_at__gte=start,
    ).aggregate(t=Sum('times_seen'))['t'] or 0

    data = {
        'events': num_events,
        'resolved': num_resolved,
    }

    response = HttpResponse(json.dumps(data))
    response['Content-Type'] = 'application/json'

    return response
开发者ID:brettlangdon,项目名称:sentry,代码行数:44,代码来源:api.py


示例18: prepare_project_calendar_series

def prepare_project_calendar_series(interval, project):
    start, stop = get_calendar_query_range(interval, 3)

    rollup = 60 * 60 * 24
    series = tsdb.get_range(
        tsdb.models.project,
        [project.id],
        start,
        stop,
        rollup=rollup,
    )[project.id]

    return clean_calendar_data(
        project,
        series,
        start,
        stop,
        rollup,
    )
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:19,代码来源:reports.py


示例19: get

    def get(self, request, team):
        """
        Retrieve event counts for a team

        **Draft:** This endpoint may change in the future without notice.

        Return a set of points representing a normalized timestamp and the
        number of events seen in the period.

            {method} {path}?since=1421092384.822244&until=1434052399.443363

        Query ranges are limited to Sentry's configured time-series resolutions.

        Parameters:

        - since: a timestamp to set the start of the query
        - until: a timestamp to set the end of the query
        - resolution: an explicit resolution to search for (i.e. 10s)

        **Note:** resolution should not be used unless you're familiar with Sentry
        internals as it's restricted to pre-defined values.
        """
        projects = Project.objects.get_for_user(
            team=team,
            user=request.user,
        )

        if not projects:
            return Response([])

        data = tsdb.get_range(
            model=tsdb.models.project,
            keys=[p.id for p in projects],
            **self._parse_args(request)
        ).values()

        summarized = []
        for n in range(len(data[0])):
            total = sum(d[n][1] for d in data)
            summarized.append((data[0][n][0], total))

        return Response(summarized)
开发者ID:ChadKillingsworth,项目名称:sentry,代码行数:42,代码来源:team_stats.py


示例20: get_attrs

    def get_attrs(self, item_list, user):
        attrs = super(StreamGroupSerializer, self).get_attrs(item_list, user)

        # we need to compute stats at 1d (1h resolution), and 14d
        group_ids = [g.id for g in item_list]
        if self.stats_period:
            days = 14 if self.stats_period == '14d' else 1
            now = timezone.now()
            stats = tsdb.rollup(tsdb.get_range(
                model=tsdb.models.group,
                keys=group_ids,
                end=now,
                start=now - timedelta(days=days),
            ), 3600 * days)

            for item in item_list:
                attrs[item].update({
                    'stats': stats[item.id],
                })
        return attrs
开发者ID:jonashaag,项目名称:sentry,代码行数:20,代码来源:group.py



注:本文中的sentry.app.tsdb.get_range函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tsdb.incr函数代码示例发布时间:2022-05-27
下一篇:
Python ratelimiter.is_limited函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap