时区差8个小时解决

下面例子, 时区差8个小时

  1. # Sample Logstash configuration for creating a simple
  2. # Beats -> Logstash -> Elasticsearch pipeline.
  3. input {
  4. beats {
  5. port => 5044
  6. }
  7. }
  8. filter {
  9. ruby {
  10. code => "event.timestamp.time.localtime"
  11. }
  12. if [fields][file_source] == "log" {
  13. grok {
  14. match => { "message" => "%{TIMESTAMP_ISO8601:log_date}\s+\[%{NOTSPACE:thread}\]\s+%{NOTSPACE:log_level}\s+%{NOTSPACE:logger}\s+-\s+(?<log_message>.*)" }
  15. }
  16. if "_grokparsefailure" in [tags] {
  17. drop {}
  18. }
  19. if [log_level] != "ERROR" {
  20. drop {}
  21. }
  22. } else if [fields][file_source] == "dot" {
  23. grok {
  24. match => { "message" => "%{TIMESTAMP_ISO8601:log_date}\s+\[%{NOTSPACE:thread}\]\s+%{NOTSPACE:log_level}\s+%{NOTSPACE:logger}\s+-\s+__glde:title=%{DATA:dot_title}&url=%{DATA:dot_url}&type=%{DATA:dot_type}&version=%{DATA:dot_version}&source=%{DATA:dot_source}&app-ver=%{DATA:dot_app_ver}&tenant-code=%{DATA:dot_tenant_code}&spm=%{DATA:dot_spm}&uid=%{DATA:dot_uid}&tid=%{DATA:dot_tid}&tc=%{DATA:dot_tc}&tr=%{DATA:dot_tr}&sr=%{DATA:dot_sr}&sra=%{DATA:dot_sra}&timestamp=%{NUMBER:dot_timestamp}&ip=%{DATA:dot_ip}&sessionId=%{DATA:dot_session_id}\s+(?<other_message>.*)" }
  25. }
  26. if "_grokparsefailure" in [tags] {
  27. drop {}
  28. }
  29. if [log_level] != "INFO" {
  30. drop {}
  31. }
  32. }
  33. }
  34. output {
  35. if [fields][file_source] == "log" {
  36. elasticsearch {
  37. hosts => ["http://localhost:9200","host2:9200"]
  38. index => "hao-log-%{+YYYY.MM.dd}"
  39. #user => "elastic"
  40. #password => "changeme"
  41. }
  42. } else if [fields][file_source] == "dot" {
  43. elasticsearch {
  44. hosts => ["http://localhost:9200","host2:9200"]
  45. index => "hao-dot-%{+YYYY.MM.dd}"
  46. #user => "elastic"
  47. #password => "changeme"
  48. }
  49. }
  50. }

需要改为类似这样的

input { 
    stdin { 
        add_field => {"timestamp" => "2022-02-08 18:35:56.280"}
        codec => "plain"
        type => "std"
    } 
} 

filter {
    mutate {
        add_field => { "nowTimeTemp" =>  "%{[timestamp]}"}
    }

    mutate {
        split => ["nowTimeTemp"," "]
        split => ["[nowTimeTemp][0]","-"]
        add_field =>   {
            "currentIndexPrefix" => "%{[nowTimeTemp][0][0]}.%{[nowTimeTemp][0][1]}.%{[nowTimeTemp][0][2]}"
        }
        remove_field => ["nowTimeTemp"]
    }
}

output { 
    stdout {
        codec => rubydebug
    } 
}

输出

{
              "@version" => "1",
             "timestamp" => "2022-02-08 18:35:56.280",
               "message" => "111",
                  "type" => "std",
                  "host" => "xjd-jdxia.local",
            "@timestamp" => 2022-02-09T03:34:08.189Z,
    "currentIndexPrefix" => "2022.02.08"
}

上面的logstash改为

output {

  if [fields][file_source] == "log" {
    elasticsearch {
      hosts => ["http://localhost:9200"]
      index => "hao-log-%{[currentIndexPrefix]}"
      #user => "elastic"
      #password => "changeme"
    }
  } else if [fields][file_source] == "dot" {
    elasticsearch {
      hosts => ["http://localhost:9200"]
      index => "hao-dot-%{[currentIndexPrefix]}"
      #user => "elastic"
      #password => "changeme"
    }
  }


}