add logparser module#4900
Conversation
|
@ilyam8 could explain it a bit more
It's better to use
Am i right? |
|
It depends on the method/value. Example You should parse value and use appropriate We need a We can use any logic for matchig - Matchers: Matchers example
class BaseStringMatcher:
def __init__(self, value):
self.value = value
def match(self, row):
raise NotImplementedError
class BaseRegexMatcher:
def __init__(self, value):
self.value = re.compile(value)
def match(self, row):
raise NotImplementedError
class StringMatcher(BaseStringMatcher):
def match(self, row):
return self.value in row
class StringPrefixMatcher(BaseStringMatcher):
def match(self, row):
return row.startswith(self.value)
class StringSuffixMatcher(BaseStringMatcher):
def match(self, row):
return row.endswith(self.value)
class RegexMatchMatcher(BaseRegexMatcher):
def match(self, row):
return self.value.match(row)
class RegexSearchMatcher(BaseRegexMatcher):
def match(self, row):
return self.value.search(row)Matcher factory
METHOD_REGEX = "regex"
METHOD_STRING = "string"
def regex_matcher_factory(value):
if value.startswith('^'):
return RegexMatchMatcher(value)
return RegexSearchMatcher(value)
def string_matcher_factory(value):
if value.startswith("^"):
return StringPrefixMatcher(value)
elif value.endswith('$'):
return StringSuffixMatcher(value)
return StringMatcher(value)
def matcher_factory(raw_value):
method, value = raw_value.split("=")
if method == METHOD_REGEX:
return regex_matcher_factory(value)
if method == METHOD_STRING:
return string_matcher_factory(value)
raise ValueError('unknown search method') |
|
if you need any help with the module feel free to ask |
|
@hamedbrd if you don't have time to finish it i can take over, np |
cakrit
left a comment
There was a problem hiding this comment.
In readme and config instructions,
-
Correct first paragraph to:
This module is able to monitor an application specific log file and then create a chart based on occurrences of a log line (like amount of occurrences in a day, or a line graph of when the occurrences happen). It can read multiple files and produce multiple charts with multiple dimensions on each chart. -
Rename "Config patterns" to "Configuration" and write the following before the final example.
By default, the plugin does not read any files or produce any charts. To configure it, edit python.d/logparser.conf.
The sample config below shows the general definition of a chart named chart_name with a single dimension with name dimension_name. The metric for that dimension is a counter of the occurrences of lines matching the python regular expression regex_pattern in file path/logfile:
chart_name:
log_path: path/logfile
dimensions:
dimension_name: regex_patternA final config for more than one chart and more than one dimension could be something like this
|
@ilyam8 as you guessed ,unfortunately i do not have time for these changes and also i have some other changes in my mind for this plugin to being able to do something more but no free time. So i would appreciate if you help on this |
|
@ilyam8 could you please take look at new changes and if you think there is not problem then i will update the readme? |
|
This pull request introduces 1 alert when merging 13f5c48 into f1bb78a - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
@hamedbrd logic should be
for row in raw:
for m in self.matchers:
if m.match(row):
self.data[m.name] += 1
break
return self.dataexample^^ |
|
@ilyam8 |
Yes, I've test it many times because it's used on different services |
|
i mean the latest, becase we made few changes in the last hour. |
|
@cakrit please have a look, i see you had some questions code looks ok to me |
|
|
One more - please add default info to the readme after that - lgtm |
|
Ok, so what I still don't see here is a time element. What I got from the code is that we just have an incremental counter for each pattern that starts at zero every time netdata is restarted and just keeps increasing with every matching line. However, the metric unit states jobs/s, so perhaps I missed something here? |
imo should be
Yes |
|
So what I'm saying is that we don't actually have a way here to show e.g. the occurences in a day, as the issue and the README say we want to. |
|
The issue has
I think the PR implements the part after |
|
@ilyam8 any update? |
|
@hamedbrd sorry for delay. The module is finished, good job 👍 But we will rewrite it in We need to wait untis this PR is merged. And we use new syntax for all that string/regex stuff: |
|
@ilyam8 For rewriting to go, I will take over this part too but you won't merge this MR, will you? |
No.
Nice! As i said lets wait for netdata/go.d.plugin#141. I will ping you when it will be merged. |
|
@hamedbrd you can follow netdata/go.d.plugin#141. I'm closing this one. |

Fix: #3729
This PR is the same of this PR
#4334
But I just forked the latest version and add my new plugin in it
I added this plugin in collectors/python.d.plugin/logparser/ which it was completely different structure in previous version .
This module is able to monitor an application specific log file and then create a chart based on occurrences of a log line (like amount of occurrences in a day, or a line graph of when the occurrences happen).It has no limitation to have multi dimension and multi charts.
Config patterns
Above config show how to define your charts and how to fetching metrics from custom log files.
For each dimension in each chart must one regex be written in order to fetch those matches from that log file.It allows us to define whatever charts we want to show in dashboard.
A final config for more than one chart and more than one dimension could be something like this