33.4.2. 단계별 가이드


이 고객이 원하는 사용자 지정 분석을 달성하기 위한 단계는 다음과 같습니다.

  • 전체 애플리케이션 목록을 검색합니다. 이 작업에는 pagination이 필요하지만 볼 수 있듯이 간단한 것입니다.
def api_call_applications_list(domain, provider_key)
  done = false
  res = Array.new
  page = 1

      while !done
    url = "https://#{domain}/admin/api/applications.xml?provider_key=#{provider_key}&page=#{page}&per_page=100"
    page += 1
    response = RestClient.get url
    raise Exception.new("Wrong response code (#{response.code}) in request #{url}") if response.code!=200
    document = Nokogiri::XML(response.to_str)    done = document.xpath("applications/@current_page").text == document.xpath("applications/@total_pages").text
    document.xpath("//application").each do |item|
      app = Hash.new
      app["created_at"] = DateTime.parse(item.xpath("created_at").text)
      app["plan_name"] = item.xpath("plan/name").text
      app["service_id"] = item.xpath("plan/service_id").text
      app["account_id"] = item.xpath("user_account_id").text
      app["id"] = item.xpath("id").text
      res << app
    end
  end
  return res
end
Copy to Clipboard Toggle word wrap
  • 기준을 충족하지 않는 애플리케이션을 필터링합니다. 즉, 계획이 "예: 평가"여야 하며 10일보다 최신 상태여야 합니다.
def filter_applications(domain, provider_key, plan_name, num_of_days)
  res = api_call_applications_list(domain, provider_key)
  res.each do |item|
    res.delete(item) if item["plan_name"] != plan_name
    res.delete(item) if item["created_at"] > (DateTime.now - num_of_days)
  end
  return res
end
Copy to Clipboard Toggle word wrap
  • 그런 다음 기준을 충족하는 각 애플리케이션에 대해 지난 10일 동안 애플리케이션의 히트 횟수를 의미합니다.
def api_call_application_usage(domain, provider_key, application_id, metric, from, to, granularity)
  url = "https://#{domain}/stats/applications/#{application_id}/usage.xml?provider_key=#{provider_key}&metric_name=#{metric}&since=#{from}&until=#{to}&granularity=#{granularity}"
  response = RestClient.get url
  raise Exception.new("Wrong response code (#{response.code}) in request #{url}") if response.code!=200
  document = Nokogiri::XML(response.to_str)
  return document.xpath("//usage/data/values").text.split(",")
end
Copy to Clipboard Toggle word wrap
  • 마지막으로 개발자의 정보가 계정 오브젝트에 저장되므로 계정에 애플리케이션을 상호 참조해야 합니다.
def api_call_account_read(domain, provider_key, account_id)
  url = "https://#{domain}/admin/api/accounts/#{account_id}.xml?provider_key=#{provider_key}"
  response = RestClient.get url
  raise Exception.new("Wrong response code (#{response.code}) in request #{url}") if response.code!=200
  document = Nokogiri::XML(response.to_str)
  account = Hash.new
  account["email"] = document.xpath("//users/user/email").text
  account["name"] = document.xpath("//users/user/first_name").text + " " + document.xpath("//users/user/last_name").text
  return account
end
Copy to Clipboard Toggle word wrap

그리고 이것은 거의 모든 것입니다. 이제 모든 것을 함께 넣기만 하면 됩니다 ( 전체 스크립트를 Gist로가져올 수 있음) 그리고 완료된 것입니다. 3scale의 기본 제공 분석에서 아직 사용할 수 없는 정보를 가져오는 스크립트가 있습니다.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat