Code Monkey home page Code Monkey logo

sensu-plugins-cpu-checks's Introduction

Sensu Bonsai Asset Build Status Gem Version Code Climate Test Coverage Dependency Status

Sensu Plugins CPU Checks Plugin

Overview

This plugin provides native CPU instrumentation for monitoring and metrics collection, including CPU usage and metrics for user, nice, system, idle, iowait, irq, softirq, steal, and guest.

Files

  • bin/check-cpu.rb

  • bin/metrics-cpu-interrupts.rb

  • bin/metrics-cpu-mpstat.rb

  • bin/metrics-cpu-pcnt-usage.rb

  • bin/metrics-cpu-softirqs.rb

  • bin/metrics-cpu.rb

  • bin/metrics-numastat.rb

  • bin/metrics-softnet-stat.rb

  • bin/metrics-user-pct-usage.rb

    Added cpu interrupts, softirqs, softnet-stat 2 years ago metrics-user-pct-usage.rb

check-cpu Checks CPU usage.

metrics-cpu-interrupts Provides metrics for CPU interrupts.

metrics-cpu-mpstat Provides metrics for individual CPU and overall CPU usage.

metrics-cpu-pcnt-usage Provides metrics for CPU percent usage.

metrics-cpu-softirqs Provides metrics for CPU softirqs.

metrics-cpu Provides CPU metrics.

metrics-numastat Provides a simple wrapper around numastat for getting per-NUMA-node memory stats.

metrics-softnet-stat Provides softnet stats.

metrics-user-pct-usage Produces Graphite output of sum of %CPU over all processes by user. For example, if user Joe is running two processes, each using 10% CPU, and user Jane is running one process using 50% CPU, output will be:

  • Joe 20.0 (timestamp)
  • Jane 50.0 (timestamp)

Usage examples

Help

check-cpu.rb

Usage: check-cpu.rb (options)
        --cache-file CACHEFILE
    -c CRIT
        --guest                      Check cpu guest instead of total cpu usage
        --guest_nice                 Check cpu guest_nice instead of total cpu usage
        --idle                       Check cpu idle instead of total cpu usage
        --idle-metrics METRICS       Treat the specified metrics as idle. Defaults to idle,iowait,steal,guest,guest_nice
        --iowait                     Check cpu iowait instead of total cpu usage
        --irq                        Check cpu irq instead of total cpu usage
    -l, --less_than                  Change whether value is less than check
        --nice                       Check cpu nice instead of total cpu usage
        --proc-path /proc
        --sleep SLEEP                This sleep controls the interval between the initial poll for cpu utilization and the next data point, the longer the interval is the more accurate your data will be
        --softirq                    Check cpu softirq instead of total cpu usage
        --steal                      Check cpu steal instead of total cpu usage
        --system                     Check cpu system instead of total cpu usage
        --user                       Check cpu user instead of total cpu usage
    -w WARN  

metrics-numastat.rb

Usage: metrics-numastat.rb (options)
    -s, --scheme SCHEME              Metric naming scheme, text to prepend to metric

Configuration

Sensu Go

Asset registration

Assets are the best way to make use of this plugin. If you're not using an asset, please consider doing so! If you're using sensuctl 5.13 or later, you can use the following command to add the asset:

sensuctl asset add sensu-plugins/sensu-plugins-cpu-checks

If you're using an earlier version of sensuctl, you can download the asset definition from this project's Bonsai asset index page.

Asset definition

---
type: Asset
api_version: core/v2
metadata:
  name: sensu-plugins-cpu-checks
spec:
  url: https://assets.bonsai.sensu.io/68546e739d96fd695655b77b35b5aabfbabeb056/sensu-plugins-cpu-checks_4.0.0_centos_linux_amd64.tar.gz
  sha512: 518e7c17cf670393045bff4af318e1d35955bfde166e9ceec2b469109252f79043ed133241c4dc96501b6636a1ec5e008ea9ce055d1609865635d4f004d7187b

Check definition

---
type: CheckConfig
spec:
  command: "check-cpu.rb"
  handlers: []
  high_flap_threshold: 0
  interval: 10
  low_flap_threshold: 0
  publish: true
  runtime_assets:
  - sensu-plugins/sensu-plugins-cpu-checks
  - sensu/sensu-ruby-runtime
  subscriptions:
  - linux

