New Relic Data API (v2)を使用して、特定の期間におけるアプリケーションの平均エラーレートを取得する例を紹介します。この値は、 APM Summary ページ の Error rate chart の上にパーセンテージで表示されます。
APIを利用するには、以下のものが必要です。
平均パーセンテージは、アプリの Summary ページ の Error rate チャートの上に表示されます。New Relic ではこの式で計算しています。
Application Error Rate = 100 * Errors/all:error_count / (HttpDispatcher:call_count + OtherTransaction/all:call_count)
APIコマンド
metric timeslice の値を取得するには、次の3つのコマンドを使用します。この例では、各コマンドに同じ時間帯を使用し、すべてを要約しています。
エラーカウントを取得するには
$curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml" \
> -H "Api-Key:<a href="/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2
$ -d 'names[]=Errors/all&values[]=error_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
"from": "2014-04-01T00:00:00+00:00",
"from": "2014-04-01T00:35:00+00:00",
"to": "2014-04-01T23:35:00+00:00",
"metrics_found": ["Errors/all"],
"to": "2014-04-01T23:35:00+00:00"
HttpDispatcher のコールカウントを取得するには (Web アプリケーション)が必要です。
$curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml" \
> -H "Api-Key:<a href="/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2
$ -d 'names[]=HttpDispatcher&values[]=call_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
"from": "2014-04-01T00:00:00+00:00",
"name": "HttpDispatcher",
"from": "2014-04-01T00:35:00+00:00",
"to": "2014-04-01T23:35:00+00:00",
"metrics_found": ["HttpDispatcher"],
"to": "2014-04-01T23:35:00+00:00"
OtherTransactionのコールカウントを取得するには (非ウェブアプリ)をご利用ください。
$curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml" \
> -H "Api-Key:<a href="/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2
$ -d 'names[]=OtherTransaction/all&values[]=call_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
"from": "2014-04-01T00:00:00+00:00",
"name": "OtherTransaction/all",
"from": "2014-04-01T00:35:00+00:00",
"to": "2014-04-01T23:35:00+00:00",
"metrics_found": ["OtherTransaction/all"],
"to": "2014-04-01T23:35:00+00:00"