Cannot send logs from logstash to elasticsearch using systemctl

Hi
when i send using "bin/logstash -f /etc/logstash/conf.d/logstash.conf" I am able to send logs to elasticsearch and see the index in kibana. But I am not able to send logs from logstash to elasticsearch when I am starting logastash using systemctl ($ systemctl start logastash.service) I am running this command as root user.

root@develk:/etc/logstash# ps aux| grep logstash
logstash 31791  3.4 20.8 4812128 842684 ?      SNsl 12:15   3:58 /usr/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.compile.invokedynamic=true -Djruby.jit.threshold=0 -Djruby.regexp.interruptible=true -XX:+HeapDumpOnOutOfMemoryError -Djava.security.egd=file:/dev/urandom -Dlog4j2.isThreadContextMapInheritable=true -cp /usr/share/logstash/logstash-core/lib/jars/animal-sniffer-annotations-1.14.jar:/usr/share/logstash/logstash-core/lib/jars/commons-codec-1.13.jar:/usr/share/logstash/logstash-core/lib/jars/commons-compiler-3.1.0.jar:/usr/share/logstash/logstash-core/lib/jars/error_prone_annotations-2.0.18.jar:/usr/share/logstash/logstash-core/lib/jars/google-java-format-1.1.jar:/usr/share/logstash/logstash-core/lib/jars/gradle-license-report-0.7.1.jar:/usr/share/logstash/logstash-core/lib/jars/guava-22.0.jar:/usr/share/logstash/logstash-core/lib/jars/j2objc-annotations-1.1.jar:/usr/share/logstash/logstash-core/lib/jars/jackson-annotations-2.9.10.jar:/usr/share/logstash/logstash-core/lib/jars/jackson-core-2.9.10.jar:/usr/share/logstash/logstash-core/lib/jars/jackson-databind-2.9.10.1.jar:/usr/share/logstash/logstash-core/lib/jars/jackson-dataformat-cbor-2.9.10.jar:/usr/share/logstash/logstash-core/lib/jars/janino-3.1.0.jar:/usr/share/logstash/logstash-core/lib/jars/javassist-3.26.0-GA.jar:/usr/share/logstash/logstash-core/lib/jars/jruby-complete-9.2.9.0.jar:/usr/share/logstash/logstash-core/lib/jars/jsr305-1.3.9.jar:/usr/share/logstash/logstash-core/lib/jars/log4j-api-2.12.1.jar:/usr/share/logstash/logstash-core/lib/jars/log4j-core-2.12.1.jar:/usr/share/logstash/logstash-core/lib/jars/log4j-slf4j-impl-2.12.1.jar:/usr/share/logstash/logstash-core/lib/jars/logstash-core.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.core.commands-3.6.0.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.core.contenttype-3.4.100.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.core.expressions-3.4.300.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.core.filesystem-1.3.100.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.core.jobs-3.5.100.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.core.resources-3.7.100.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.core.runtime-3.7.0.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.equinox.app-1.3.100.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.equinox.common-3.6.0.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.equinox.preferences-3.4.1.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.equinox.registry-3.5.101.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.jdt.core-3.10.0.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.osgi-3.7.1.jar:/usr/share/logstash/logstash-core/lib/jars/org.eclipse.text-3.5.101.jar:/usr/share/logstash/logstash-core/lib/jars/reflections-0.9.11.jar:/usr/share/logstash/logstash-core/lib/jars/slf4j-api-1.7.25.jar org.logstash.Logstash --path.settings /etc/logstash
root     31953  0.0  0.0  14428  1052 pts/0    S+   14:12   0:00 grep --color=auto logstash

From logs it appears that logstash is working, here is the tail message from the log file:

[2020-04-15T14:11:10,190][DEBUG][logstash.instrument.periodicpoller.jvm] collector name {:name=>"ParNew"}
[2020-04-15T14:11:10,193][DEBUG][logstash.instrument.periodicpoller.jvm] collector name {:name=>"ConcurrentMarkSweep"}
[2020-04-15T14:11:10,340][DEBUG][org.logstash.execution.PeriodicFlush][main] Pushing flush onto pipeline.

here is the logstash.yml

