# Simple CPU Monitoring via nscp-local-cpu?

**URL:** <https://community.icinga.com/t/simple-cpu-monitoring-via-nscp-local-cpu/690>\
**Category:** Service Monitoring\
**Created:** [March 22, 2019, 3:35pm UTC](https://community.icinga.com/t/simple-cpu-monitoring-via-nscp-local-cpu/690 "2019-03-22T15:35:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![funk0id](https://community.icinga.com/user_avatar/community.icinga.com/funk0id/32/389_2.png) [@funk0id](https://community.icinga.com/u/funk0id)\
**Post date:** [March 22, 2019, 3:35pm UTC](https://community.icinga.com/t/simple-cpu-monitoring-via-nscp-local-cpu/690/1 "2019-03-22T15:35:40Z")

</div>

New to icinga so go easy 🙂

I’m pulling in what I thought would be CPU usage via nscp-local-cpu, even though the processor isn’t being hit hard, it’s flagged as critical and just displays the disk stats again as in the screenshot attached?

Probably me completely missing the point again but thought I’d reach out for help!

Thanks

 ![cpugrab](https://community.icinga.com/uploads/default/original/1X/b97b41fc10c8840938c58bad93ffc47233bcec70.png)

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [March 22, 2019, 4:27pm UTC](https://community.icinga.com/t/simple-cpu-monitoring-via-nscp-local-cpu/690/2 "2019-03-22T16:27:53Z")

</div>

Hi,

nscp-local-cpu has a design flaw, as it only takes a short snapshot. In order to measure the CPU load, you’ll need to hold and calculate performance counters over time, and calculate the average from it. This is what NSClient++ does as a service and was the main motivation behind development `check_nscp_api` querying its REST API.

The instructions for a local setup can be found inside the docs. First off, ensure that NSClient++ has an API password set during the [setup](https://icinga.com/docs/icinga2/latest/doc/06-distributed-monitoring/#bundled-nsclient-setup) routine. You can also do that manually as described in its [docs](http://docs.nsclient.org/api/rest/#enable-the-webserver-module).

Then you’ll integrate the provided CheckCommand into an actual service like described [here](https://icinga.com/docs/icinga2/latest/doc/06-distributed-monitoring/#nsclient-with-check_nscp_api). The main difference are the command arguments, [modify](http://docs.nsclient.org/api/rest/legacy/#checksystem-module) them like this:

```auto
object Host "windows-host.fqdn" {
  address = "..."
  vars.client_endpoint = name //requires the endpoint object called 'windows-host.fqdn'

  vars.nscp_api_password = NscpApiPassword //define this constant in constants.conf

  vars.os_type = "windows"
}

apply Service "cpu" {
  import "generic-service"

  check_command = "nscp_api"
  command_endpoint = host.vars.client_endpoint

  vars.nscp_api_host = "localhost"
  vars.nscp_api_password = host.vars.nscp_api_password //will be hidden in Icinga Web 2's detail view by default (security config)

  vars.nscp_api_query = "check_cpu"
  vars.nscp_api_arguments = ["warning=load>1", "critical=load>20"]

  assign where host.vars.os_type == "windows"
}

```

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![funk0id](https://community.icinga.com/user_avatar/community.icinga.com/funk0id/32/389_2.png) [@funk0id](https://community.icinga.com/u/funk0id)\
**Post date:** [March 22, 2019, 4:37pm UTC](https://community.icinga.com/t/simple-cpu-monitoring-via-nscp-local-cpu/690/3 "2019-03-22T16:37:49Z")

</div>

Thanks for your help, really useful.

Next challenge, sorting the check\_nscp\_api, not sure there is a way of enabling this on install as part of the icinga2-powershell-module.

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [March 22, 2019, 4:45pm UTC](https://community.icinga.com/t/simple-cpu-monitoring-via-nscp-local-cpu/690/4 "2019-03-22T16:45:27Z")

</div>

When NSClient++ is installed (and it already is since you’re using nscp-local-cpu), you can use the [linked](http://docs.nsclient.org/api/rest/#enable-the-webserver-module) command to enable this via CLI (and add this to your script calls after the main PS script).

```auto
nscp web install --password <MY SECURE API KEY>

```

Keep in mind that the API enabled here has no permission system (yet, Michael is working on that), so you’ll get everything (even stopping the service) or nothing. That is why the above examples still use Icinga 2 as client command endpoint and only query the service **locally**.

Cheers,  
Michael
