Ingest Data into OpenTSDB

EMQX supports integration with OpenTSDB. You can save MQTT messages to OpenTSDB for subsequent analysis and retrieval.

TIP

EMQX Enterprise Edition features. EMQX Enterprise Edition provides comprehensive coverage of key business scenarios, rich data integration, product-level reliability, and 24/7 global technical support. Experience the benefits of this enterprise-ready MQTT messaging platformIngest Data into OpenTSDB - 图1 (opens new window) today.

Prerequisites

Features List

Quick Start Tutorial

This section introduces how to configure the OpenTSDB data bridge, covering topics like how to set up the OpenTSDB server, create data bridges and rules for forwarding data to OpenTSDB and test the data bridges and rules.

This tutorial assumes that you run both EMQX and OpenTSDB on the local machine. If you have OpenTSDB and EMQX running remotely, adjust the settings accordingly.

The data reported by the client in this tutorial is as follows:

  • Topic: t/opents
  • Payload:
  1. {
  2. "metric": "cpu",
  3. "tags": {
  4. "host": "serverA"
  5. },
  6. "value":12
  7. }

Install OpenTSDB

Install OpenTSDB via Docker, and then run the docker image.

  1. docker pull petergrace/opentsdb-docker
  2. docker run -d --name opentsdb -p 4242:4242 petergrace/opentsdb-docker

Create OpenTSDB Data Bridge

  1. Go to EMQX Dashboard, and click Integration -> Data Bridge.

  2. Click Create on the top right corner of the page.

  3. In the Create Data Bridge page, click to select OpenTSDB, and then click Next.

  4. Input a name for the data bridge. The name should be a combination of upper/lower case letters and numbers.

  5. Input the connection information:

    • URL: Input http://127.0.0.1:4242, or the actual URL if the OpenTSDB server runs remotely.
    • Leave other options as default.
  6. Advanced settings (optional): Choose whether to use sync or async query mode as needed. For details, see the relevant configuration information in Data Integration.

  7. Before clicking Create, you can click Test Connectivity to test that the bridge can connect to the OpenTSDB server.

  8. Then click Create to finish the creation of the data bridge.

    A confirmation dialog will appear and ask if you like to create a rule using this data bridge, you can click Create Rule to continue creating rules to specify the data to be saved into OpenTSDB. You can also create rules by following the steps in Create Rules for OpenTSDB Data Bridge.

Now the OpenTSDB data bridge should appear in the data bridge list (Integration -> Data Bridge) with Resource Status as Connected.

Create Rules for OpenTSDB Data Bridge

Now that you have successfully created the data bridge to OpenTSDB, you can continue to create rules to specify the data to be saved into OpenTSDB.

  1. Go to EMQX Dashboard, and click Integration -> Rules.

  2. Click Create at the upper right corner of the page.

  3. Input my_rule as the rule ID, and set the rules in the SQL Editor using the following statement, which means the MQTT messages under topic t/# will be saved to OpenTSDB.

    Note: If you want to specify your own SQL syntax, make sure that you have included all fields required by the data bridge in the SELECT part.

    1. SELECT
    2. payload.metric as metric, payload.tags as tags, payload.value as value
    3. FROM
    4. "t/#"
  4. Click the Add Action button, select Forwarding with Data Bridge from the dropdown list, and then select the data bridge you just created under Data Bridge. Click the Add button.

  5. Click the Create button to finish the setup.

Now you have successfully created the data bridge to OpenTSDB. You can click Integration -> Flows to view the topology. It can be seen that the messages under topic t/# are sent and saved to OpenTSDB after parsing by rule my_rule.

Test the Data Bridges and Rules

Use MQTTX to publish a message on topic t/opents.

  1. mqttx pub -i emqx_c -t t/opents -m '{"metric":"cpu","tags":{"host":"serverA"},"value":12}'

Check the running status of the data bridge, there should be one new incoming and one new outgoing message.

Check whether the data is written into the OpenTSDB:

  1. curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" http://localhost:4242/api/query -d '{
  2. "start": "1h-ago",
  3. "queries": [
  4. {
  5. "aggregator": "last",
  6. "metric": "cpu",
  7. "tags": {
  8. "host": "*"
  9. }
  10. }
  11. ],
  12. "showTSUIDs": "true",
  13. "showQuery": "true",
  14. "delete": "false"
  15. }'

The formatted output of the query result is as follows:

  1. [
  2. {
  3. "metric": "cpu",
  4. "tags": {
  5. "host": "serverA"
  6. },
  7. "aggregateTags": [],
  8. "query": {
  9. "aggregator": "last",
  10. "metric": "cpu",
  11. "tsuids": null,
  12. "downsample": null,
  13. "rate": false,
  14. "filters": [
  15. {
  16. "tagk": "host",
  17. "filter": "*",
  18. "group_by": true,
  19. "type": "wildcard"
  20. }
  21. ],
  22. "percentiles": null,
  23. "index": 0,
  24. "rateOptions": null,
  25. "filterTagKs": [
  26. "AAAB"
  27. ],
  28. "explicitTags": false,
  29. "useFuzzyFilter": true,
  30. "preAggregate": false,
  31. "rollupUsage": null,
  32. "rollupTable": "raw",
  33. "showHistogramBuckets": false,
  34. "useMultiGets": true,
  35. "tags": {
  36. "host": "wildcard(*)"
  37. },
  38. "histogramQuery": false
  39. },
  40. "tsuids": [
  41. "000001000001000001"
  42. ],
  43. "dps": {
  44. "1683532519": 12
  45. }
  46. }
  47. ]%