• EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

Syntheticモニタリングのベストプラクティスガイド

Syntheticsモニタリングを使用すると、アプリを監視しテストできるので、エンドユーザーに影響が生じる前に問題に対処できます。そのフルパワーを活用するための5つのヒントを以下にご紹介します。

1. Syntheticモニターを選択

Syntheticsモニターは、ウェブサイトのパフォーマンスを測定し、読み込み時間、稼働時間、平均ダウンロードサイズの集計値をキャプチャする仮想ブラウザです。また、ダウンタイムインシデントと各ページリソースに関する詳細な統計情報にもアクセスできます。

モニターの対象と方法に応じて、7種類のSyntheticモニターから選択できます。たとえば、ステップモニターは、コードを記述せずにスクリプト化されたブラウザとして、本質的に機能するものを作成するための優れた方法です。Syntheticモニターの自動管理をお探しの場合は、当社のNerdGraph APIを使用すると、API呼び出しを通じてSyntheticモニターを作成、更新、削除できます。

Syntheticモニターを追加する

  1. モニターを追加するには、one.newrelic.com > All capabilities > Synthetic Monitoringの順に移動します。(EUベースのアカウントをお持ちの場合は、one.eu.newrelic.comに移動します。)Create monitorをクリックします。
  1. モニタータイプを選択し、すべての必須フィールドに入力します。

  2. タグの追加、期間の変更、または別のランタイムバージョンの選択ができます。pingおよび単純なブラウザモニターでは、検証文字列を追加できます。高度なオプションを使用して、次のタイプの応答検証の部分文字列モニタリングを有効にすることができます。

    • SSL検証(Pingとシンプルブラウザ用)。このオプションは、SSL証明書チェーンの有効性を検証します。次の構文を実行することによって複製することができます。

      bash
      $
      openssl s_client -servername {YOUR_HOSTNAME} -connect {YOUR_HOSTNAME}:443 -CApath /etc/ssl/certs > /dev/null
    • HEADリクエストのバイパス(Pingモニター用)。このオプションは、デフォルトのHEADリクエストをスキップし、その代わりにpingチェックを含むGET動詞を使用します。HEADリクエストが失敗した場合、GETリクエストは常時発生します。

    • Redirect is Failure(Ping用)。Redirect is Failureが有効になっているときにリダイレクト結果が発生すると、Syntheticsモニターはリダイレクトにしたがって、結果のURLをチェックするのではなく、結果をエラーとして分類します。

  3. モニターを実行するロケーションを選択します。誤検出を避けるために、少なくとも3つの場所を選択するようにしてください。つまり、少なくとも1つの場所が成功した結果を返す場合、エンドポイントは稼働しており、アラートのトリガーを回避できます。

  4. モニターの種類に応じて、モニターの保存検証スクリプトの記述のいずれかを行うよう求められます。

  5. 結果を受け取ったら、概要ページで表示します。

2. Syntheticモニターの概要ページを表示する

概要ページには、Syntheticモニターのステータスに関する情報が表示されます。アラートをトリガーするアクティブなインシデントが作成された場合は、このモニターのクリティカルなアラートをクリックして新しいタブで開きます。また、クリックしてページ上部のすべてのモニターのアラートポリシーを管理すると、モニターのすべてのアラートポリシーにアクセスすることもできます。

3. アプリケーションのパフォーマンスの全体像を把握

アプリケーションのパフォーマンス結果を継続的に確認して、ウェブサービスが適切に機能し、期待どおりに動作し、エラーが発生しないようにする必要があります。Syntheticsモニタリングでは、選択した場所ごとにウェブアプリケーションで自動テストを実行することで確実にします。Syntheticsモニターは、ダウンタイムインスタンス(「違反」と呼びます)を記録し、各ページリソースの集計数、結果、および詳細な統計情報を収集します。