Sensu Core

Check definition

{
  "checks": {
    "check-cpu": {
      "command": "check-cpu.rb",
      "subscribers": ["linux"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["influxdb"]
    }
  }
}

Installation from source

Sensu Go

See the instructions above for asset registration.

Sensu Core

Install and setup plugins on Sensu Core.

Additional notes

Sensu Go Ruby Runtime Assets

The Sensu assets packaged from this repository are built against the Sensu Ruby runtime environment. When using these assets as part of a Sensu Go resource (check, mutator, or handler), make sure to include the corresponding Sensu Ruby Runtime Asset in the list of assets needed by the resource.

Required bc utility

The check-cpu.sh shell script in this repository requires the bc utility to be installed and available in the executable path. This shell script is not installed when using the Ruby gem or Sensu asset derived from this repository.

Contributing

See CONTRIBUTING.md for information about contributing to this plugin.

sensu-plugins-cpu-checks's People

Contributors

ajohnstone avatar amdprophet avatar analytically avatar axos88 avatar bimlendu avatar cwjohnston avatar dalesit avatar dependabot-preview[bot] avatar dependabot-support avatar eheydrick avatar envintus avatar hillaryfraley avatar jspaleta avatar majormoses avatar mjulian avatar mrichar1 avatar santhosh-tekuri avatar tas50 avatar vervas avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sensu-plugins-cpu-checks's Issues

metrics-cpu.rb much faster than other scripts

sensu-plugins-cpu-checks (0.0.4)

# time /opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb | grep real

real    0m1.123s
user    0m0.116s
sys 0m0.006s
# time /opt/sensu/embedded/bin/metrics-cpu-mpstat.rb | grep real

real    0m1.125s
user    0m0.117s
sys 0m0.007s
# time /opt/sensu/embedded/bin/metrics-cpu.rb | grep real

real    0m0.124s
user    0m0.116s
sys 0m0.008s

Ran multiple iterations and the two additional versions seem to always take a second or longer to execute, is the a reason behind this?

New release needed

The latest gem I can find is 0.0.4 which has a fixed version dependency to sensu-plugin:

sensu-plugin (= 1.2.0)

And this results in the following error after updating sensu to version 0.25.0:

# /opt/sensu/embedded/bin/check-cpu.rb --help
/opt/sensu/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:310:in `to_specs': Could not find 'sensu-plugin' (= 1.2.0) - did find: [sensu-plugin-1.3.0] (Gem::MissingSpecVersionError)

It's already fixed on master:
sensu-plugins-cpu-checks.gemspec#L41

s.add_runtime_dependency 'sensu-plugin', '~> 1.2'

Inaccurate interrupts stat

I think there's an issue with the reporting of interrupts from metrics-cpu.rb.

As per https://www.kernel.org/doc/Documentation/filesystems/proc.txt (section 1.8):

The "intr" line gives counts of interrupts serviced since boot time, for each
of the possible system interrupts. The first column is the total of all
interrupts serviced including unnumbered architecture specific interrupts;
each subsequent column is the total for that particular numbered interrupt.

However, in the metrics check

output "#{config[:scheme]}.#{name}", info.last if other_metrics.include? name

This will return the last element of the array for each stat including intr. However, for intr the total is actually the first element. The last column is just the total for a given interrupt (which can actually vary between platform).

Using sensu-plugins-cpu-checks 1.0.0.

Missing column in metrics-cpu.rb

Hi,

It appears to me that the metrics-cpu.rb is missing the final column from /proc/stat
This is the guest_nice column.

Here's an example from /proc/stat on a Linux server running kernel version 3.2.0

ben@server:~$ cat /proc/stat |head -n 1
cpu  724635608 1472915 42523717 1190216593 104755408 1555 18433154 58368179 0 0

This has 10 columns.
From https://www.kernel.org/doc/Documentation/filesystems/proc.txt

The meanings of the columns are as follows, from left to right:

  • user: normal processes executing in user mode
  • nice: niced processes executing in user mode
  • system: processes executing in kernel mode
  • idle: twiddling thumbs
  • iowait: waiting for I/O to complete
  • irq: servicing interrupts
  • softirq: servicing softirqs
  • steal: involuntary wait
  • guest: running a normal guest
  • guest_nice: running a niced guest

This line of code shows that cpu-metrics.rb is only recording 9 named values:
https://github.com/sensu-plugins/sensu-plugins-cpu-checks/blob/master/bin/metrics-cpu.rb#L45

cpu_metrics = %w(user nice system idle iowait irq softirq steal guest)

The result is that we get an unnamed metric saved, shown by the last line of this output.

ben@server:~$ /opt/sensu/embedded/bin/metrics-cpu.rb |head -n 10
server.cpu.total.user 724691512 1471650046
server.cpu.total.nice 1472915 1471650046
server.cpu.total.system 42529159 1471650046
server.cpu.total.idle 1190347167 1471650046
server.cpu.total.iowait 104771725 1471650046
server.cpu.total.irq 1556 1471650046
server.cpu.total.softirq 18436526 1471650046
server.cpu.total.steal 58377036 1471650046
server.cpu.total.guest 0 1471650046
server.cpu.total. 0 1471650046

The version of sensu-plugin-cpu-checks is 1.0.0

Many thanks for this excellent software.

sh: check-cpu.rb: not found

Hi,

in the Sensu Backend I am getting sh: check-cpu.rb: not found.

I have installed the sensu-plugins-cpu-checks asset with the following manifest:

---
type: Asset
api_version: core/v2
metadata:
  name: sensu-plugins-cpu-checks
spec:
  builds:
  - url: https://s1artproxy:PASSWORD@artifactory:8088/artifactory/remote-sensu-assets/24e5a5d7ff0a5e63b0a6902f1224b7d4592cbdc9/sensu-plugins-cpu-checks_4.1.0_centos7_linux_amd64.tar.gz
    sha512: 8a018622018220323588a0d69ce0ee1e8c3ae72ad708108eb105006e1453a507289445eefb222da838b132106abf86910e2226d2148cc90ae64def9e7d887584
    filters:
    - entity.system.os == 'linux'
    - entity.system.arch == 'amd64'
    - entity.system.platform_family == 'rhel'
    - entity.system.platform_version.split('.')[0] == '7'

But I don't find the check-cpu.rb script on my sensu-agent container. Other plugins install without problems.

How can I check why my installation of sensu-plugins-cpu-checks is failing?

Best regards,
rforberger

metrics-cpu-mpstat.rb inflating CPU when run from sensu

I have a problem on one of my systems which is showing (according to metrics-cpu-mpstat) nearly 100% cpu utilisation, but according to sar, 75% idle time. The act of measuring the CPU over a second seems to be incorrectly putting up the CPU stats, although not on other identical servers which are 88% idle (according to sar). Running top -d 0.5 shows that the check-rabbitmq checks run at high CPU when they come through. If they coincide with the cpu metrics run, the stats will be skewed. However, running metrics-cpu.rb just takes the counter, and compares it against the value the next time it is run, so gives a true picture of the amount of CPU utilisation over that interval.

Bonsai debian9 filter definition is too broad

The filters debian 9 are too broad, either remove or add debian platform_family and version to filter

- platform: "debian9"
  arch: "amd64"
  asset_filename: "#{repo}_#{version}_debian9_linux_amd64.tar.gz"
  sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
  filter:
  -  "entity.system.os == 'linux'"
  -  "entity.system.arch == 'amd64'"

check-cpu.rb alerts sometimes regardless of load on cpu

check-cpu.rb alerts sometimes with total cpu being 100% busy, but the top output captured at the same time as a part of hooks doesn't show any load.

Explanation by @majormoses:

the way that it detects it is by gathering the current and then gathering it again (defaults to 1s) and measuring the difference. As the very act of doing so means that you are inflating the cpu utilization by loading up ruby. In addition because of the short timespan it collects data for the numbers will also not be 100% accurate. You can use the --sleep option to control how long it waits before using another data point, the longer you wait the more accurate it will be. In an ideal world I would opt for changing the default value to 5 as that is what I found was a good compromise for accuracy and being able to still get very granular/frequent checks but the problem is that someone might be setting their thresholds to less than 5 seconds which would cause issues as you'd have multiple instances of the check running at the same time. I am willing to do it as a breaking change as I think its a good move forward, just giving context of where it is and why it was not changed previously.

Change default 1 seconds to something higher to get more accurate data and avoid un-necessary alerts.

Wrong type being set for --proc-path long option

The --proc-path long option is being set as a float instead of a string. The default for this option works fine, but when a user supplied value is passed that value is then converted to a float. The value of config[:proc_path] then becomes 0.0.

Assuming a scenario where you are running the Sensu client as a container with the host /proc/ file system mounted at /rootfs/proc, the following output is the error produced:

/opt/sensu/embedded/bin/check-cpu.rb --proc-path=/rootfs/proc
Check failed to run: No such file or directory @ rb_sysopen - 0.0/stat, ["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:71:in `initialize'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:71:in `open'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:71:in `acquire_cpu_stats'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:79:in `run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.4/lib/sensu-plugin/cli.rb:58:in `block in <class:CLI>'"]

In the above output you can see what should be /rootfs/proc/stat is 0.0/stat, because that user input is being converted to a float.

ubuntu excluded, not using platform_family

tl;dr: Suggest changing platform to platform_family.

After adding this asset to a Sensu Backend, using sensuctl asset add sensu-plugins/sensu-plugins-cpu-checks --rename sensu-plugins-cpu-checks, the current 4.0.0 release shows this Bonsai metadata (sensuctl asset list --format=yaml):

---
type: Asset
api_version: core/v2
metadata:
  annotations:
    io.sensu.bonsai.api_url: https://bonsai.sensu.io/api/v1/assets/sensu-plugins/sensu-plugins-cpu-checks
    io.sensu.bonsai.name: sensu-plugins-cpu-checks
    io.sensu.bonsai.namespace: sensu-plugins
    io.sensu.bonsai.tags: ruby-runtime-2.4.4
    io.sensu.bonsai.tier: Community
    io.sensu.bonsai.url: https://bonsai.sensu.io/assets/sensu-plugins/sensu-plugins-cpu-checks
    io.sensu.bonsai.version: 4.0.0
  name: sensu-plugins-cpu-checks
  namespace: default
spec:
  builds:
  - filters:
    - entity.system.os == 'linux'
    - entity.system.arch == 'amd64'
    - entity.system.platform == 'debian'
    headers: null
    sha512: da5a183ad1a1f76962561eed659c6184b3e5d6a412432e1ccb4297cce123c41f9a8bb4fdb9ab19663aada978ea862ab2bd5f00bc91e4769ddd87543f5662b3af
    url: https://assets.bonsai.sensu.io/68546e739d96fd695655b77b35b5aabfbabeb056/sensu-plugins-cpu-checks_4.0.0_debian_linux_amd64.tar.gz

(I removed rhel and alpine sections.)

This prevents the asset-managers in sensu agents running on Ubuntu from fetching this asset when running checks. I don't think exluding Ubuntu is intentional?

Thus I suggest changing the metadata from platform to platform_family, and quickly release a 4.0.1.

Scheme not working as expected

I feel that this could be invalid, but I'm opening an issue after spending 4 hours trying to find documentation on the subject in the hopes that a quick answer can be provided. I am attempting to upgrade from Sensu 1.x to Sensu 5.x and am having difficulty with this plugin. Previously I would use '--scheme production.:::name:::' to prefix my metrics, and the hostname would be substituted. This does not appear to be the case now as the substitution is not taking place. Is there some other way of handling this under Sensu 5.x?

gem installation fails on windows due to linux-kstat 0.1.3 dependency

Hi,
having installed sensu 1.4.2-4 on windows, the command
C:\opt\sensu\embedded\bin\gem install sensu-plugins-cpu-checks fails with error:

ERROR: Could not find a valid gem 'linux-kstat' (= 0.1.3) in any repository
ERROR: Possible alternatives: linux-kstat

When I try to download linux-kstat I see only 0.1.0 using gem install linux-kstat I see only 0.1.0 version available.

Best regards,

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.