2

I want to use logstash in my golangApp.

/etc/logstash/conf.d/first-pipeline.conf

input {
  tcp {
    port => 5959
    codec => json
  }
}
#filter {}
output {
    elasticsearch {
        hosts => [ "localhost:9200" ]
    }
}

and command for run logstash :

/usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/first-pipeline.conf --path.settings=/etc/logstash

    Sending Logstash logs to /var/log/logstash which is now configured via log4j2.properties
    [2018-12-09T09:11:14,984][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
    [2018-12-09T09:11:14,995][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.5.1"}
    [2018-12-09T09:11:16,968][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>4, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
    [2018-12-09T09:11:17,347][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://localhost:9200/]}}
    [2018-12-09T09:11:17,356][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://localhost:9200/, :path=>"/"}
    [2018-12-09T09:11:17,589][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://localhost:9200/"}
    [2018-12-09T09:11:17,655][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
    [2018-12-09T09:11:17,660][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>6}
    [2018-12-09T09:11:17,692][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//localhost:9200"]}
    [2018-12-09T09:11:17,730][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
    [2018-12-09T09:11:17,786][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"_default_"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
    [2018-12-09T09:11:17,809][INFO ][logstash.inputs.tcp      ] Automatically switching from json to json_lines codec {:plugin=>"tcp"}
    [2018-12-09T09:11:17,862][INFO ][logstash.inputs.tcp      ] Starting tcp input listener {:address=>"0.0.0.0:5959", :ssl_enable=>"false"}
    [2018-12-09T09:11:18,097][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x42d68f8e run>"}
    [2018-12-09T09:11:18,157][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
    [2018-12-09T09:11:18,329][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}

Code in golang:

import (
    "encoding/json"
    "fmt"
    "github.com/heatxsink/go-logstash"
    "time"
)
func main() {

l := logstash.New("0.0.0.0", 5959, 5)
_, err := l.Connect()
if err != nil {
    fmt.Println(err)
}


dataMap := map[string]int{"apple": 5, "lettuce": 7}
jsonMap, _ := json.Marshal(dataMap)

err = l.Writeln(string(jsonMap))
if err != nil {
    fmt.Println(err)
}
}

when I try to request for logstash in app .show this error end of terminal:

[2018-12-09T09:12:41,954][ERROR][logstash.inputs.tcp ] Error in Netty pipeline: java.io.IOException: Connection reset by peer

Every things are in my local system. Can help me , please !

1
  • You are not closing the connection gracefully. If you call Close in the connection returned by Connect the error should go away. Commented Dec 9, 2018 at 11:27

1 Answer 1

1

I found the answer on this page :

https://github.com/logstash-plugins/logstash-input-tcp/issues/132

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.