Monitoring R Applications with RZabbix

September 14, 2016
By

(This article was first published on http://r-addict.com, and kindly contributed to R-bloggers)

As R users we mostly perform analysis, produce reports and create interactive shiny applications. Those are rather one-time performances. Sometimes, however, the R developer enters the world of the real software development, where R applications should be distributed and maintained on many machines. Then one really appreciates the value of a proper applications monitoring. In this post I present my last package called RZabbix – the R interface to the Zabbix API data.

What is Zabbix?

According to procudct overview

With Zabbix it is possible to gather virtually limitless types of data from the network. High performance real-time monitoring means that tens of thousands of servers, virtual machines and network devices can be monitored simultaneously. Along with storing the data, visualization features are available (overviews, maps, graphs, screens, etc), as well as very flexible ways of analyzing the data for the purpose of alerting.

This Ultimate Enterprise-class Monitoring Platform was nominated for the 2nd time among world’s best monitoring solutions according to Gartner

Zabbix can be used to Monitor everything – servers, network devices and applications, gathering accurate statistics and performance data.


Connect from R with RZabbix Star

I have created a simple R connector to Zabbix API, packed in the library and released it on Share Zabbix and also on CRAN.

You can install the package with

install.packages('RZabbix') 
library(RZabbix)
?ZabbixAPI # help manual page

and then connect to Zabbix API with

ZabbixAPI(
   'http://localhost/zabbix/',
    body = 
      list(method = "user.login",
           params = jsonlite::unbox(
            data.frame(user = "Admin",
                       password = "zabbix")))
   ) -> auth

The authentication is required, because every other call need to use auth parameter in its body.

Base information of the API version can be checked with

ZabbixAPI(
   'http://localhost/zabbix',
    body = 
       list(method = "apiinfo.version"))

and the regular request to get history of an item of item_id number can be done as below

ZabbixAPI(
   'http://localhost/zabbix',
    body = 
       list(method = "history.get",
            params = jsonlite::unbox(
           data.frame(output = "extend",
                      itemids = "item_id",
                      history = 0,
                      sortfield = "clock",
                      sortorder = "DESC",
                      limit = 10)
               ),
               auth = auth))

The body parameter can be also passed as a JSON string – see example for getting event data for object with object_id number

library(jsonlite)
paste0('{
    "method": "event.get",
    "params": {
        "output": "extend",
        "select_acknowledges": "extend",
        "objectids": "object_id",
        "sortfield": ["clock", "eventid"],
        "sortorder": "DESC"
    },
    "auth": "', auth, '"
}') -> json_rpc

ZabbixAPI('http://localhost/zabbix',
          body = fromJSON(json_rpc)) -> event.info

Methods and params to Zabbix API can be found in Method reference. It is a great date, because few days ago new version of Zabbix (3.2) was released.

You can try to set your own Zabbix Server from Docker container or you can use public test Zabbix on zabbix.org. If you are not yet motivated for using Docker then read my post from May
R 3.3.0 is another motivation for Docker
or join 10th Cracow R User Group meetup at the end of September where I will present Rocker: explanation and motivation for Docker containers usage in applications development (by R user, for R users)

Example of usage

Jan Garaj from Monitoring Artist has used RZabbix to provide Monitoring Analytics – R statistical computing and graphic tool for monitoring metrics from data scientists.

Monitoring Analytics

You can contribute!

RZabbix is still a young package and many can be done. If you would like to contribute then fill free to Fork the RZabbix repository. I am currently looking for examples on how to create a SLA overview for a specific host, calculate the amount of diskspace used by all active hosts and filesystems and create a overview of the most active triggers and I am thinking about adding tests.

To leave a comment for the author, please follow the link and comment on their blog: http://r-addict.com.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)