本文整理汇总了Python中sentry.app.tsdb.get_range函数的典型用法代码示例。如果您正苦于以下问题:Python get_range函数的具体用法?Python get_range怎么用?Python get_range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_range函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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()})
示例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)
示例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)
示例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)
示例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),
)
示例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)),
),
)
示例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)
示例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)
示例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
),
)
示例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()})
示例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)
示例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)
示例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)
示例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])