• EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

이 한글 문서는 사용자의 편의를 위해 기계 번역되었습니다.

영문본과 번역본이 일치하지 않는 경우 영문본이 우선합니다. 보다 자세한 내용은 이 페이지를 방문하시기 바랍니다.

문제 신고

data_source_factory(파이썬 에이전트 API)

통사론

data_source_factory(name=None, **properties)

팩토리로 정의된 데이터 소스를 래핑합니다.

설명

데이터 소스 API는 record_custom_metric 에 의해 구현된 푸시 스타일 API가 아닌 풀 스타일 API 를 사용하여 측정항목 타임슬라이스 데이터 를 생성하는 방법을 제공합니다. 사용자 지정 메트릭에 데이터 소스를 사용하는 이유와 방법에 대한 자세한 내용은 사용자 지정 메트릭 데이터 소스 를 참조하십시오.

data_source_factory 데코레이터는 팩토리로 정의된 데이터 소스를 래핑합니다. 데코레이터는 클래스나 함수에 적용할 수 있습니다. 클래스 생성자 또는 함수는 settings (데이터 소스에 대한 구성 설정) 및 environ (데이터 소스가 사용되는 컨텍스트에 대한 정보)의 인수를 허용해야 합니다.

결과 객체는 각 샘플에 대한 메트릭과 함께 반복 가능/생성기를 직접 반환하는 호출 가능이어야 합니다.

매개변수

매개변수

설명

name

선택 과목. 데이터 소스의 이름입니다. 이것은 로깅 목적으로만 사용됩니다. 제공하지 않으면 기본적으로 데코레이트된 함수에서 파생된 호출 가능한 이름이 사용됩니다.

properties

사전

선택 과목. 데이터 소스 팩터리에 전달할 추가 속성입니다.

사전에 가능한 필드는 다음과 같습니다.

  • count
  • total
  • min
  • max
  • sum_of_squares

반환 값

함수를 반환합니다.

data_source_factory 예

예:

import os
import time
import multiprocessing
@newrelic.agent.data_source_factory(name='CPU Usage')
class CPUMetricsDataSource(object):
def __init__(self, settings, environ):
self.last_timestamp = None
self.times = None
def start(self):
self.last_timestamp = time.time()
self.times = os.times()
def stop(self):
self.last_timestamp = None
self.times = None
def __call__(self):
if self.times is None:
return
now = time.time()
new_times = os.times()
elapsed_time = now - self.last_timestamp
user_time = new_times[0] - self.times[0]
utilization = user_time / (elapsed_time*multiprocessing.cpu_count())
self.last_timestamp = now
self.times = new_times
yield ('Custom/CPU/User Time', user_time)
yield ('Custom/CPU/User/Utilization', utilization)
newrelic.agent.register_data_source(CPUMetricsDataSource)
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.