モニターの障害をすばやく検出するには、合成モニターインデックスページを使用して、未解決の違反があるモニター、24時間にわたる成功率、障害が発生した場所の数、モニター期間、モニタータイプを確認できます。モニターをクリックすると概要ページが表示され、特定のモニターがどこで故障しているか、なぜ故障しているか(最後のエラーメッセージ、エラーレスポンスコード、ドメイン別の期間)などを評価するための情報が表示され、経時的なアプリケーションのパフォーマンスに関する深い洞察が提供されます。

モニターをエンティティのリストで表示する

4. 個々のモニター結果を表示する

世界中のさまざまな地域からアクセスされるウェブアプリのパフォーマンスを確認する必要があります。結果ページには、開発から本番までのすべてがユーザー体験にいかに影響するかが表示されます。リストされているものを並べ替えて、問題のある領域や異常結果を特定できます。場所別にフィルタリングして、さまざまな場所からのモニターのパフォーマンスを比較してみてください。これを行うには、以下を実行します。

  1. one.newrelic.com > All capabilities > Synthetic Monitoringの順に移動します。
  2. one.newrelic.com > All capabilities >から
  3. モニターをクリックし、結果をクリックします。

結果から監視対象の各場所に対して最も遅いページロードの最新のビューが得られます。

5. 各リソースのロードタイムへの影響を把握する

Syntheticsリソースページには、ウェブサイトのさまざまなコンポーネント(CSS、JavaScript、画像、HTMLなど)が全体的な負荷にどのように影響しているかが表示されます。ランタイムに収集される詳細なメトリクスを掘り下げて調べ、サードパーティリソースによって費やされる時間に関するパフォーマンス情報を検出し、各リソースのHTTP応答コードを特定することができます。これを行うには、以下を実行します。

  1. one.newrelic.comにアクセスし、Synthetic Monitoringをクリックします。
  2. モニタードロップダウンメニューから、モニターを選択します。
  3. モニターをクリックし、リソースをクリックします。

6. スクリプト化ブラウザテストを設定して開発する

スクリプト化ブラウザを使用して、Selenium JavaScript Webdriverバインディングで複雑な監視ワークフローを構築できます。たとえば、アプリケーションにログインして特定のリンクにナビゲートし、ページ要素がロードされてアサーションを追加するのを待機できます。これを行うには、以下を実行します。

  1. one.newrelic.com > All capabilities > Synthetic Monitoringの順に移動します。
  2. Create monitorボタンをクリックします。
  3. モニターの名前と詳細(sitename.comのスクリプト化ブラウザなど)を入力します
  4. モニターを実行する場所 (ムンバイ、ソウル、コロンバス、モントリオールなど) を選択します。
  5. ここからモニターを実行する頻度 (5分など) を選択します。
  6. パフォーマンスインシデントが発生した際にチームに送信するアラート通知を設定します。
  7. これでスクリプトを記述する準備ができました。(以下は、newrelic.comのパフォーマンスをテストし、特定の要素が読み込まれたことを確認するスクリプトの例です。)