# Settings file in YAML
#
# Settings can be specified either in hierarchical form, e.g.:
#
#   pipeline:
#     batch:
#       size: 125
#       delay: 5
#
# Or as flat keys:
#
#   pipeline.batch.size: 125
#   pipeline.batch.delay: 5
#
# ------------  Node identity ------------
#
# Use a descriptive name for the node:
#
# node.name: test
#
# If omitted the node name will default to the machine's host name
#
# ------------ Data path ------------------
#
# Which directory should be used by logstash and its plugins
# for any persistent needs. Defaults to LOGSTASH_HOME/data
#
path.data: /var/lib/logstash
#
# ------------ Pipeline Settings --------------
#
# The ID of the pipeline.
#
# pipeline.id: main
#
# Set the number of workers that will, in parallel, execute the filters+outputs
# stage of the pipeline.
#
# This defaults to the number of the host's CPU cores.
#
# pipeline.workers: 2
#
# How many events to retrieve from inputs before sending to filters+workers
#
# pipeline.batch.size: 125
#
# How long to wait in milliseconds while polling for the next event
# before dispatching an undersized batch to filters+outputs
#
# pipeline.batch.delay: 50
#
# Force Logstash to exit during shutdown even if there are still inflight
# events in memory. By default, logstash will refuse to quit until all
# received events have been pushed to the outputs.
#
# WARNING: enabling this can lead to data loss during shutdown
#
# pipeline.unsafe_shutdown: false
#
# ------------ Pipeline Configuration Settings --------------
#
# Where to fetch the pipeline configuration for the main pipeline
#
# path.config:
path.config: /etc/logstash/conf.d
#
# Pipeline configuration string for the main pipeline
#
# config.string:
#
# At startup, test if the configuration is valid and exit (dry run)
#
# config.test_and_exit: false
#
# Periodically check if the configuration has changed and reload the pipeline
# This can also be triggered manually through the SIGHUP signal
#
# config.reload.automatic: false
#
# How often to check if the pipeline configuration has changed (in seconds)
#
# config.reload.interval: 3s
#
# Show fully compiled configuration as debug log message
# NOTE: --log.level must be 'debug'
#
# config.debug: false
#
# When enabled, process escaped characters such as \n and \" in strings in the
# pipeline configuration files.
#
# config.support_escapes: false
#
# ------------ Module Settings ---------------
# Define modules here.  Modules definitions must be defined as an array.
# The simple way to see this is to prepend each `name` with a `-`, and keep
# all associated variables under the `name` they are associated with, and
# above the next, like this:
#
# modules:
#   - name: MODULE_NAME
#     var.PLUGINTYPE1.PLUGINNAME1.KEY1: VALUE
#     var.PLUGINTYPE1.PLUGINNAME1.KEY2: VALUE
#     var.PLUGINTYPE2.PLUGINNAME1.KEY1: VALUE
#     var.PLUGINTYPE3.PLUGINNAME3.KEY1: VALUE
#
# Module variable names must be in the format of
#
# var.PLUGIN_TYPE.PLUGIN_NAME.KEY
#
# modules:
#
# ------------ Cloud Settings ---------------
# Define Elastic Cloud settings here.
# Format of cloud.id is a base64 value e.g. dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRub3RhcmVhbCRpZGVudGlmaWVy
# and it may have an label prefix e.g. staging:dXMtZ...
# This will overwrite 'var.elasticsearch.hosts' and 'var.kibana.host'
# cloud.id: <identifier>
#
# Format of cloud.auth is: <user>:<pass>
# This is optional
# If supplied this will overwrite 'var.elasticsearch.username' and 'var.elasticsearch.password'
# If supplied this will overwrite 'var.kibana.username' and 'var.kibana.password'
# cloud.auth: elastic:<password>
#
# ------------ Queuing Settings --------------
#
# Internal queuing model, "memory" for legacy in-memory based queuing and
# "persisted" for disk-based acked queueing. Defaults is memory
#
# queue.type: memory
#
# If using queue.type: persisted, the directory path where the data files will be stored.
# Default is path.data/queue
#
# path.queue:
#
# If using queue.type: persisted, the page data files size. The queue data consists of
# append-only data files separated into pages. Default is 64mb
#
# queue.page_capacity: 64mb
#
# If using queue.type: persisted, the maximum number of unread events in the queue.
# Default is 0 (unlimited)
#
# queue.max_events: 0
#
# If using queue.type: persisted, the total capacity of the queue in number of bytes.
# If you would like more unacked events to be buffered in Logstash, you can increase the
# capacity using this setting. Please make sure your disk drive has capacity greater than
# the size specified here. If both max_bytes and max_events are specified, Logstash will pick
# whichever criteria is reached first
# Default is 1024mb or 1gb
#
# queue.max_bytes: 1024mb
#
# If using queue.type: persisted, the maximum number of acked events before forcing a checkpoint
# Default is 1024, 0 for unlimited
#
# queue.checkpoint.acks: 1024
#
# If using queue.type: persisted, the maximum number of written events before forcing a checkpoint
# Default is 1024, 0 for unlimited
#
# queue.checkpoint.writes: 1024
#
# If using queue.type: persisted, the interval in milliseconds when a checkpoint is forced on the head page
# Default is 1000, 0 for no periodic checkpoint.
#
# queue.checkpoint.interval: 1000
#
# ------------ Dead-Letter Queue Settings --------------
# Flag to turn on dead-letter queue.
#
# dead_letter_queue.enable: false

