Giter VIP home page Giter VIP logo

logmine's Introduction

logmine - a log pattern analyzer CLI

PyPI version

A command-line tool to help you quickly inspect your log files and identify patterns.

Install

pip install logmine

Usage

cat sample/Apache_2k.log | logmine

logmine helps to cluster the logs into multiple clusters with common patterns along with the number of messages in each cluster.

image

You can have more granular clusters by adjusting -m value, the lower the value, the more details you will get.

cat sample/Apache_2k.log | logmine -m0.2

image

The texts in red are the placeholder for multiple values that fit in the pattern, you can replace those with your own placeholder.

cat sample/Apache_2k.log | logmine -m0.2 -p'---'

image

You can define variables to reduce the number unnecessary patterns and have less clusters. For example, the command bellow replaces all time texts with <time> variable.

cat sample/Apache_2k.log | logmine -m0.2 -p'---' -v "<time>:/\\d{2}:\\d{2}:\\d{2}/"

image

See all available options

How it works

LogMine is an implementation of the same name paper LogMine: Fast Pattern Recognition for Log Analytics. The idea is to use a distance function to calculate a distance between to log line and group them into clusters.

image

The distance function is designed to work well on log dataset, where all log messages from the same application are generated by a finite set of formats.

The Max Distance variable (max_dist or the -m option) represents the maximum distance between any log message in a cluster. The smaller max_dist, the more clusters will be generated. This can be useful to analyze a set of log messages at multiple levels.

image

More details on the clustering algorithm and pattern generation are available in the paper.

Features

  • Customizable max_dist and many other variables
  • Parallel processing on multiple cores
  • Colorful output
  • Support pipe/redirect
  • No dependencies
  • Tail mode: watch the clusters on a continuous input stream (TODO)
  • Sampling to reduce processing time on a large dataset (TODO)

Contribute / Development

  • Welcome all contributions

  • Install virtualenv (and optionally twine if you intend to publish):

      python3 -m pip install virtualenv twine
    
  • Create (if not yet exists) & activate virtual env:

      python3 -m virtualenv -p $(which python3) .v
    
  • Activate the virtualenv

      source ./.v/bin/activate
    
  • Run tests:

      ./test.sh
    
  • Run the dev version:

      ./logmine sample/Apache_2k.log
    
  • Publish:

    • Update the version value in setup.py following semver.
    • run ./publish.sh

CLI options

usage: logmine [-h] [-m MAX_DIST] [-v [VARIABLES [VARIABLES ...]]]
               [-d DELIMETERS] [-i MIN_MEMBERS] [-k1 K1] [-k2 K2]
               [-s {desc,asc}] [-da] [-p PATTERN_PLACEHOLDER] [-dhp] [-dm]
               [-dhv] [-c]
               [file [file ...]]

LogMine: a log pattern analyzer

positional arguments:
  file                  Filenames or glob pattern to analyze. Default: stdin

optional arguments:
  -h, --help            show this help message and exit
  -m MAX_DIST, --max-dist MAX_DIST
                        This parameter control how the granularity of the
                        clustering algorithm. Lower the value will provide
                        more granular clusters (more clusters generated).
                        Default: 0.6
  -v [VARIABLES [VARIABLES ...]], --variables [VARIABLES [VARIABLES ...]]
                        List of variables to replace before process the log
                        file. A variable is a pair of name and a regex
                        pattern. Format: "name:/regex/". During processing
                        time, LogMine will consider all texts that match
                        varible regexes to be the same value. This is useful
                        to reduce the number of unnecessary cluster generated,
                        with trade off of processing time. Default: None
  -d DELIMETERS, --delimeters DELIMETERS
                        A regex pattern used to split a line into multiple
                        fields. Default: "\s+"
  -i MIN_MEMBERS, --min-members MIN_MEMBERS
                        Minimum number of members in a cluster to show in the
                        result. Default: 2
  -k1 K1, --fixed-value-weight K1
                        Internal weighting variable. This value will be used
                        as the weight value when two fields have the same
                        value. This is used in the score function to calculate
                        the distance between two lines. Default: 1
  -k2 K2, --variable-weight K2
                        Similar to k1 but for comparing variables. Two
                        variable is considering the same if they have same
                        name. Default: 1
  -s {desc,asc}, --sorted {desc,asc}
                        Sort the clusters by number of members. Default: desc
  -da, --disable-number-align
                        Disable number align in output. Default: True
  -p PATTERN_PLACEHOLDER, --pattern-placeholder PATTERN_PLACEHOLDER
                        Use a string as placeholder for patterns in output.
                        Default: None
  -dhp, --disable-highlight-patterns
                        Disable highlighting for patterns in output. Default:
                        True
  -dm, --disable-mask-variables
                        Disable masks for variables in output. When disabled
                        variables will be shown as the actual value. Default:
                        True
  -dhv, --disable-highlight-variables
                        Disable highlighting for variables in output. Default:
                        True
  -c, --single-core     Force LogMine to only run on 1 core. This will
                        increase the processing time. Note: the result output
                        can be different compare to when run with multicores,
                        this is expected. Default: False

