Syntheticsモニタリングを使用すると、アプリを監視しテストできるので、エンドユーザーに影響が生じる前に問題に対処できます。そのフルパワーを活用するための5つのヒントを以下にご紹介します。
1. Syntheticモニターを選択
Syntheticsモニターは、ウェブサイトのパフォーマンスを測定し、読み込み時間、稼働時間、平均ダウンロードサイズの集計値をキャプチャする仮想ブラウザです。また、ダウンタイムインシデントと各ページリソースに関する詳細な統計情報にもアクセスできます。
モニターの対象と方法に応じて、7種類のSyntheticモニターから選択できます。たとえば、ステップモニターは、コードを記述せずにスクリプト化されたブラウザとして、本質的に機能するものを作成するための優れた方法です。Syntheticモニターの自動管理をお探しの場合は、当社のNerdGraph APIを使用すると、API呼び出しを通じてSyntheticモニターを作成、更新、削除できます。
Syntheticモニターを追加する
モニターを追加するには、
one.newrelic.com > All capabilities > Synthetic Monitoring
の順に移動します。( EUベースのアカウントをお持ちの場合は、
に移動します。)
Create monitor
をクリックします。
モニタータイプを選択し、すべての必須フィールドに入力します。
タグの追加、期間の変更、または別のランタイムバージョンの選択ができます。pingおよび単純なブラウザモニターでは、検証文字列を追加できます。高度なオプションを使用して、次のタイプの応答検証の部分文字列モニタリングを有効にすることができます。
Verify SSL (for ping and simple browser). このオプションは、SSL証明書チェーンの有効性を検証します。次の構文を実行することによって複製することができます。
bash$openssl s_client -servername {YOUR_HOSTNAME} -connect {YOUR_HOSTNAME}:443 -CApath /etc/ssl/certs > /dev/nullBypass HEAD request (for ping monitors). このオプションは、デフォルトのHEADリクエストをスキップし、その代わりにpingチェックを含むGET動詞を使用します。HEADリクエストが失敗した場合、GETリクエストは常時発生します。
Redirect is Failure (for ping).
Redirect is Failure
が有効になっているときにリダイレクト結果が発生すると、Syntheticsモニターはリダイレクトにしたがって、結果のURLをチェックするのではなく、結果をエラーとして分類します。
モニターを実行するロケーションを選択します。誤検出を避けるために、少なくとも3つの場所を選択するようにしてください。つまり、少なくとも1つの場所が成功した結果を返す場合、エンドポイントは稼働しており、アラートのトリガーを回避できます。
モニターの種類に応じて、Save monitor、 Validate、Write scriptのいずれかを行うよう求められます。
結果を受け取ったら、概要ページで表示します。
2. Syntheticモニターの概要ページを表示する
概要ページには、Syntheticモニターのステータスに関する情報が表示されます。アラートをトリガーするアクティブなインシデントが作成された場合は、このモニターのクリティカルなアラートをクリックして新しいタブで開きます。また、クリックしてページ上部のすべてのモニターのアラートポリシーを管理すると、モニターのすべてのアラートポリシーにアクセスすることもできます。
3. アプリケーションのパフォーマンスの全体像を把握
アプリケーションのパフォーマンス結果を継続的に確認して、ウェブサービスが適切に機能し、期待どおりに動作し、エラーが発生しないようにする必要があります。Syntheticsモニタリングでは、選択した場所ごとにウェブアプリケーションで自動テストを実行することで確実にします。Syntheticsモニターは、ダウンタイムインスタンス(「違反」と呼びます)を記録し、各ページリソースの集計数、結果、および詳細な統計情報を収集します。
モニターの障害をすばやく検出するには、合成モニターインデックスページを使用して、未解決の違反があるモニター、24時間にわたる成功率、障害が発生した場所の数、モニター期間、モニタータイプを確認できます。モニターをクリックすると概要ページが表示され、特定のモニターがどこで故障しているか、なぜ故障しているか(最後のエラーメッセージ、エラーレスポンスコード、ドメイン別の期間)などを評価するための情報が表示され、経時的なアプリケーションのパフォーマンスに関する深い洞察が提供されます。
モニターをエンティティのリストで表示する
4. 個々のモニター結果を表示する
世界中のさまざまな地域からアクセスされるウェブアプリのパフォーマンスを確認する必要があります。結果ページには、開発から本番までのすべてがユーザー体験にいかに影響するかが表示されます。リストされているものを並べ替えて、問題のある領域や異常結果を特定できます。場所別にフィルタリングして、さまざまな場所からのモニターのパフォーマンスを比較してみてください。これを行うには、以下を実行します。
one.newrelic.com > All capabilities > Synthetic Monitoring
に移動します。
Monitor
をクリックし、
Results
をクリックします。
結果から監視対象の各場所に対して最も遅いページロードの最新のビューが得られます。
5. 各リソースのロードタイムへの影響を把握する
Syntheticsリソースページには、ウェブサイトのさまざまなコンポーネント(CSS、JavaScript、画像、HTMLなど)が全体的な負荷にどのように影響しているかが表示されます。ランタイムに収集される詳細なメトリクスを掘り下げて調べ、サードパーティリソースによって費やされる時間に関するパフォーマンス情報を検出し、各リソースのHTTP応答コードを特定することができます。これを行うには、以下を実行します。
に移動し、次に
Synthetic Monitoring
をクリックします。
Monitors
ドロップダウンメニューから、モニターを選択します。
Monitor
をクリックし、
Resources
をクリックします。
6. スクリプト化ブラウザテストを設定して開発する
スクリプト化ブラウザを使用して、Selenium JavaScript Webdriverバインディングで複雑な監視ワークフローを構築できます。たとえば、アプリケーションにログインして特定のリンクにナビゲートし、ページ要素がロードされてアサーションを追加するのを待機できます。これを行うには、以下を実行します。
one.newrelic.com > All capabilities > Synthetic Monitoring
に移動します。
Create Monitor
ボタンをクリックします
モニターの名前と詳細(
sitename.com
のスクリプト化ブラウザなど)を入力しますモニターを実行する場所 (ムンバイ、ソウル、コロンバス、モントリオールなど) を選択します。
ここからモニターを実行する頻度 (5分など) を選択します。
パフォーマンスインシデントが発生した際にチームに送信するアラート通知を設定します。
これでスクリプトを記述する準備ができました。(以下は、newrelic.comのパフォーマンスをテストし、特定の要素が読み込まれたことを確認するスクリプトの例です。)
/** * Script Name: Best Practices - Chrome 100 * Author: New Relic * Version: 1.5 * Purpose: best practices example * Reference: https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/scripting-monitors/synthetic-scripted-browser-reference-monitor-versions-chrome-100/ */
// -------------------- CONSTANTSconst SCRIPT_NAME = "Best Practices - Chrome 100" // name to record in script logconst IMPLICIT_TIMEOUT = 3000 // default implicit timeout is 10 seconds, 3 seconds x 8 findElement operations = 24 seconds, assuming all operations time outconst PAGE_LOAD_TIMEOUT = 60000 // default page load timeout is 60 seconds, fail early to prevent long duration timeoutsconst SCRIPT_TIMEOUT = 20000 // default script timeout is 30 secondsconst USER_AGENT = "default" // set the user agent for Chromeconst PROTOCOL = "https://" // set the protocolconst USERNAME = "" // username:const PASSWORD = "" // password@const DOMAIN = "docs.newrelic.com" // your domainconst PATH = "/docs/new-relic-solutions/get-started/intro-new-relic/" // path to main pageconst CHECK = "Need some inspiration first? Check out this intro video." // text to match on pageconst AUTH = USERNAME + PASSWORDconst MAIN_URL = PROTOCOL + AUTH + DOMAIN + PATH
// -------------------- DEPENDENCIESvar assert = require("assert")
// -------------------- CONFIGURATIONawait $webDriver.manage().setTimeouts({ implicit: IMPLICIT_TIMEOUT, // sets element load timeout pageLoad: PAGE_LOAD_TIMEOUT, // sets page load timeout script: SCRIPT_TIMEOUT // sets script timeout})
// -------------------- VARIABLESvar By = $selenium.Byvar 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 runtimesasync 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// Start loggingvar start_time = new Date()console.log("Starting synthetics script: " + SCRIPT_NAME)
// confirm timeouts are setconst {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 returnedconsole.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 }})
// End loggingvar end_time = new Date()
// Calculate the durationvar script_duration = end_time - start_time
// Log the timesconsole.log("Start time: " + start_time)console.log("End time: " + end_time)console.log("Duration: " + script_duration)