# If using dead_letter_queue.enable: true, the maximum size of each dead letter queue. Entries
# will be dropped if they would increase the size of the dead letter queue beyond this setting.
# Default is 1024mb
# dead_letter_queue.max_bytes: 1024mb

# If using dead_letter_queue.enable: true, the directory path where the data files will be stored.
# Default is path.data/dead_letter_queue
#
# path.dead_letter_queue:
#
# ------------ Metrics Settings --------------
#
# Bind address for the metrics REST endpoint
#
# http.host: "127.0.0.1"
http.host: "10.2.101.43"
#
# Bind port for the metrics REST endpoint, this option also accept a range
# (9600-9700) and logstash will pick up the first available ports.
#
# http.port: 9600-9700
#
# ------------ Debugging Settings --------------
#
# Options for log.level:
#   * fatal
#   * error
#   * warn
#   * info (default)
#   * debug
#   * trace
#
# log.level: info
log.level: debug
path.logs: /var/log/logstash
#
# ------------ Other Settings --------------
#
# Where to find custom plugins
# path.plugins: []
#
# Flag to output log lines of each pipeline in its separate log file. Each log filename contains the pipeline.name
# Default is false
# pipeline.separate_logs: false
#
# ------------ X-Pack Settings (not applicable for OSS build)--------------
#everything is commented here onwards same as original file

Here is the config file with which works when used from command line, just removed extra grok.

input {
  beats {
    port => 5044
  }
}
filter {
  if "Network Login" in [message]{
      grok{
        match =>{"message" => "%{TIMESTAMP_ISO8601:timeStamp}\s*[/|]\s*%{LOGLEVEL : level}\s*\|\s*(?<deviceType>.*)"}
      }
 
  }
}
output {
  elasticsearch {
    hosts => ["http://27.0.0.1:9200"]
    index => "test3-%{+YYYY.MM.dd}"
    #index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    #user => "elastic"
    #password => "changeme"
  }
  stdout { codec => rubydebug}
}

I am not sure where to look for errors. Thanks for your time.

I would start with /var/log/logstash, which is where log4j2 logs to by default.

Hi Badger,
Thanks for the reply. I look in the logs but couldn't find errors. Here are some logs after I stopped and restarted service.