Capturing the analysis result in a buffer

By default, logmine writes the analysis results to stdout. In order to capture this output, a file-like object can be passed using the set_output_file() method to capture the result string, like in the below example :

buffer = io.StringIO()
lm = LogMine() # pass the usual parameters
lm.output.set_output_file(file=buffer)
lm.run()
# The captured output can be accessed in the buffer.
print(buffer.getvalue())

logmine's People

Contributors

ericjlarson avatar nr-blablacar avatar sayrus avatar trungdq88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logmine's Issues

Python script to run Logmine to run on Splunk

Need a Python script to run Logmine as a custom command on Splunk. The custom command should be able to extend Splunk eventing interface and accept events and create clusters using Logmine.

Strange variable behaviour

👋
First, thanks for the tools, it's very useful.
However, I'm facing a quite strange behaviour with variables.

Let say I've logs like:

07:09:36 caps,info router21-1: selected channel 2412/20/gn(10dBm) (fixed) 
07:09:36 caps,info router21-2: selected channel 5180/20-Ceee/ac/P(23dBm) (fixed) 
07:09:37 caps,info router42-1: selected channel 2412/20/gn(10dBm) (fixed) 
07:09:38 caps,info router41-1: selected channel 2412/20/gn(10dBm) (fixed) 
07:09:38 caps,info router41-2: selected channel 5180/20-Ceee/ac/P(23dBm) (fixed) 
07:56:58 caps,info router42-1: selected channel 2412/20/gn(10dBm) (fixed) 
07:58:25 caps,info router42-1: selected channel 2412/20/gn(10dBm) (fixed) 
07:59:28 caps,info router41-1: selected channel 2412/20/gn(10dBm) (fixed) 
07:59:28 caps,info router41-2: selected channel 5180/20-Ceee/ac/P(23dBm) (fixed) 
08:00:45 caps,info router41-1: selected channel 2412/20/gn(10dBm) (fixed) 
08:00:45 caps,info router41-2: selected channel 5180/20-Ceee/ac/P(23dBm) (fixed) 
08:02:18 caps,info router42-1: selected channel 2412/20/gn(10dBm) (fixed) 
08:02:19 caps,info router41-1: selected channel 2412/20/gn(10dBm) (fixed) 
08:02:19 caps,info router41-2: selected channel 5180/20-Ceee/ac/P(23dBm) (fixed) 
08:06:35 caps,info router42-1: selected channel 2412/20/gn(10dBm) (fixed) 
08:06:35 caps,info router41-1: selected channel 2412/20/gn(10dBm) (fixed) 
08:06:35 caps,info router41-2: selected channel 5180/20-Ceee/ac/P(23dBm) (fixed)

And I want to use variables to get:

17 <time> caps,info <router_name> selected channel <wifiChannel> (fixed)

Let's start with time as in the README file:

> logmine -v "<time>:/\\d{2}:\\d{2}:\\d{2}/"
17 <time> caps,info router21-1: selected channel 2412/20/gn(10dBm) (fixed)

Cool, let's add router_name:

> logmine -v "<time>:/\\d{2}:\\d{2}:\\d{2}/" "<router_name>:/router\\d{2}-\\d{1}/"
17 <time> caps,info <router_name> selected channel 2412/20/gn(10dBm) (fixed)

Great. Now, add wifiChannel:

> logmine -v "<time>:/\\d{2}:\\d{2}:\\d{2}/" "<router_name>:/router\\d{2}-\\d{1}/" \
               "<wifiChannel>:/\\d{4}\\/\\d{2}\\/\\w{2}\\(\\d{2}cBm\\)/"
Traceback (most recent call last):
  File "/home/jbfavre/.local/bin/logmine", line 6, in <module>
    run()
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/run.py", line 47, in run
    return logmine.run(input_files)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/log_mine.py", line 18, in run
    clusters = self.processor.process(files)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/processor.py", line 25, in process
    return self.process_pipe()
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/processor.py", line 84, in process_pipe
    clusterer = Clusterer(**self.cluster_config)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/clusterer.py", line 18, in __init__
    self.preprocessor = Preprocessor(variables)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/preprocessor.py", line 16, in __init__
    self.variables = [
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/preprocessor.py", line 17, in <listcomp>
    (tuple[0], re.compile(tuple[1])) for tuple in parsed_variables
  File "/usr/lib/python3.9/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python3.9/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.9/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.9/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.9/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.9/sre_parse.py", line 644, in _parse
    if not sourcematch("}"):
  File "/usr/lib/python3.9/sre_parse.py", line 251, in match
    self.__next()
  File "/usr/lib/python3.9/sre_parse.py", line 245, in __next
    raise error("bad escape (end of pattern)",
re.error: bad escape (end of pattern) at position 5

Wooops… let's try "<wifiChannel>:/\\d{4}\/\\d{2}\/\\w{2}\\(\\d{2}cBm\\)/" (only one \ escape before internal /)

logmine -v "<time>:/\\d{2}:\\d{2}:\\d{2}/" \
               "<router_name>:/router\\d{2}-\\d{1}/" \
               "<wifiChannel>:/\\d{4}\/\\d{2}\/\\w{2}\\(\\d{2}cBm\\)/"
Traceback (most recent call last):
  File "/home/jbfavre/.local/bin/logmine", line 6, in <module>
    run()
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/run.py", line 47, in run
    return logmine.run(input_files)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/log_mine.py", line 18, in run
    clusters = self.processor.process(files)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/processor.py", line 25, in process
    return self.process_pipe()
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/processor.py", line 84, in process_pipe
    clusterer = Clusterer(**self.cluster_config)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/clusterer.py", line 18, in __init__
    self.preprocessor = Preprocessor(variables)
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/preprocessor.py", line 16, in __init__
    self.variables = [
  File "/home/jbfavre/.local/lib/python3.9/site-packages/logmine_pkg/preprocessor.py", line 17, in <listcomp>
    (tuple[0], re.compile(tuple[1])) for tuple in parsed_variables
  File "/usr/lib/python3.9/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python3.9/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.9/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.9/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.9/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.9/sre_parse.py", line 644, in _parse
    if not sourcematch("}"):
  File "/usr/lib/python3.9/sre_parse.py", line 251, in match
    self.__next()
  File "/usr/lib/python3.9/sre_parse.py", line 245, in __next
    raise error("bad escape (end of pattern)",
re.error: bad escape (end of pattern) at position 5

Nope, doesn't work either…
Let's go without any escape before internal /:

> logmine -v "<time>:/\\d{2}:\\d{2}:\\d{2}/" \
               "<router_name>:/router\\d{2}-\\d{1}/" \
               "<wifiChannel>:/\\d{4}/\\d{2}/\\w{2}\\(\\d{2}cBm\\)/"
17 <time> caps,info <router_name> selected channel <wifiChannel> (fixed)

Cool, it works !
But…wait a minute… if I do not escape internal /, how does Python knows it's not the end of the regexp ?
More: I'm looking for 4 digits followed by / then 2 digits followed by / then 2 letters.
So, how is it that 5180/20-Ceee/ac/P could ever match and get replaced?

Thanks in advance for the explanation, I'm stuck here 🤔

Logmine giving '---' in output without any pattern placeholder and two similar patterns

I am processing input data (below) with logmine using command:

logmine data.json  -d "\"log\":| |\",\""

But in the output, I am getting --- even though I didn't specify any pattern placeholder. Also, there are two different lines here although these patterns look very similar. Should have been only a single line.

19 --- --- --- --- --- --- --- --- --- --- for --- --- --- --- ---
18 --- --- containerId":"mycontainer --- --- --- --- --- --- --- for --- --- --- --- ---

Input data:

{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612773092000617953","@timestamp":"2021-02-08T08:31:32Z","log":"couldn't update the deployment for the app app1","accountId":"id1"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612773089000913826","@timestamp":"2021-02-08T08:31:29Z","log":"Failed to delete kube objects for app: app1","accountId":"id2"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612773089000913825","@timestamp":"2021-02-08T08:31:29Z","log":"couldn't update the deployment for the app app1","accountId":"id2"}
{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612773092000617954","@timestamp":"2021-02-08T08:31:32Z","log":"Failed to delete kube objects for app: app1","accountId":"id1"}
{"@log_name":"ccddeeff","agentId":"ccddeeff","containerId":"mycontainer","timestamp":"1612772772011333155","@timestamp":"2021-02-08T08:26:12Z","log":"Failed to delete kube objects for app: app1","accountId":"id3"}
{"@log_name":"ccddeeff","agentId":"ccddeeff","containerId":"mycontainer","timestamp":"1612772772011333154","@timestamp":"2021-02-08T08:26:12Z","log":"couldn't update the deployment for the app app1","accountId":"id3"}
{"@log_name":"ddeeffgg","agentId":"ddeeffgg","containerId":"mycontainer","timestamp":"1612772677000593161","@timestamp":"2021-02-08T08:24:37Z","log":"couldn't update the deployment for the app app1","accountId":"id1"}
{"@log_name":"ddeeffgg","agentId":"ddeeffgg","containerId":"mycontainer","timestamp":"1612772677000593162","@timestamp":"2021-02-08T08:24:37Z","log":"Failed to delete kube objects for app: app1","accountId":"id1"}
{"@log_name":"eeffgghh","agentId":"eeffgghh","containerId":"mycontainer","timestamp":"1612772564000906700","@timestamp":"2021-02-08T08:22:44Z","log":"couldn't update the deployment for the app app1","accountId":"id2"}
{"@log_name":"eeffgghh","agentId":"eeffgghh","containerId":"mycontainer","timestamp":"1612772564000906701","@timestamp":"2021-02-08T08:22:44Z","log":"Failed to delete kube objects for app: app1","accountId":"id2"}
{"@log_name":"ffgghhii","agentId":"ffgghhii","containerId":"mycontainer","timestamp":"1612772530013805055","@timestamp":"2021-02-08T08:22:10Z","log":"Failed to delete kube objects for app: app1","accountId":"id3"}
{"@log_name":"ffgghhii","agentId":"ffgghhii","containerId":"mycontainer","timestamp":"1612772530013805054","@timestamp":"2021-02-08T08:22:10Z","log":"couldn't update the deployment for the app app1","accountId":"id3"}
{"@log_name":"gghhiijj","agentId":"gghhiijj","containerId":"mycontainer","timestamp":"1612772467000861260","@timestamp":"2021-02-08T08:21:07Z","log":"Failed to delete kube objects for app: app2","accountId":"id4"}
{"@log_name":"gghhiijj","agentId":"gghhiijj","containerId":"mycontainer","timestamp":"1612772467000861259","@timestamp":"2021-02-08T08:21:07Z","log":"couldn't update the deployment for the app app2","accountId":"id4"}
{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612772389000617209","@timestamp":"2021-02-08T08:19:49Z","log":"couldn't update the deployment for the app app1","accountId":"id1"}
{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612772389000617210","@timestamp":"2021-02-08T08:19:49Z","log":"Failed to delete kube objects for app: app1","accountId":"id1"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612772275000912965","@timestamp":"2021-02-08T08:17:55Z","log":"Failed to delete kube objects for app: app1","accountId":"id2"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612772275000912964","@timestamp":"2021-02-08T08:17:55Z","log":"couldn't update the deployment for the app app1","accountId":"id2"}
{"@log_name":"ccddeeff","agentId":"ccddeeff","containerId":"mycontainer","timestamp":"1612771889011332151","@timestamp":"2021-02-08T08:11:29Z","log":"Failed to delete kube objects for app: app1","accountId":"id3"}
{"@log_name":"ccddeeff","agentId":"ccddeeff","containerId":"mycontainer","timestamp":"1612771889011332150","@timestamp":"2021-02-08T08:11:29Z","log":"couldn't update the deployment for the app app1","accountId":"id3"}
{"@log_name":"ffgghhii","agentId":"ffgghhii","containerId":"mycontainer","timestamp":"1612771843013803890","@timestamp":"2021-02-08T08:10:43Z","log":"Failed to delete kube objects for app: app1","accountId":"id3"}
{"@log_name":"ffgghhii","agentId":"ffgghhii","containerId":"mycontainer","timestamp":"1612771843013803889","@timestamp":"2021-02-08T08:10:43Z","log":"couldn't update the deployment for the app app1","accountId":"id3"}
{"@log_name":"eeffgghh","agentId":"eeffgghh","containerId":"mycontainer","timestamp":"1612771746000905850","@timestamp":"2021-02-08T08:09:06Z","log":"Failed to delete kube objects for app: app1","accountId":"id2"}
{"@log_name":"eeffgghh","agentId":"eeffgghh","containerId":"mycontainer","timestamp":"1612771746000905849","@timestamp":"2021-02-08T08:09:06Z","log":"couldn't update the deployment for the app app1","accountId":"id2"}
{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612771687000616484","@timestamp":"2021-02-08T08:08:07Z","log":"Failed to delete kube objects for app: app1","accountId":"id1"}
{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612771687000616483","@timestamp":"2021-02-08T08:08:07Z","log":"couldn't update the deployment for the app app1","accountId":"id1"}
{"@log_name":"ddeeffgg","agentId":"ddeeffgg","containerId":"mycontainer","timestamp":"1612771644000592077","@timestamp":"2021-02-08T08:07:24Z","log":"Failed to delete kube objects for app: app1","accountId":"id1"}
{"@log_name":"ddeeffgg","agentId":"ddeeffgg","containerId":"mycontainer","timestamp":"1612771644000592075","@timestamp":"2021-02-08T08:07:24Z","log":"couldn't update the deployment for the app app1","accountId":"id1"}
{"@log_name":"gghhiijj","agentId":"gghhiijj","containerId":"mycontainer","timestamp":"1612771523000860204","@timestamp":"2021-02-08T08:05:23Z","log":"Failed to delete kube objects for app: app2","accountId":"id4"}
{"@log_name":"gghhiijj","agentId":"gghhiijj","containerId":"mycontainer","timestamp":"1612771523000860203","@timestamp":"2021-02-08T08:05:23Z","log":"couldn't update the deployment for the app app2","accountId":"id4"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612771460000912097","@timestamp":"2021-02-08T08:04:20Z","log":"Failed to delete kube objects for app: app1","accountId":"id2"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612771460000912096","@timestamp":"2021-02-08T08:04:20Z","log":"couldn't update the deployment for the app app1","accountId":"id2"}
{"@log_name":"ffgghhii","agentId":"ffgghhii","containerId":"mycontainer","timestamp":"1612771155013802947","@timestamp":"2021-02-08T07:59:15Z","log":"Failed to delete kube objects for app: app1","accountId":"id3"}
{"@log_name":"ffgghhii","agentId":"ffgghhii","containerId":"mycontainer","timestamp":"1612771155013802946","@timestamp":"2021-02-08T07:59:15Z","log":"couldn't update the deployment for the app app1","accountId":"id3"}
{"@log_name":"ccddeeff","agentId":"ccddeeff","containerId":"mycontainer","timestamp":"1612771005011331138","@timestamp":"2021-02-08T07:56:45Z","log":"Failed to delete kube objects for app: app1","accountId":"id3"}
{"@log_name":"ccddeeff","agentId":"ccddeeff","containerId":"mycontainer","timestamp":"1612771005011331137","@timestamp":"2021-02-08T07:56:45Z","log":"couldn't update the deployment for the app app1","accountId":"id3"}
{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612770985000615739","@timestamp":"2021-02-08T07:56:25Z","log":"couldn't update the deployment for the app app1","accountId":"id1"}
{"@log_name":"aabbccdd","agentId":"aabbccdd","containerId":"mycontainer","timestamp":"1612770985000615740","@timestamp":"2021-02-08T07:56:25Z","log":"Failed to delete kube objects for app: app1","accountId":"id1"}
{"@log_name":"eeffgghh","agentId":"eeffgghh","containerId":"mycontainer","timestamp":"1612770931000905018","@timestamp":"2021-02-08T07:55:31Z","log":"couldn't update the deployment for the app app1","accountId":"id2"}
{"@log_name":"eeffgghh","agentId":"eeffgghh","containerId":"mycontainer","timestamp":"1612770931000905019","@timestamp":"2021-02-08T07:55:31Z","log":"Failed to delete kube objects for app: app1","accountId":"id2"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612770646000911250","@timestamp":"2021-02-08T07:50:46Z","log":"couldn't update the deployment for the app app1","accountId":"id2"}
{"@log_name":"bbccddee","agentId":"bbccddee","containerId":"mycontainer","timestamp":"1612770646000911251","@timestamp":"2021-02-08T07:50:46Z","log":"Failed to delete kube objects for app: app1","accountId":"id2"}
{"@log_name":"ddeeffgg","agentId":"ddeeffgg","containerId":"mycontainer","timestamp":"1612770611000590983","@timestamp":"2021-02-08T07:50:11Z","log":"Failed to delete kube objects for app: app1","accountId":"id1"}
{"@log_name":"ddeeffgg","agentId":"ddeeffgg","containerId":"mycontainer","timestamp":"1612770611000590982","@timestamp":"2021-02-08T07:50:11Z","log":"couldn't update the deployment for the app app1","accountId":"id1"}
{"@log_name":"gghhiijj","agentId":"gghhiijj","containerId":"mycontainer","timestamp":"1612770578000859110","@timestamp":"2021-02-08T07:49:38Z","log":"couldn't update the deployment for the app app2","accountId":"id4"}
{"@log_name":"gghhiijj","agentId":"gghhiijj","containerId":"mycontainer","timestamp":"1612770578000859111","@timestamp":"2021-02-08T07:49:38Z","log":"Failed to delete kube objects for app: app2","accountId":"id4"}

variables work at the token level instead of line

I am working on parsing a syslog and trying to enter a variable for the date and time. The date format is "Mmm dd hh:mm:ss" the spaces in the date are split out as tokens then the tokens are replaced. This causes a problem when trying to replace the day "dd" as the pattern is to simple and replaces data I don't want to.
Can the variable functionality be applied before the line is tokenized?

command using
cat system.log | logmine -p'*' -v time:"/\d{2}:\d{2}:\d{2}/" month:"/Mar/" day:"/[1-3]?[0-9]/" -c

Log example
Mar 26 18:07:28 --- last message repeated 1 time ---
Mar 26 18:07:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:08:06 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0D000000-0700-0000-0000-000000000000[15944]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:08:07 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0B000000-0700-0000-0000-000000000000[15957]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:08:16 xxx Google Chrome Helper[15966]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:08:28 --- last message repeated 16 times ---
Mar 26 18:08:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:08:45 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.08000000-0400-0000-0000-000000000000[15955]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:08:47 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.06000000-0000-0000-0000-000000000000[15951]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:08:50 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0C000000-0200-0000-0000-000000000000[15964]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:08:55 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0A000000-0000-0000-0000-000000000000[15960]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:09:16 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0F000000-0200-0000-0000-000000000000[15962]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:09:25 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0D000000-0000-0000-0000-000000000000[15963]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:09:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:09:40 xxx Google Chrome Helper[1567]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:09:53 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0C000000-0300-0000-0000-000000000000[15970]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:09:54 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0F000000-0300-0000-0000-000000000000[15971]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:10:14 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.07000000-0300-0000-0000-000000000000[15954]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:10:24 xxx Google Chrome Helper[1567]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:10:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:11:01 xxx Google Chrome Helper[1567]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:11:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:11:28 xxx syslogd[63]: ASL Sender Statistics
Mar 26 18:11:34 xxx Google Chrome Helper[1567]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:12:06 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0F000000-0400-0000-0000-000000000000[15979]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:12:13 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0A000000-0100-0000-0000-000000000000[15975]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:12:13 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.07000000-0400-0000-0000-000000000000[15977]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:12:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:12:50 xxx Google Chrome Helper[1567]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:13:24 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.08000000-0500-0000-0000-000000000000[15982]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:13:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:14:03 xxx Google Chrome Helper[1567]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:14:09 --- last message repeated 1 time ---
Mar 26 18:14:09 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0C000000-0400-0000-0000-000000000000[15987]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:14:09 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0F000000-0500-0000-0000-000000000000[15986]): Service exited due to SIGKILL | sent by mds[92]
Mar 26 18:14:28 xxx Google Chrome Helper[56961]: Libnotify: notify_register_coalesced_registration failed with code 9 on line 2835
Mar 26 18:14:29 xxx com.apple.xpc.launchd[1] (com.apple.mdworker.shared.0D000000-0100-0000-0000-000000000000[15973]): Service exited due to SIGKILL | sent by mds[92]

line count does not seem to be correct

Hello. I'm running this:

# grep --no-filename duration /var/lib/pgsql/data/pg_log/postgresql-*.log | logmine --pattern-placeholder REPLACED --min-members 1 | sed 's/^\(.\{200\}\).*/\1/'
2479 REPLACED REPLACED EDT LOG: duration: REPLACED ms execute <unnamed>: UPDATE REPLACED SET REPLACED = $1, "updated_at" = $2 WHERE REPLACED = $3
 926 2020-05-22 02:46:52 EDT LOG: duration: 1341.912 ms statement: SELECT * FROM "dynflow_execution_plans" WHERE ("state" = 'scheduled') ORDER BY "started_at"
 179 2020-05-22 02:28:00 EDT LOG: duration: 977.242 ms statement: COMMIT
  13 REPLACED REPLACED EDT LOG: duration: REPLACED ms execute <unnamed>: select this_.id as id1_36_19_, this_.created as created2_36_19_, this_.updated as updated3_36_19_, this_.consumer_id as consume
  10 REPLACED REPLACED EDT LOG: duration: REPLACED ms statement: INSERT INTO "dynflow_actions" ("execution_plan_uuid", "id", "data", "input", "caller_execution_plan_id", "caller_action_id", "class", "
...

so I would expect there is 926 lines matching something like SELECT \* FROM "dynflow_execution_plans regexp (second line of output) - but there is only one:

# grep --no-filename duration /var/lib/pgsql/data/pg_log/postgresql-*.log | grep 'SELECT \* FROM "dynflow_execution_plans'
2020-05-22 02:46:52 EDT LOG:  duration: 1341.912 ms  statement: SELECT * FROM "dynflow_execution_plans" WHERE ("state" = 'scheduled') ORDER BY "started_at"

Did I understood the meaning of number in first column incorrectly, or is there some bug?

# python --version
Python 2.7.5
# pip freeze
logmine==0.1.4

logmine not installing properly

After doing pip install logmine, the module was installed succesfully.
But on running command logmine, it is giving error:
'logmine' is not recognized as an internal or external command,
operable program or batch file.

error on CLI execution

Hi,

after I pip install logmine, I get the following error:

% logmine
Traceback (most recent call last):
  File "/home/sebastian/.local/bin/logmine", line 3, in <module>
    from src.run import run
  File "/home/sebastian/.local/lib/python3.6/site-packages/src/run.py", line 2, in <module>
    from log_mine import LogMine
ModuleNotFoundError: No module named 'log_mine'

What strikes me is, that logmine claims to be python 2

"Programming Language :: Python :: 2",

but the backtrace points to python3.6 site packages. I have multiple python versions installed.

Best
Sebastian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.