/**
* Script Name: Best Practices - Chrome 100
* Author: New Relic
* Version: 1.4
* Purpose: best practices example
* Reference: https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/scripting-monitors/synthetic-scripted-browser-reference-monitor-versions-chrome-100/
*/
// -------------------- CONSTANTS
const SCRIPT_NAME = "Best Practices - Chrome 100" // name to record in script log
const IMPLICIT_TIMEOUT = 3000 // default implicit timeout is 10 seconds, 4 seconds x 14 findElement operations = 42 seconds, assuming all operations time out
const PAGE_LOAD_TIMEOUT = 60000 // default page load timeout is 60 seconds, fail early to prevent long duration timeouts
const SCRIPT_TIMEOUT = 20000 // default script timeout is 30 seconds
const USER_AGENT = "default" // set the user agent for Chrome
const PROTOCOL = "https://" // set the protocol
const USERNAME = "" // username:
const PASSWORD = "" // password@
const DOMAIN = "docs.newrelic.com" // your domain
const PATH = "/docs/new-relic-solutions/get-started/intro-new-relic/" // path to main page
const CHECK = "Need some inspiration first? Check out this intro video." // text to match on page
const AUTH = USERNAME + PASSWORD
const MAIN_URL = PROTOCOL + AUTH + DOMAIN + PATH
// -------------------- DEPENDENCIES
var assert = require("assert")
// -------------------- CONFIGURATION
await $webDriver.manage().setTimeouts({
implicit: IMPLICIT_TIMEOUT, // sets element load timeout
pageLoad: PAGE_LOAD_TIMEOUT, // sets page load timeout
script: SCRIPT_TIMEOUT // sets script timeout
})
// -------------------- VARIABLES
var By = $selenium.By
var loc = {
video: By.css("#gatsby-focus-wrapper > div.css-1uz5ayg > div > main > div > article > div > div > div:nth-child(1) > div > p:nth-child(2)"),
start: By.css("#gatsby-focus-wrapper > div.css-1uz5ayg > div > main > div > h1"),
e: [
{ step: 'signup', selector: By.css("#sign-up-for-new-relic-if-you-havent-already") },
{ step: 'ingest', selector: By.css("#ingest-some-data") },
{ step: 'dashboards', selector: By.css("#check-out-some-dashboards") },
{ step: 'data', selector: By.css("#add-more-data") },
{ step: 'alerting', selector: By.css("#set-up-alerting") },
{ step: 'users', selector: By.css("#add-users") }
]
}
// -------------------- FUNCTIONS
// for backwards compatibility with legacy runtimes
async function waitForAndFindElement(locator, timeout) {
const element = await $webDriver.wait(
$selenium.until.elementLocated(locator),
timeout,
"Timed-out waiting for element to be located using: " + locator
)
await $webDriver.wait(
$selenium.until.elementIsVisible(element),
timeout,
"Timed-out waiting for element to be visible using ${element}"
)
return await $webDriver.findElement(locator)
}
// -------------------- START OF SCRIPT
console.log("Starting synthetics script: " + SCRIPT_NAME)
// confirm timeouts are set
const {implicit, pageLoad, script} = await $webDriver.manage().getTimeouts()
console.log("Timeouts are set to:")
console.log(" IMPLICIT: " + implicit / 1000 + "s")
console.log(" PAGE LOAD: " + pageLoad / 1000 + "s")
console.log(" SCRIPT: " + script / 1000 + "s")
// Setting User Agent is not then-able, so we do this first (if defined and not default)
if (USER_AGENT && 0 !== USER_AGENT.trim().length && USER_AGENT != "default") {
$headers.add("User-Agent", USER_AGENT)
console.log("Setting User-Agent to " + USER_AGENT)
}
// if an error happens at any step, script execution is halted and a failed result is returned
console.log("1. get: " + MAIN_URL)
await $webDriver.get(MAIN_URL)
console.log("2. waitForAndFindElement: " + loc.video)
const textBlock = await waitForAndFindElement(loc.video, IMPLICIT_TIMEOUT)
console.log("3. getText: " + CHECK)
const text = await textBlock.getText()
console.log("4. assert.equal: " + text)
assert.equal(text, CHECK, "validation text not found")
console.log("5. waitForAndFindElement: " + loc.start)
const platformMenu = await waitForAndFindElement(loc.start, IMPLICIT_TIMEOUT)
console.log("6. takeScreenshot")
await $webDriver.takeScreenshot()
console.log("7. findElement")
loc.e.forEach(async function (nr, i) {
let n = i + 1
try{
// verify each asset has loaded
console.log(" " + n + ". " + nr.step + ": " + nr.selector)
await $webDriver.findElement(nr.selector)
}catch(exception){
console.error("Failure in Step 7." + n)
throw exception
}
})
Copyright © 2024 New Relic株式会社。

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