Use the logstash-input-datahub plug-in
The logstash-input-datahub plug-in reads data from DataHub and sends it to a destination such as Elasticsearch.
Prerequisites
Before you begin, ensure that you have:
Installed the
logstash-input-datahubplug-in. For more information, see Install and remove a plug-in.Activated DataHub, created a project and a topic, and imported data to the topic. For more information, see Get started with DataHub.
Configure the pipeline
Create a pipeline by following Use configuration files to manage pipelines. When configuring the pipeline, set the parameters described in the Parameters section. After you save and deploy the pipeline, Logstash reads data from DataHub and transfers it to the destination.
The following example shows a complete pipeline configuration:
input {
datahub {
access_id => "<your-access-key-id>"
access_key => "<your-access-key-secret>"
endpoint => "<datahub-endpoint>"
project_name => "test_project"
topic_name => "test_topic"
interval => 5
# cursor: start point per shard (leave blank to consume from the beginning)
#cursor => {
# "0"=>"20000000000000000000000003110091"
# "2"=>"20000000000000000000000003110091"
# "1"=>"20000000000000000000000003110091"
# "4"=>"20000000000000000000000003110091"
# "3"=>"20000000000000000000000003110000"
#}
shard_ids => []
pos_file => "/ssd/1/<logstash-cluster-id>/logstash/data/<filename>"
}
}
output {
elasticsearch {
hosts => ["http://es-cn-mp91cbxsm000c****.elasticsearch.aliyuncs.com:9200"]
user => "elastic"
password => "your_password"
index => "datahubtest"
document_type => "_doc"
}
}By default, Alibaba Cloud Logstash supports data transmission only within the same virtual private cloud (VPC). If your DataHub data source is on the Internet, configure a Network Address Translation (NAT) gateway for your Logstash cluster. For more information, see Configure a NAT gateway for data transmission over the Internet.
Parameters
The following table describes the parameters supported by logstash-input-datahub.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
endpoint | string | Yes | — | The endpoint used to access DataHub. For more information, see Endpoints. |
access_id | string | Yes | — | The AccessKey ID of your Alibaba Cloud account. |
access_key | string | Yes | — | The AccessKey secret of your Alibaba Cloud account. |
project_name | string | Yes | — | The name of the DataHub project. |
topic_name | string | Yes | — | The name of the DataHub topic. |
pos_file | string | Yes | — | The path to the checkpoint file. Checkpoints take priority over cursor for resuming consumption. |
retry_times | number | No | -1 | The number of retries. -1 means no limit. 0 disables retries. A positive integer sets the exact retry count. |
retry_interval | number | No | — | The interval between retries, in seconds. |
shard_ids | array | No | [] (all shards) | The shards to consume. Leave blank to consume all shards. |
cursor | string | No | — (from beginning) | The start point for consumption per shard. Leave blank to consume from the beginning. |
enable_pb | boolean | No | true | Whether to use Protocol Buffers (Protobuf) for data transfer. Set to false if Protobuf is not supported in your environment. |
compress_method | string | No | — (no compression) | The compression algorithm for data transfer. Valid values: lz4, deflate. |
print_debug_info | boolean | No | false | Whether to print DataHub debugging information. Setting this to true generates a large volume of output. Use only for script debugging. |