Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgresSQL module for Filebeat #4763

Merged
merged 3 commits into from
Aug 8, 2017

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Jul 26, 2017

I have been working on a PostgreSQL module for Filebeat. Unfortunately, I got stuck at viewing logs in Kibana or maybe at indexing logs in Elasticsearch.

The fields for PostgreSQL I have defined are visible in the index. When I test the the pipeline I have created using the Simulate API with the sample logs in the commit, the fields are parsed properly. However, when I read logs of PostgreSQL using Filebeat, it does not seem to work when viewed in Kibana.

This is what I see:
postgreslog

I would expect the logs to be properly parsed, but I don't think it is what I see. To be honest, I am not sure what to expect. Could you give me some pointers on how to go on?

Also I have collected a few TODOs, but please let me know if I missed something.

TODO

  • write proper documentation
  • gather more test logs
  • create visualizations in Kibana
  • make checks green
  • add PR to changelog
  • add expected outputs

@kvch kvch added Filebeat Filebeat in progress Pull request is currently in progress. review labels Jul 26, 2017
@kvch kvch force-pushed the feature/filebeat-postgresql-module branch 2 times, most recently from 528c9a5 to 5f93a94 Compare July 26, 2017 20:04
"ignore_missing": true,
"patterns": [
"%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timeformat} \[%{NUMBER:postgresql.log.thread_id}\] %{USERNAME:postgresql.log.username}@%{HOSTNAME:postgresql.log.host} %{WORD:postgresql.log.level}: ?%{GREEDYDATA:postgresql.log.message}",
"%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timeformat} \[%{NUMBER:postgresql.log.thread_id}\] \[%{USERNAME:postgresql.username}\]@\[%{HOSTNAME:postgresql.log.host}\] %{WORD:postgresql.log.level}: ?%{GREEDYDATA:postgresql.log.message}",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/postgresql.username/postgreseql.log.username/ ?

"patterns": [
"%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timeformat} \[%{NUMBER:postgresql.log.thread_id}\] %{USERNAME:postgresql.log.username}@%{HOSTNAME:postgresql.log.host} %{WORD:postgresql.log.level}: ?%{GREEDYDATA:postgresql.log.message}",
"%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timeformat} \[%{NUMBER:postgresql.log.thread_id}\] \[%{USERNAME:postgresql.username}\]@\[%{HOSTNAME:postgresql.log.host}\] %{WORD:postgresql.log.level}: ?%{GREEDYDATA:postgresql.log.message}",
"%{LOCALDATETIME:postgresql.log.timestamp} %{WORD:postgresql.log.timeformat} \[%{NUMBER:postgresql.log.thread_id}\] %{WORD:postgresql.log.level}: ?%{GREEDYDATA:postgresql.log.message}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you need to use \\ here. grok is basically build on regular expressions. Plus this file being json might might affect the \ on read.

@kvch kvch force-pushed the feature/filebeat-postgresql-module branch 2 times, most recently from 2335916 to ceba36c Compare July 28, 2017 10:32
@kvch
Copy link
Contributor Author

kvch commented Jul 28, 2017

My initial problem was solved. Thank you for your help. :) I updated the TODO list based on the current state of the PR.

@kvch kvch force-pushed the feature/filebeat-postgresql-module branch 5 times, most recently from bf388ab to 69234ae Compare July 28, 2017 19:49
@tsg
Copy link
Contributor

tsg commented Jul 31, 2017

This is green enough, the remaining failure is Metricbeat on Windows.

Copy link
Contributor

@tsg tsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think only the Changelog is missing.

@tsg
Copy link
Contributor

tsg commented Jul 31, 2017

@kvch It would be nice to also have a fileset for slow logs, like we have for MySQL. But totally fine to do that in a second PR.

@kvch kvch force-pushed the feature/filebeat-postgresql-module branch from 69234ae to 2781c17 Compare July 31, 2017 20:19
@kvch
Copy link
Contributor Author

kvch commented Jul 31, 2017

@tsg I am trying to add slowlog parsing. It is not in a different fileset, because PostgreSQL puts slowlogs in the same file as the other logs by default.

Again the Grok parser has failed me. :D I have worked out a regex for multiline query statements using Kibana Dev Tools, but it does not seem to work with Filebeat.

@kvch kvch force-pushed the feature/filebeat-postgresql-module branch 2 times, most recently from 4805b3b to 00bb4a3 Compare July 31, 2017 22:19
@kvch
Copy link
Contributor Author

kvch commented Jul 31, 2017

The problem is fixed. Multiline configuration was missing from the module.

@tsg
Copy link
Contributor

tsg commented Aug 1, 2017

@kvch Something else I noticed, I think you didn't yet add -expected.json files. See for example, the one from the Nginx module. There's test.log, which contains a few sample log lines, and test.log-expected.json which contain the result after passing it through Elasticsearch. If you add such an *-expected.json file, the system tests will automatically check the results. See the responsible system test here.

@kvch
Copy link
Contributor Author

kvch commented Aug 1, 2017

@tsg I will add it. Thanks.

@kvch kvch force-pushed the feature/filebeat-postgresql-module branch 2 times, most recently from c66cae4 to e1128f9 Compare August 2, 2017 16:39
@kvch
Copy link
Contributor Author

kvch commented Aug 2, 2017

I have added a new commit containing a test refactor.

@kvch kvch removed the in progress Pull request is currently in progress. label Aug 2, 2017
This module includes a sample dashboard and two sample searches for
Kibana.
Previously, only 10 logs could be in *.log and *-expected.json files,
as it is the default page size of ES. However, to be more future proof
the test was extended, so it can validate more than 10 logs and events.
@kvch kvch force-pushed the feature/filebeat-postgresql-module branch from e1128f9 to c36915d Compare August 3, 2017 10:28
@tsg
Copy link
Contributor

tsg commented Aug 8, 2017

Remaining test failure is not related. Merging.

@tsg tsg merged commit 2caf75d into elastic:master Aug 8, 2017
Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The links to some images look wrong?


The second one shows the slowlogs of PostgreSQL.

image::./images/filebeat-postgresql-postgresql-overview.png[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be images/filebeat-postgresql-slowlog-overview.png I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed with: #4843


The second one shows the slowlogs of PostgreSQL.

image::./images/filebeat-postgresql-postgresql-overview.png[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be images/filebeat-postgresql-slowlog-overview.png I think

@liuqian1990
Copy link

2017-12-27 11:19:07 GMT [30072]-[14] session=5a43112b.7578 user=postgres db=postgres app=[unknown] client=10.0.2.73 LOG: duration: 1.229 ms statement:
SELECT COUNT(mode) AS count, mode
FROM pg_locks GROUP BY mode
UNION SELECT COUNT(*) AS count, 'waiting' AS mode
FROM pg_locks
WHERE granted is false;

2017-12-27 11:19:07 GMT [30072]-[15] session=5a43112b.7578 user=postgres db=postgres app=[unknown] client=10.0.2.73 LOG: duration: 0.334 ms parse : SELECT pg_database_size($1) AS size;
2017-12-27 11:19:07 GMT [30072]-[16] session=5a43112b.7578 user=postgres db=postgres app=[unknown] client=10.0.2.73 LOG: duration: 0.206 ms bind : SELECT pg_database_size($1) AS size;
2017-12-27 11:19:07 GMT [30072]-[17] session=5a43112b.7578 user=postgres db=postgres app=[unknown] client=10.0.2.73 DETAIL: parameters: $1 = 'postgres'
2017-12-27 11:19:07 GMT [30070]-[18] session=5a43112b.7576 user=postgres db=postgres app=[unknown] client=10.0.2.73 LOG: duration: 52.563 ms execute : SELECT pg_database_size($1) AS size;
2017-12-27 11:19:07 GMT [30070]-[19] session=5a43112b.7576 user=postgres db=postgres app=[unknown] client=10.0.2.73 DETAIL: parameters: $1 = 'postgres'
2017-12-27 11:19:07 GMT [30070]-[20] session=5a43112b.7576 user=postgres db=postgres app=[unknown] client=10.0.2.73 LOG: duration: 0.112 ms parse : SELECT pg_database_size($1) AS size;
2017-12-27 11:19:07 GMT [30070]-[21] session=5a43112b.7576 user=postgres db=postgres app=[unknown] client=10.0.2.73 LOG: duration: 0.165 ms bind : SELECT pg_database_size($1) AS size;

How to resolve these logs, set up can not be resolved

@liuqian1990
Copy link

Provided Grok expressions do not match field value: [2017-12-27 13:54:07 GMT [30071]-[3741] session=5a43112b.7577 user=postgres db=postgres app=[unknown] client=10.0.2.73 LOG: duration: 0.180 ms bind : SELECT pg_database_size($1) AS size;]

@ruflin
Copy link
Member

ruflin commented Dec 28, 2017

@liuqian1990 Could you please open a new topic on discuss for further discussions as this is a closed PR? https://discuss.elastic.co/c/beats/filebeat Please provide there your config and the filebeat version you are using + the logs as you did above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants