0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

REST API を使って Yellowfin 監視 - 詳細情報

Posted at

はじめに

『REST API を使って Yellowfin の死活監視』で、ポーリング監視に適した API を紹介しました。今回は、もう少し詳細な情報を返す REST API を紹介します。
定期的なシステム稼働情報を管理する場合や、不定期に稼働状況を確認する目的に活用できます。

アクセストークンの取得

詳細な情報を取得するためには、リソースにアクセスするためのアクセストークンが必要です。
アクセストークンは下記のコードで取得することができます。コードの詳細な説明は、こちらをご確認ください。

アクセストークン
//変数の宣言
$adminId = 'admin@yellowfin.com.au';
$adminPassword = 'test';
$time = ceil(microtime(true)*1000);
$url = 'http://yellowfin:8080/api/refresh-tokens';
$url2 = 'http://yellowfin:8080/api/access-tokens';
$refreshToken = "";
$accessToken = "";

//リフレッシュトークン
$header = array(
    'Authorization:YELLOWFIN ts='.$time.', nonce=123',
    'Accept:application/vnd.yellowfin.api-v2+json',
    'Content-Type:application/json;charset=UTF-8'
);

$body = array(
    'userName'=>$adminId,
    'password'=>$adminPassword
);
$body_json = json_encode($body, JSON_PRETTY_PRINT);

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_close($ch);
$result = curl_exec($ch);
$json_result = json_decode($result);
$refreshToken = $json_result->securityToken;

//アクセストークン
$header2 = array(
    'Authorization:YELLOWFIN ts='.$time.', nonce=123, token='.$refreshToken,
    'Accept:application/vnd.yellowfin.api-v2+json',
    'Content-Type:application/json'
);

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_HTTPHEADER, $header2);
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch2, CURLOPT_POSTFIELDS, '');
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_URL, $url2);
curl_close($ch2);
$result2 = curl_exec($ch2);
$json_result2 = json_decode($result2);
$accessToken = $json_result2->securityToken;

稼働状況の取得

上記で取得したアクセストークンを伴い、GET で API にアクセスして情報を要求します。

稼働状況
$url3 = 'http://yellowfin:8080/api/health/';
$header3 = array(
    'Authorization:YELLOWFIN ts='.$time.', nonce=123, token='.$accessToken,
    'Accept:application/vnd.yellowfin.api-v3+json',
    'Content-Type:application/json'
);

$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_HTTPHEADER, $header3);
curl_setopt($ch3, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch3, CURLOPT_URL, $url3);
curl_close($ch3);
$result3 = curl_exec($ch3);
$result3_json = json_encode(array_Values($result3));
echo($result3_json);

/api/health/ api を使用します。前回ポーリング監視に用いた /api/health/ping と、名前空間的には親子関係にあります。
・GET で受け渡すヘッダー情報には、先のコードで取得したアクセストークンを含みます。
・\$url3 や \$header3 の情報を用いて、curl で Yellowfin に対して GET で情報を要求します。
・レスポンスは $result3 に連装配列の形式で格納されて返ってきます。
・連装配列だと少々可読性に欠けるので、中身を見やすくするために、json_encode() で JSON 形式にしておきます。

プログラム全容

プログラムの全容は以下の通りです。

healthChech.php
<?php
//変数の宣言
$adminId = 'admin@yellowfin.com.au';
$adminPassword = 'test';
$time = ceil(microtime(true)*1000);
$url = 'http://yellowfin:8080/api/refresh-tokens';
$url2 = 'http://yellowfin:8080/api/access-tokens';
$refreshToken = "";
$accessToken = "";

//リフレッシュトークン
$header = array(
    'Authorization:YELLOWFIN ts='.$time.', nonce=123',
    'Accept:application/vnd.yellowfin.api-v2+json',
    'Content-Type:application/json;charset=UTF-8'
);

