GithubHelp home page GithubHelp logo

if string exists about grok_exporter HOT 7 OPEN

davidy718 avatar davidy718 commented on July 18, 2024
if string exists

from grok_exporter.

Comments (7)

ashevchuk123 avatar ashevchuk123 commented on July 18, 2024

Hi! Try something like this

      ...
      match: "%{ERROR_MESSAGE_PATTERN:error}."
      value: '{{ if eq .error "string to compare" }}1{{ else }}0{{ end }}'
      ...

from grok_exporter.

davidy718 avatar davidy718 commented on July 18, 2024

thanks for the reply @ashevchuk123
I get this
failed to initialize metric error_in_log: Pattern %{ERROR_MESSAGE_PATTERN:error} not defined.

from grok_exporter.

ashevchuk123 avatar ashevchuk123 commented on July 18, 2024

Because you need to initialize patterns (variables with regexes) and include them in config.

    imports:
    - type: grok_patterns
      file: /path/to/patterns/file

in this file you may create patterns for your error, for example:
ERROR_MESSAGE_PATTERN (regex_for_your_error_here)

You may find examples for patterns in the zip archive provided in the release.

from grok_exporter.

davidy718 avatar davidy718 commented on July 18, 2024

OK thanks so much for the help : )

from grok_exporter.

davidy718 avatar davidy718 commented on July 18, 2024

my issue is that if the string is not found I don't get the metric error_in_log
is there a way to have it to 0 and if the string is found then its 1 value: '{{ if eq .error "string to compare" }}1{{ else }}0{{ end }}' this didn't work

from grok_exporter.

davidy718 avatar davidy718 commented on July 18, 2024

and im trying it with multiple metrics

global:
    config_version: 3
input:
    type: file
    paths:
    - /var/logs/logfile.log
    - /var/logs1/logfile.log
    readall: true
imports:
    - type: grok_patterns
      dir: /path/to/patterns/file
metrics:
    - type: gauge
      name: error_in_log
      help: Error has been found in log.
      match: "%{ERROR_MESSAGE_PATTERN:error}."
      value: '{{ if eq .error "string to compare" }}1{{ else }}0{{ end }}'
      path: /var/logs/logfile.log
      labels:
        logfile: '{{base .logfile}}'
    - type: gauge
      name: error_in_log_1
      help: Error has been found in log 1.
      match: "%{ERROR_MESSAGE_PATTERN:error}."
      value: '{{ if eq .error "string to compare" }}1{{ else }}0{{ end }}'
      path: /var/logs1/logfile.log
      labels:
        logfile: '{{base .logfile}}'
server:
    port: 9144

is this the right way to do it ?

from grok_exporter.

davidy718 avatar davidy718 commented on July 18, 2024

and I have in my patterns
ERROR_MESSAGE_PATTERN (.*)
but I always get 0

from grok_exporter.

Related Issues (20)

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.