[2020-04-15T16:13:32,653][DEBUG][io.netty.util.internal.PlatformDependent0][main] java.nio.DirectByteBuffer.<init>(long, int): unavailable
[2020-04-15T16:13:32,653][DEBUG][io.netty.util.internal.PlatformDependent][main] sun.misc.Unsafe: available
[2020-04-15T16:13:32,654][DEBUG][io.netty.util.internal.PlatformDependent][main] maxDirectMemory: 1038876672 bytes (maybe)
[2020-04-15T16:13:32,655][DEBUG][io.netty.util.internal.PlatformDependent][main] -Dio.netty.tmpdir: /tmp (java.io.tmpdir)
[2020-04-15T16:13:32,656][DEBUG][io.netty.util.internal.PlatformDependent][main] -Dio.netty.bitMode: 64 (sun.arch.data.model)
[2020-04-15T16:13:32,657][DEBUG][io.netty.util.internal.PlatformDependent][main] -Dio.netty.maxDirectMemory: -1 bytes
[2020-04-15T16:13:32,658][DEBUG][io.netty.util.internal.PlatformDependent][main] -Dio.netty.uninitializedArrayAllocationThreshold: -1
[2020-04-15T16:13:32,660][DEBUG][io.netty.util.internal.CleanerJava9][main] java.nio.ByteBuffer.cleaner(): available
[2020-04-15T16:13:32,660][DEBUG][io.netty.util.internal.PlatformDependent][main] -Dio.netty.noPreferDirect: false
[2020-04-15T16:13:32,669][DEBUG][io.netty.util.internal.PlatformDependent][main] org.jctools-core.MpscChunkedArrayQueue: available
[2020-04-15T16:13:32,682][INFO ][org.logstash.beats.Server][main] Starting server on port: 5044
[2020-04-15T16:13:32,707][DEBUG][io.netty.channel.DefaultChannelId][main] -Dio.netty.processId: 32060 (auto-detected)
[2020-04-15T16:13:32,711][DEBUG][io.netty.util.NetUtil    ][main] -Djava.net.preferIPv4Stack: false
[2020-04-15T16:13:32,711][DEBUG][io.netty.util.NetUtil    ][main] -Djava.net.preferIPv6Addresses: false
[2020-04-15T16:13:32,712][DEBUG][io.netty.util.NetUtil    ][main] Loopback interface: lo (lo, 0:0:0:0:0:0:0:1%lo)
[2020-04-15T16:13:32,714][DEBUG][io.netty.util.NetUtil    ][main] /proc/sys/net/core/somaxconn: 128
[2020-04-15T16:13:32,715][DEBUG][io.netty.channel.DefaultChannelId][main] -Dio.netty.machineId: 52:54:00:ff:fe:72:b4:38 (auto-detected)
[2020-04-15T16:13:32,720][DEBUG][io.netty.util.internal.InternalThreadLocalMap][main] -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024
[2020-04-15T16:13:32,721][DEBUG][io.netty.util.internal.InternalThreadLocalMap][main] -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096
[2020-04-15T16:13:32,700][DEBUG][logstash.agent           ] Starting puma
[2020-04-15T16:13:32,732][DEBUG][io.netty.util.ResourceLeakDetector][main] -Dio.netty.leakDetection.level: simple
[2020-04-15T16:13:32,732][DEBUG][io.netty.util.ResourceLeakDetector][main] -Dio.netty.leakDetection.targetRecords: 4
[2020-04-15T16:13:32,742][DEBUG][logstash.agent           ] Trying to start WebServer {:port=>9600}
[2020-04-15T16:13:32,762][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.numHeapArenas: 8
[2020-04-15T16:13:32,763][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.numDirectArenas: 8
[2020-04-15T16:13:32,764][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.pageSize: 8192
[2020-04-15T16:13:32,764][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.maxOrder: 11
[2020-04-15T16:13:32,765][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.chunkSize: 16777216
[2020-04-15T16:13:32,765][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.tinyCacheSize: 512
[2020-04-15T16:13:32,766][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.smallCacheSize: 256
[2020-04-15T16:13:32,766][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.normalCacheSize: 64
[2020-04-15T16:13:32,767][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.maxCachedBufferCapacity: 32768
[2020-04-15T16:13:32,767][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.cacheTrimInterval: 8192
[2020-04-15T16:13:32,768][DEBUG][io.netty.buffer.PooledByteBufAllocator][main] -Dio.netty.allocator.useCacheForAllThreads: true
[2020-04-15T16:13:32,780][DEBUG][io.netty.buffer.ByteBufUtil][main] -Dio.netty.allocator.type: pooled
[2020-04-15T16:13:32,780][DEBUG][io.netty.buffer.ByteBufUtil][main] -Dio.netty.threadLocalDirectBufferSize: 0
[2020-04-15T16:13:32,781][DEBUG][io.netty.buffer.ByteBufUtil][main] -Dio.netty.maxThreadLocalCharBufferSize: 16384
[2020-04-15T16:13:32,812][DEBUG][logstash.api.service     ] [api-service] start
[2020-04-15T16:13:32,940][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
[2020-04-15T16:13:34,464][DEBUG][logstash.instrument.periodicpoller.jvm] collector name {:name=>"ParNew"}
[2020-04-15T16:13:34,474][DEBUG][logstash.instrument.periodicpoller.jvm] collector name {:name=>"ConcurrentMarkSweep"}
[2020-04-15T16:13:37,554][DEBUG][org.logstash.execution.PeriodicFlush][main] Pushing flush onto pipeline.
[2020-04-15T16:13:39,487][DEBUG][logstash.instrument.periodicpoller.jvm] collector name {:name=>"ParNew"}

After this, there is repeat of last couple of lines. Please let me know if you see anything of concern here. Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.