$body = array(
    'userName'=>$adminId,
    'password'=>$adminPassword
);
$body_json = json_encode($body, JSON_PRETTY_PRINT);

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_close($ch);
$result = curl_exec($ch);
$json_result = json_decode($result);
$refreshToken = $json_result->securityToken;

//アクセストークン
$header2 = array(
    'Authorization:YELLOWFIN ts='.$time.', nonce=123, token='.$refreshToken,
    'Accept:application/vnd.yellowfin.api-v2+json',
    'Content-Type:application/json'
);

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_HTTPHEADER, $header2);
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch2, CURLOPT_POSTFIELDS, '');
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_URL, $url2);
curl_close($ch2);
$result2 = curl_exec($ch2);
$json_result2 = json_decode($result2);
$accessToken=$json_result2->securityToken;

//情報取得
$url3 = 'http://yellowfin:8080/api/health/';
$header3 = array(
    'Authorization:YELLOWFIN ts='.$time.', nonce=123, token='.$accessToken,
    'Accept:application/vnd.yellowfin.api-v3+json',
    'Content-Type:application/json'
);

$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_HTTPHEADER, $header3);
curl_setopt($ch3, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch3, CURLOPT_URL, $url3);
curl_close($ch3);
$result3 = curl_exec($ch3);
$result3_json = json_encode($result3, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
echo($result3_json);
?>

動作確認

実際にプログラムを起動して、レスポンスを確認します。

healthChech.php
>php healthChech.php

メモリ使用やデータベース接続の情報が含まれていることが分かるかと思います。
また、クラスタ構成を取っている場合、既定では起動しているノード全ての情報をまとめて取得します。nodes に複数ノードの情報を含む形で表示されます。

Yellowfin の健康状態
{
	"statusCode": "OK",
	"nodes": [
		{
			"hostName": "yellowfin",
			"applicationVersion": "9.14.0",
			"statusCode": "OK",
			"availableProcessors": 14,
			"jvmMemoryInUse": 599340744,
			"jvmTotalMemory": 2006450176,
			"jvmFreeMemory": 1407109432,
			"jvmMaxMemory": 28633464832,
			"systemMemory": 33849171968,
			"webSessions": 0,
			"caches": {
				"viewCache": {
					"cacheCurrentSize": 2,
					"cacheMaxSize": 2147483647
				},
				"reportDefinitionCache": {
					"cacheCurrentSize": 15,
					"cacheMaxSize": 1000
				},
				"dashboardDefinitionCache": {
					"cacheCurrentSize": 3,
					"cacheMaxSize": 1000
				},
				"personCache": {
					"cacheCurrentSize": 1,
					"cacheMaxSize": 1000
				},
				"groupCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 1000
				},
				"documentCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 50
				},
				"reportDataCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 20
				},
				"cachedFilterCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 100
				},
				"cachedFilterQueryCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 100
				},
				"cachedFilterMetadataCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 1000
				},
				"textEntityCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 10000
				},
				"geometryCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 4000
				},
				"thumbnailCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 1000
				},
				"olapMemberCache": {
					"cacheCurrentSize": 0,
					"cacheMaxSize": 1000
				},
				"restUserCache": {
					"cacheCurrentSize": 1,
					"cacheMaxSize": 100
				}
			},
			"configDB": {
				"status": "OK",
				"maxConnections": 25,
				"minConnections": 2,
				"openConnections": 3,
				"activeConnections": 1
			}
		}
	],
	"_links": {
		"menu": {
			"href": "/api/menus/mobile-menu",
			"options": [
				"GET"
			]
		},
		"api": {
			"href": "/api",
			"options": [
				"GET"
			]
		},
		"self": {
			"href": "/api/health",
			"options": [
				"GET"
			]
		}
	}
}

最後に

REST API を使って、様々な形での Yellowfin の健康監視が可能となりました。
日ごろの運用にお役立てください。

では皆様、良いデータ分析を!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?