Azure AppFabric Service Bus でクラウド型PC監視サービスを作ってみる
-
Upload
tomoya-nakahara -
Category
Technology
-
view
6.224 -
download
4
description
Transcript of Azure AppFabric Service Bus でクラウド型PC監視サービスを作ってみる
AZURE APPFABRIC SERVICE BUS でクラウド型PC監視サービスを作ってみる
26 August 2010 #jazug中原知也 @tnkhr01
自己紹介
中原 知也 (Twitter : @tnkhr01)
新しいモノに目がない
Azure歴1年(2009CTP~)
本職は仮想化系営業/SE/ソリューション開発
社内でAzureの話があがると駆けつける人
Tech・Days 2010 でAzure賞を頂きました→
26-Aug-10@tnkhr01 2
クラウド型PC監視サービス?
Agent
監視対象PC(Agent起動) 26-Aug-10@tnkhr01 3
監視用PC
InternetExplorer
Tool
Windows Azure
クラウド型PC監視サービス?
Windows Azure Platform AppFabric Service Bus
EndPoint
Agent
監視対象PC(Agent起動)
WebRole
WCF
WCF
監視用PC
Tool
26-Aug-10@tnkhr01 4
InternetExplorer
WCF
AppFabric SDK V1.0EchoSample
Windows Azure Platform AppFabricService Bus
EndPoint
Service.exe Client.exe
Echo:「Hello Azure!」
http://www.microsoft.com/downloads/details.aspx?FamilyID=39856a03-1490-4283-908f-c8bf0bfad8a5
26-Aug-10@tnkhr01 5
Return:「Hello Azure!」
クラウド(Service Bus)側の実装
26-Aug-10@tnkhr01 6
終了
3. Connection数を決める
2. Regionを決める
1. Namespaceを決める
Service(監視Agent)側の実装
public string Echo(string text) {
ProcessStartInfo psi = new ProcessStartInfo();psi.FileName = System.Environment.
GetEnvironmentVariable("ComSpec");psi.RedirectStandardInput = false;psi.RedirectStandardOutput = true;psi.UseShellExecute = false;psi.CreateNoWindow = true;psi.Arguments = @"/c " + text;
Process p = Process.Start(psi);string results = p.StandardOutput.ReadToEnd();p.WaitForExit();
return results;}
コマンド 効果
dir ls
typeperf CPU使用率など
systeminfo PCスペックなど
sc query state= all サービス一覧
<実装方法>
受け取ったEchoをコマンドと見立てて実行し、標準出力をクライアントに返す(だけ)。
<メリット>
楽。
<デメリット>
セキュリティ的に激しく危険。(実際は構文解析+フィルタが必須)
26-Aug-10@tnkhr01 7
<実装方法>
コマンドをEchoとして監視Agentに送り込み、標準出力を受け取って整形・表示する。
<メリット>
標準出力のままでよければコード変更の必要なし (…?)
<デメリット>
HTML化(テーブル表現等)は手間。作りこむとOS Version依存など。(PowerShell、WMI+WSHなどうまく使いたいところ)
Client(監視用Tool)側の実装
26-Aug-10@tnkhr01 8
<実装方法>
コマンドをEchoとして監視Agentに送り込み、標準出力を受け取って整形・表示する。
<メリット>
標準出力のままでよければコード変更の必要なし (…?)
<デメリット>
HTML化(テーブル表現等)は手間。作りこむとOS Version依存など。(PowerShell、WMI+WSHなどうまく使いたいところ)
Client(監視用Tool)側の実装
26-Aug-10@tnkhr01 9
typeperf -sc 1 "\Processor(*)\% Processor Time”
"(PDH-CSV 4.0)","\\E4300-02\Processor(0)\% Processor Time","\\E4300-02\Processor(1)\% Processor Time","\\E4300-02\Processor(_Total)\% Processor Time""08/25/2010 00:36:54.941","7.964674","31.363486","19.664075"
コマンドは、正しく完了しました。
CPU使用率(コア1,2,合計)
sc query state= all
…SERVICE_NAME: W3SVCDISPLAY_NAME: World Wide Web Publishing Service
TYPE : 20 WIN32_SHARE_PROCESSSTATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)WIN32_EXIT_CODE : 0 (0x0)SERVICE_EXIT_CODE : 0 (0x0)CHECKPOINT : 0x0WAIT_HINT : 0x0
SERVICE_NAME: WAS…
プロセス稼働状況
…と表示してほしいが?
大きなデータを送受信すると…
Error: 操作 'Echo' の応答メッセージの本文をシリアル化解除しているときにエラーが発生しました。XML データの読み取り中に、最大文字列コンテンツ長のクォータ (8192)を超えました。このクォータを増やすには、XML リーダーの作成時に使用される XmlDictionaryReaderQuotas オブジェクトの MaxStringContentLength プロパティを変更してください。
26-Aug-10@tnkhr01 10
Client/Program.cs (問題の箇所)
// create the channel factory loading the configuration
ChannelFactory<IEchoChannel> channelFactory =
new ChannelFactory<IEchoChannel>
("RelayEndpoint", new EndpointAddress(serviceUri));
// apply the Service Bus credentials
channelFactory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);
// create and open the client channel
IEchoChannel channel = channelFactory.CreateChannel();
channel.Open();
…26-Aug-10@tnkhr01 11
Client/App.config (bindingの確認)
<client>
<!-- Application Endpoint -->
<endpoint
name="RelayEndpoint“contract="Microsoft.ServiceBus.Samples.IEchoContract“binding="netTcpRelayBinding"/>
</client>
26-Aug-10@tnkhr01 12
Client/Program.cs (変更後)
// create the channel factory loading the configuration
NetTcpRelayBinding binding = new NetTcpRelayBinding();
binding.Name = "RelayEndpoint";
binding.MaxReceivedMessageSize = 819200;
binding.MaxBufferSize = 819200;
binding.ReaderQuotas.MaxStringContentLength = 819200;
binding.ReaderQuotas.MaxNameTableCharCount = 819200;
ChannelFactory<IEchoChannel> channelFactory =
new ChannelFactory<IEchoChannel>
(binding, new EndpointAddress(serviceUri));
// apply the Service Bus credentials
… 「msdn セキュリティに関するデータの考慮事項」は要確認http://msdn.microsoft.com/ja-jp/library/ms733135.aspx
26-Aug-10@tnkhr01 13
DEMO
26-Aug-10@tnkhr01 14
Windows AzureWindows Azure Platform AppFabric Service Bus
EndPoint
Agent
監視対象Win7 PC(Agent起動)
WebRole
WCF
WCF
ガラケー@tnkhr01
ブラウザ
まとめ
Service Bus単体でも立派なネットワーククラウドサービスとして使える
マイクロソフトの優秀なサンプルを使えばほとんど手を加えずに手軽に新しいツールが作れる
Service Busを使う際はWCFも勉強しておくべき(反省)
26-Aug-10@tnkhr01 15
26-Aug-10@tnkhr01 16