{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"redocly_category":"Integrations","type":"markdown"},"seo":{"title":"Java Apps Import Integration","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":"java-apps-import-integration","__idx":0},"children":["Java Apps Import Integration"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure Data provides Treasure Agent (",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/installing-td-agent"},"children":["td-agent"]},"), to collect server-side logs and events and seamlessly import the data from Java applications."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Basic knowledge of Java."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Basic knowledge of Maven."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Basic knowledge of Treasure Data."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Java 6 or higher (for local testing)."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"installing-td-agent","__idx":2},"children":["Installing td-agent"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Install td-agent on your application servers. td-agent sits within your application servers, focusing on uploading application logs to the cloud."," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/image2021-4-15_14-42-29.e1f0a3881144362a280b1dabf16baeb3de7e9fc7265ee930c72b1518d9bbaf83.10220609.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"http://github.com/treasure-data/td-logger-java"},"children":["td-logger-java"]}," library enables Java applications to post records to their local td-agent. td-agent, in turn, receives the records, buffers them, and uploads the data to the cloud every 5 minutes. Because the daemon runs on a local node, the logging latency is negligible."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"install-options","__idx":3},"children":["Install Options"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["td-agent, a stable distribution package of fluentd, is installed automatically when you use the package management software for each platform like rpm/deb/dmg. Refer to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/installing-td-agent"},"children":["Installing td-agent"]}," for detailed instructions for each platform."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"modifying-etctd-agenttd-agentconf","__idx":4},"children":["Modifying /etc/td-agent/td-agent.conf"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Specify your API key by setting the API key option in your /etc/td-agent/td-agent.conf file."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"# Input from Logger Libraries\nsource\n  type forward\n  port 24224\n</source>\n\n# Treasure Data Output\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":["Restart your agent when the following lines are in place:"]},{"$$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 accepts data via port 24224, buffers it (",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["var/log/td-agent/buffer/td"]},"), and automatically uploads it into the cloud."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"using-td-logger-java","__idx":5},"children":["Using td-logger-java"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If you need an all-in-one JAR file, see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://search.maven.org/artifact/com.treasuredata/td-logger"},"children":["https://search.maven.org/artifact/com.treasuredata/td-logger"]}," Download the latest version of the td-logger-{version_number}-jar-with-dependencies.jar file."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If you are using Maven, add the following lines to pom.xml in your Maven project:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"dependencies\n  ...\n  dependency\n    groupIdcom.treasuredata</groupId>\n    artifactIdtd-logger</artifactId>\n    version${logger.version}</version>\n  </dependency>\n  ...\n</dependencies>\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Configure your ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["treasure-data.properties"]}," file using the following commands:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"td.logger.agentmode=true\ntd.logger.agent.host=localhost\ntd.logger.agent.port=24224\ntd.logger.agent.tag=td\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You must ensure that the ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["treasure-data.properties"]}," file is referenced by your Java classpath."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Insert the following lines into your application. For more information regarding the API, see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/treasure-data/td-logger-java"},"children":["here"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"import com.treasure_data.logger.TreasureDataLogger;\npublic class Main {\n  private static TreasureDataLogger LOG;\n  static {\n    try {\n      Properties props = System.getProperties();\n      props.load(Main.class.getClassLoader().getResourceAsStream(\"treasure-data.properties\"));\n      LOG = TreasureDataLogger.getLogger(\"test_db\");\n    } catch (IOException e) {\n      // do something\n    }\n  }\n  public void doApp() {\n    Map<String, Object> data = new HashMap<String, Object>();\n    data.put(\"from\", \"userA\");\n    data.put(\"to\", \"userB\");\n    LOG.log(\"follow\", data);\n  }\n}\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"confirming-data-import","__idx":6},"children":["Confirming Data Import"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Execute the program."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"# Post a record\n$ java -jar test.jar\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Sending a SIGUSR1 signal flushes td-agent’s buffer. The upload starts immediately."]},{"$$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":"Heading","attributes":{"level":4,"id":"from-treasure-console","__idx":7},"children":["From Treasure Console"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To confirm that your data has been uploaded successfully, check your dataset from the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://console.treasuredata.com/app/databases"},"children":["web browser"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"from-cli","__idx":8},"children":["From CLI"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Or, issue the ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["td tables"]}," command if you have a ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-product-documentation/configuring-authentication-for-td-using-the-td-toolbelt"},"children":["td CLI client"]},"."]},{"$$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":"Heading","attributes":{"level":1,"id":"production-deployments","__idx":9},"children":["Production Deployments"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"high-availability-configurations-of-td-agent","__idx":10},"children":["High-Availability Configurations of td-agent"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For high-traffic websites (more than 5 application nodes), use a high availability configuration of td-agent to improve data transfer reliability and query performance."]},{"$$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":"monitoring-td-agent","__idx":11},"children":["Monitoring td-agent"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Monitoring td-agent itself is also important. For general monitoring methods for td-agent, see ",{"$$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 is fully open-sourced under the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://www.fluentd.org/"},"children":["Fluentd project"]},"."]}]},"headings":[{"value":"Java Apps Import Integration","id":"java-apps-import-integration","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":1},{"value":"Installing td-agent","id":"installing-td-agent","depth":1},{"value":"Install Options","id":"install-options","depth":2},{"value":"Modifying /etc/td-agent/td-agent.conf","id":"modifying-etctd-agenttd-agentconf","depth":2},{"value":"Using td-logger-java","id":"using-td-logger-java","depth":2},{"value":"Confirming Data Import","id":"confirming-data-import","depth":2},{"value":"From Treasure Console","id":"from-treasure-console","depth":4},{"value":"From CLI","id":"from-cli","depth":4},{"value":"Production Deployments","id":"production-deployments","depth":1},{"value":"High-Availability Configurations of td-agent","id":"high-availability-configurations-of-td-agent","depth":2},{"value":"Monitoring td-agent","id":"monitoring-td-agent","depth":2}],"frontmatter":{"seo":{"title":"Java Apps Import Integration"}},"lastModified":"2026-06-01T09:09:59.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/int/java-apps-import-integration","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}