GithubHelp home page GithubHelp logo

Comments (8)

haihongren avatar haihongren commented on June 12, 2024

are you able to share the output of the script? what format is it? thanks!

from nri-flex.

sdeedee avatar sdeedee commented on June 12, 2024

Just a sample (all nagios checks works the same way)
root@monworker001:/var/db/newrelic-infra/custom-integrations# /usr/lib64/cmbmonit/plugins/check_load -w 0,3,2 -c 1,6,4
WARNING - load average: 0.01, 0.07, 0.08|load1=0.010;0.000;1.000;0; load5=0.070;3.000;6.000;0; load15=0.080;2.000;4.000;0;
PID USER %CPU COMMAND
1 root 0.0 /sbin/init
2 root 0.0 [kthreadd]
3 root 0.0 [ksoftirqd/0]
5 root 0.0 [kworker/0:0H]
7 root 0.0 [rcu_sched]
root@monworker001:/var/db/newrelic-infra/custom-integrations# /usr/lib64/cmbmonit/plugins/check_load -w 5,3,2 -c 6,6,4
OK - load average: 0.01, 0.07, 0.08|load1=0.010;5.000;6.000;0; load5=0.070;3.000;6.000;0; load15=0.080;2.000;4.000;0;

So I want to catch output into a variable. It can be 1 line but also multiple lines (in case of warning/critical).

Thanks.

from nri-flex.

haihongren avatar haihongren commented on June 12, 2024

I am not sure what metrics you are trying to get from the output.
With the following sdeedee.yml config:

name: sdeedee
apis:
  - name: sdeedee
    commands:
      - run: cat sdeedee.abc
        split: horizontal
        row_header: 0
        set_header:
          [
            status,
            loadAverage1,
            loadAverage2,
            loadAverage1,
            load11,
            load12,
            load13,
            load14,
            load51,
            load52,
            load53,
            load54,
            load151,
            load152,
            load153,
            load154,
          ]
        regex_match: true
        split_by: '(\S+).*?(load average:)\s+(.*?),\s+(.*?),\s+(.*?)\|load1=(.*?);(.*?);(.*?);(.*?);\s+load5=(.*?);(.*?);(.*?);(.*?);\s+load15=(.*?);(.*?);(.*?);(.*?);'

I got the following result:

				{
					"event_type": "sdeedeeSample",
					"integration_name": "com.newrelic.nri-flex",
					"integration_version": "0.8.3-pre-3-gf5a6601-dirty",
					"load11": 0.08,
					"load12": 0.01,
					"load13": 5,
					"load14": 6,
					"load151": 0,
					"load152": 0.08,
					"load153": 2,
					"load154": 4,
					"load51": 0,
					"load52": 0.07,
					"load53": 3,
					"load54": 6,
					"loadAverage1": 0.07,
					"loadAverage2": 0.01,
					"status": "OK"
				}

Please insert a blank line before the first line in the current output for multiple line output as Flex expects the metrics starts from the 2nd line onwards currently (for multi line output).
For single line output, it should work fine.

So this above yml config should work for the OK output.

OK - load average: 0.01, 0.07, 0.08|load1=0.010;5.000;6.000;0; load5=0.070;3.000;6.000;0; load15=0.080;2.000;4.000;0;

Please let me know how you go with the yml config.

./nri-flex -config_file sdeedee.yml -pretty -verbose

from nri-flex.

haihongren avatar haihongren commented on June 12, 2024

In the above yml file, i am using "run: cat sdeedee.abc" to simulate your script output.
the "sdeedee.abc" has the following content:
OK - load average: 0.01, 0.07, 0.08|load1=0.010;5.000;6.000;0; load5=0.070;3.000;6.000;0; load15=0.080;2.000;4.000;0;

from nri-flex.

sdeedee avatar sdeedee commented on June 12, 2024

Hi @haihongren, thanks! I can go on with your example. The multi line output I can cover by removing newline characters so the output is always a single line.

Just two other questions related to variables.

Is it possible to use variables in de flexConfig file?

/usr/lib64/cmbmonit/plugins/check_load -w @VARIABLES_ARG_WARNING -c @VARIABLES_ARG_CRITICAL
@VARIABLES_ARG defined somewhere in the flexconfig file:

  • variables:
    arg.warning: 3,4,5
    arg.critical: 6,7,8

Is it possible to reuse the run command and exit status of the command as variable to pass as attribute? Like in bash $? returns exit code of the command and $0 the command. To have:
custom_attributes: command.exitcode: $? command.run: $0

from nri-flex.

haihongren avatar haihongren commented on June 12, 2024

Please look at the following example:

  • variable_store
  • custom_attributes
  • ${var:myfile}
name: sdeedee
variable_store:
  myfile: sdeedee.abc
  myCommand: cat
apis:
  - name: sdeedee
    commands:
      - run: ${var:myCommand} ${var:myfile}
        split: horizontal
        set_header:
          [
            status,
            loadAverage1,
            loadAverage2,
            loadAverage1,
            load11,
            load12,
            load13,
            load14,
            load51,
            load52,
            load53,
            load54,
            load151,
            load152,
            load153,
            load154,
          ]
        regex_match: true
        # split_by: '(\S+).*?(load average:)\s+(.*?),\s+(.*?),\s+(.*?)\|load1=(.*?);(.*?);(.*?);(.*?);\s+load5=(.*?);(.*?);(.*?);(.*?);\s+load15=(.*?);(.*?);(.*?);(.*?);'
        split_by: '(\S+).*?(load average:)\s+(.*?),\s+(.*?),\s+(.*?)\|load1=(.*?);(.*?);(.*?);(.*?);\s+load5=(.*?);(.*?);(.*?);(.*?);\s+load15=(.*?);(.*?);(.*?);(.*?);'
        custom_attributes:
          myCommand: ${var:myCommand}
          myFile: ${var:myfile}

I would also recommend you to look the following wiki document:

https://github.com/newrelic/nri-flex/wiki/Functions#store_variables
https://github.com/newrelic/nri-flex/wiki/Functions#lookup_file
https://github.com/newrelic/nri-flex/wiki/Functions#store_lookups
https://github.com/newrelic/nri-flex/wiki/Functions#add_attribute

  • It does not capture exit code for Command at this moment, you can raise a feature request.
  • It does capture http return code if you are using url. For example:
name: nginxFlex
apis:
  - name: nginxStub
    url: http://127.0.0.1/nginx_status

from nri-flex.

sdeedee avatar sdeedee commented on June 12, 2024

Thanks, that was what I needed.

from nri-flex.

haihongren avatar haihongren commented on June 12, 2024

I am closing out this issue for now. Thanks!

from nri-flex.

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.