{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Node.js アプリケーション インポート インテグレーション","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"nodejs-アプリケーション-インポート-インテグレーション","__idx":0},"children":["Node.js アプリケーション インポート インテグレーション"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure Data は ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/about-treasure-data-s-server-side-agent"},"children":["td-agent"]}," を提供しており、サーバーサイドのログとイベントを収集し、Node.js アプリケーションからデータをシームレスにインポートできます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["fluent-logger-node ライブラリにより、Node.js アプリケーションはローカルの td-agent にレコードを送信できます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["td-agent は、5 分ごとにデータをクラウドにアップロードします。デーモンがローカルノードで実行されているため、ログの遅延は無視できます。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下のトピックに進んでください:"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"前提条件","__idx":1},"children":["前提条件"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Node.js と NPM の基本的な知識。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://toolbelt.treasuredata.com/"},"children":["TD Toolbelt"]}," を含む Treasure Data の基本的な知識。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Node.js 0.6 以上（ローカルテスト用）。"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"td-agent-のインストール","__idx":2},"children":["td-agent のインストール"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["アプリケーションサーバーに ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td-agent"]}," をインストールします。td-agent はアプリケーションサーバー内に配置され、アプリケーションログをクラウドにアップロードすることに重点を置いています。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/image2020-12-2_14-6-46.1754f4e3154420d54cc976b16d454ef773c83ad5fc4b8580d99a87302c614932.7c05c672.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/fluent/fluent-logger-node"},"children":["fluent-logger-node"]}," ライブラリにより、Node.js アプリケーションはローカルの td-agent にレコードを送信できます。td-agent は、5 分ごとにデータをクラウドにアップロードします。デーモンがローカルノードで実行されているため、ログの遅延は無視できます。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"td-agent-インストールオプション","__idx":3},"children":["td-agent インストールオプション"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td-agent"]}," をインストールするには、環境に基づいて以下のコマンドのいずれかを実行します。エージェントプログラムは、rpm/deb/dmg などの各プラットフォームのパッケージ管理ソフトウェアを使用して自動的にインストールされます。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"rhelcentos-567","__idx":4},"children":["RHEL/CentOS 5,6,7"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"$ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"ubuntu-と-debian","__idx":5},"children":["Ubuntu と Debian"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"# 18.04 Bionic\n$ curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-bionic-td-agent3.sh | sh\n# 16.04 Xenial (64bit only)\n$ curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-xenial-td-agent3.sh | sh\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"amazon-linux","__idx":6},"children":["Amazon Linux"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Amazon Linux 1 または Amazon Linux 2 を選択できます。",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/installing-td-agent-on-aws-linux"},"children":["Installing td-agent on Amazon Linux"]}," を参照してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"macos-x-1011","__idx":7},"children":["MacOS X 10.11+"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"$ open 'https://td-agent-package-browser.herokuapp.com/3/macosx/td-agent-3.1.1-0.dmg'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["MacOS X 10.11.1 (El Capitan) ではいくつかのセキュリティ変更が導入されました。td-agent のインストール後、",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["/Library/LaunchDaemons/td-agent.plist"]}," ファイルを編集して ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["/usr/sbin/td-agent"]}," を ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["/opt/td-agent/usr/sbin/td-agent"]}," に変更してください。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"windows-server-2012","__idx":8},"children":["Windows Server 2012+"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Windows のインストールには、以下に詳述されている手順が必要です:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.fluentd.org/installation/install-by-msi"},"children":["Installing Treasure Agent using .msi Installer (Windows)"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"opscode-chef-repository","__idx":9},"children":["Opscode Chef Repository"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$ echo 'cookbook \"td-agent\"' >> Berksfile\n$ berks install\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/treasure-data/elastic-beanstalk-td-agent"},"children":["AWS Elastic Beanstalk"]}," もサポートされています。Windows は現在サポートされていません。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"etctd-agenttd-agentconf-の変更","__idx":10},"children":["/etc/td-agent/td-agent.conf の変更"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["apikey"]}," オプションを設定して API キーを指定します。API キーは Treasure コンソール のプロフィールから確認できます。td-agent.conf ファイルで ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["apikey"]}," オプションを設定します。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"# Treasure Data Input and Output\nsource\n  type forward\n  port 24224\n</source>\n<match td.*.*>\n  type tdlog\n  endpoint api.treasuredata.com\n  apikey YOUR_API_KEY\n  auto_create_table\n  buffer_type file\n  buffer_path /var/log/td-agent/buffer/td\n  use_ssl true\n</match>\n"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["YOUR_API_KEY"]}," should be your actual apikey string. You can retrieve your API key from your profiles in Treasure Console. Using a ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/my-settings/getting-your-api-keys"},"children":["write-only API key"]}," is recommended."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下の行が配置されたら、エージェントを再起動してください。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"# Linux\n$ sudo /etc/init.d/td-agent restart\n\n# MacOS X\n$ sudo launchctl unload /Library/LaunchDaemons/td-agent.plist\n$ sudo launchctl load /Library/LaunchDaemons/td-agent.plist\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["td-agent はポート 24224 経由でデータを受け入れ、データをバッファリングし (",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["var/log/td-agent/buffer/td"]},")、自動的にデータをクラウドにアップロードします。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"fluent-logger-node-の使用","__idx":11},"children":["fluent-logger-node の使用"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"最新バージョンの取得","__idx":12},"children":["最新バージョンの取得"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/fluent/fluent-logger-node"},"children":["fluent-logger-node"]}," の最新バージョンを取得します。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"サンプルアプリケーション","__idx":13},"children":["サンプルアプリケーション"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["fluent-logger-node を使用したサンプル ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"http://expressjs.com/"},"children":["Express"]}," アプリは以下の通りです:"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"packagejson","__idx":14},"children":["package.json"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"{\n  \"name\": \"node-example\",\n  \"version\": \"0.0.1\",\n  \"dependencies\": {\n    \"express\": \"2.5.9\",\n    \"fluent-logger\": \"0.1.0\"\n  }\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["次に ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["npm"]}," を使用して依存関係をローカルにインストールします:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$ npm install\nfluent-logger@0.1.0 ./node_modules/fluent-logger\nexpress@2.5.9 ./node_modules/express\n|-- qs@0.4.2\n|-- mime@1.2.4\n|-- mkdirp@0.3.0\n|-- connect@1.8.6 (formidable@1.0.9)\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"webjs","__idx":15},"children":["web.js"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["これは最もシンプルな Web アプリです。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"var express = require('express');\nvar app = express.createServer(express.logger());\n\nvar logger = require('fluent-logger');\nlogger.configure('td.test_db', {host: 'localhost', port: 24224});\n\napp.get('/', function(request, response) {\n  logger.emit('follow', {from: 'userA', to: 'userB'});\n  response.send('Hello World!');\n});\nvar port = process.env.PORT || 3000;\napp.listen(port, function() {\n  console.log(\"Listening on \" + port);\n});\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"データインポートの確認","__idx":16},"children":["データインポートの確認"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["アプリを実行し、ブラウザで ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["http://localhost:3000/"]}," にアクセスします。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$ node web.js\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["SIGUSR1 シグナルが送信され、td-agent のバッファがフラッシュされます。アップロードは直ちに開始されます。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"# Linux\n$ kill -USR1 `cat /var/run/td-agent/td-agent.pid`\n\n# MacOS X\n$ sudo kill -USR1 `sudo launchctl list | grep td-agent | cut -f 1`\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["データが正常にアップロードされたことを確認するには、次のように ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["td tables"]}," コマンドを実行します:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$ td tables\n+------------+------------+------+-----------+\n| Database   | Table      | Type | Count     |\n+------------+------------+------+-----------+\n| test_db    | follow     | log  | 1         |\n+------------+------------+------+-----------+\n"},"children":[]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":""},"children":[]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["post() の最初の引数はデータベース名とテーブル名を決定します。",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td.test\\_db.test\\_table"]}," を指定すると、データはデータベース *test_db* 内のテーブル *test_table* にインポートされます。これらはアップロード時に自動的に作成されます。"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"本番環境への展開","__idx":17},"children":["本番環境への展開"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"td-agent-の高可用性構成","__idx":18},"children":["td-agent の高可用性構成"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["高トラフィックの Web サイト（5 つ以上のアプリケーションノード）の場合は、td-agent の高可用性構成を使用して、データ転送の信頼性とクエリパフォーマンスを向上させます。"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/configuring-td-agent-for-high-availability"},"children":["High-Availability Configurations of td-agent"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"td-agent-の監視","__idx":19},"children":["td-agent の監視"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["td-agent 自体の監視も重要です。td-agent の一般的な監視方法については、以下のドキュメントを参照してください。"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/monitoring-td-agent"},"children":["Monitoring td-agent"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["td-agent は ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"http://fluentd.org/"},"children":["Fluentd プロジェクト"]},"の下で完全にオープンソース化されています。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"次のステップ","__idx":20},"children":["次のステップ"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["従来の RDBMS よりも柔軟なスキーマメカニズムを提供しています。クエリには、Hive と Presto のクエリ言語を活用します。"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/schema-management"},"children":["Schema Management"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/data-workbench/queries/trino/quickstart"},"children":["Presto Query Language"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/data-workbench/queries/hive/quickstart"},"children":["Hive Query Language"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/apis/td-api"},"children":["Programmatic Access with REST API and its Bindings"]}]}]}]},"headings":[{"value":"Node.js アプリケーション インポート インテグレーション","id":"nodejs-アプリケーション-インポート-インテグレーション","depth":1},{"value":"前提条件","id":"前提条件","depth":2},{"value":"td-agent のインストール","id":"td-agent-のインストール","depth":2},{"value":"td-agent インストールオプション","id":"td-agent-インストールオプション","depth":2},{"value":"RHEL/CentOS 5,6,7","id":"rhelcentos-567","depth":3},{"value":"Ubuntu と Debian","id":"ubuntu-と-debian","depth":3},{"value":"Amazon Linux","id":"amazon-linux","depth":3},{"value":"MacOS X 10.11+","id":"macos-x-1011","depth":3},{"value":"Windows Server 2012+","id":"windows-server-2012","depth":3},{"value":"Opscode Chef Repository","id":"opscode-chef-repository","depth":3},{"value":"/etc/td-agent/td-agent.conf の変更","id":"etctd-agenttd-agentconf-の変更","depth":2},{"value":"fluent-logger-node の使用","id":"fluent-logger-node-の使用","depth":2},{"value":"最新バージョンの取得","id":"最新バージョンの取得","depth":4},{"value":"サンプルアプリケーション","id":"サンプルアプリケーション","depth":4},{"value":"package.json","id":"packagejson","depth":4},{"value":"web.js","id":"webjs","depth":4},{"value":"データインポートの確認","id":"データインポートの確認","depth":2},{"value":"本番環境への展開","id":"本番環境への展開","depth":1},{"value":"td-agent の高可用性構成","id":"td-agent-の高可用性構成","depth":2},{"value":"td-agent の監視","id":"td-agent-の監視","depth":2},{"value":"次のステップ","id":"次のステップ","depth":1}],"frontmatter":{"seo":{"title":"Node.js アプリケーション インポート インテグレーション"}},"lastModified":"2026-06-01T09:34:27.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/int/node-js-apps-import-integration","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}