|February 21, 2012 02:00 AM EST||
One advantage of using Monitis to monitor your systems and applications is the flexibility to use either the native agent or custom monitor code written in virtually any language. For custom monitors, the REST API provides the basic foundation to interface programmatically with Monitis. For many popular languages, there are open source SDKs available to make the process of interfacing with Monitis even easier. You can find links to Java, Perl, PHP, Ruby, C#, PowerShell, and VisualBasic SDKs and example scripts at http://monitis.com/api/api.html#sdk.
The Monitis Sandbox
For this article, we’ll be using the Monitis sandbox, a free development environment available to aid in the creation of Monitis custom monitors. You can sign up for an account at http://sandbox.monitis.com/.
Netstat is a command available on unix systems to provide information about the state of the network interfaces. It has several modes, one of which can display statistics about the number of packets and datagrams sent and received. While there is no common API across unix systems to access this data, it is possible to extract this information from the text output of the program. Since the output varies slightly from system to system, it is necessary to take these variations into account when using that output.
Netstat examples using the Python Monitis SDK
The examples for this article are available at https://github.com/monitisexchange/Python-SDK/tree/master/examples. There are two examples. The first, monitis_netstat.py, can be used as is to create, list, update, and delete netstat monitors. The second, monitis_netstat_minimal.py, is a minimal implementation intended to illustrate the concepts for this article, but lacking the structure to handle command line arguments, different operating systems, etc.
Let’s take a look at monitis_netstat_minimal.py, line by line. It illustrates many of the core concepts in the Python SDK.
The following lines are imports from the Python standard library, used for calling netstat, searching its output, and comparing output from netstat with that retrieved via the SDK.
from subprocess import Popen, PIPE from re import findall from datetime import datetime
Next are the imports from the Monitis Python SDK itself, used for creating new monitors and fetching existing monitors.
from monitis.monitors.custom import CustomMonitor, get_monitors from monitis.monitors.params import ResultParams, DataType from monitis.api import Monitis
The Monitis.sandbox flag causes the SDK to use the Monitis developer’s sandbox, http://sandbox.monitis.com. By default, when this flag isn’t set, it uses the production environment, http://www.monitis.com.
Monitis.sandbox = True
The following block creates a new monitor. ResultParams encapsulates the format for the parameters that a monitor accepts. One or more of them can be passed in to the next line. CustomMonitor.addMonitor takes the parameters and creates a monitor based on them. It returns a new CustomMonitor object that represents the monitor in the Monitis API.
rp = ResultParams( 'tcp_packets_in','TCP Packets In','pkts/s', DataType('integer')) cm = CustomMonitor.add_monitor(rp, name='netstat monitor', tag='netstat') print "Created monitor: %s" % cm.monitor_id
This code extracts the interesting data from the netstat output. In this case, that data is the count of TCP packets received. This is the only block of code in the minimal sample program that really isn’t dependent on the API. A different monitor could get data in any number of ways. Note that this call to netstat is based on OS X style output, but only a small change to the command and matching string is required to adapt it to virtually any unix-like operating system.
subproc = Popen( 'netstat -s -p tcp | grep "packets received$"', shell=True, stdout=PIPE) (netstat_out, netstat_err) = subproc.communicate() count = findall('(\d+) packets received', netstat_out)
Next, add_result takes the new data, and posts it in the format defined earlier in ResultParams.
Here, we check that retrieving the results from the monitor gets back the same data that we put in.
today = datetime.utcnow() result = cm.get_monitor_results(today.year, today.month, today.day)
Finally, delete the monitor. This exists in this example so that it cleans up after itself and doesn’t cause unused custom monitors to pile up.
In typical usage, a monitor is only deleted when that data is no longer needed. This principle is explored further in monitis_netstat.py.
Under normal circumstances, a monitor is created once, data is updated on a periodic basis over time, and then that data is viewed in the Monitis web interface. To ilustrate this, monitis_netstat.py has command line flags to create, list, delete, and update a monitor.
Create a new netstat monitor:
$ examples/monitis_netstat.py -s -c netstat_mon Using name netstat_mon Created new netstat monitor
List the monitors to verify that ours was created:
$ examples/monitis_netstat.py -s -l 2267 netstat_mon
Run the monitor 10 times over five minutes to gather some data to display.
$ while (true) do examples/monitis_netstat.py -s -u 2267; sleep 30; done 1253222, 1616400, 381497, 551524 1253393, 1616514, 381505, 551536 1253436, 1616553, 381512, 551545 1253468, 1616580, 381514, 551549 1253485, 1616596, 381517, 551558 1253526, 1616633, 381522, 551609 1253564, 1616666, 381531, 551622 1253599, 1616695, 381536, 551629 1253623, 1616716, 381538, 551633 1253647, 1616740, 381544, 551638
$ examples/monitis_netstat.py -s -d 2267 Monitor 2267 deleted $ examples/monitis_netstat.py -s -l
To get the code and try this yourself, you can clone a copy from GitHub, install the Monitis SDK module, and run it on your own system.
git clone git://github.com/monitisexchange/Python-SDK.git cd Python-SDK sudo python setup.py install
Monitis API Keys
Before you can run the tools, you will also need to set up the Monitis API Key and Secret Key. By default, these are read from the following environment variables, which you can set on the command line, or add to your .bashrc or other login command file. The values for these keys can be retrieved via the web user interface under Tools -> API -> API Key.
# production keys export MONITIS_APIKEY='API KEY' export MONITIS_SECRETKEY='SECRET KEY' # sandbox keys export MONITIS_SANDBOX_APIKEY='SANDBOX API KEY' export MONITIS_SANDBOX_SECRETKEY='SANDBOX SECRET KEY'
While the Monitis REST API makes creating custom monitors simple in almost any language, it becomes truly easy with an SDK to handle the REST interactions. This article has illustrated just how effortless it can be to collect important information from your systems and record it in Monitis custom monitors.
Signup and use free monitis sandbox here - http://sandbox.monitis.com.
See also Python Performance Tips, Part 1Share Now:
We are rapidly moving to a brave new world of interconnected smart homes, cars, offices and factories known as the Internet of Things (IoT). Sensors and monitoring devices will touch every part of our lives. Let's take a closer look at the Internet of Things. The Internet of Things is a worldwide network of objects and devices connected to the Internet. They are electronics, sensors, software and more. These objects connect to the Internet and can be controlled remotely via apps and programs. Because they can be accessed via the Internet, these devices create a tremendous opportunity to inte...
Nov. 26, 2015 02:15 PM EST Reads: 487
Today air travel is a minefield of delays, hassles and customer disappointment. Airlines struggle to revitalize the experience. GE and M2Mi will demonstrate practical examples of how IoT solutions are helping airlines bring back personalization, reduce trip time and improve reliability. In their session at @ThingsExpo, Shyam Varan Nath, Principal Architect with GE, and Dr. Sarah Cooper, M2Mi’s VP Business Development and Engineering, explored the IoT cloud-based platform technologies driving this change including privacy controls, data transparency and integration of real time context with p...
Nov. 26, 2015 01:00 PM EST Reads: 383
We all know that data growth is exploding and storage budgets are shrinking. Instead of showing you charts on about how much data there is, in his General Session at 17th Cloud Expo, Scott Cleland, Senior Director of Product Marketing at HGST, showed how to capture all of your data in one place. After you have your data under control, you can then analyze it in one place, saving time and resources.
Nov. 26, 2015 12:00 PM EST Reads: 143
The Internet of Things (IoT) is growing rapidly by extending current technologies, products and networks. By 2020, Cisco estimates there will be 50 billion connected devices. Gartner has forecast revenues of over $300 billion, just to IoT suppliers. Now is the time to figure out how you’ll make money – not just create innovative products. With hundreds of new products and companies jumping into the IoT fray every month, there’s no shortage of innovation. Despite this, McKinsey/VisionMobile data shows "less than 10 percent of IoT developers are making enough to support a reasonably sized team....
Nov. 26, 2015 11:00 AM EST Reads: 440
Just over a week ago I received a long and loud sustained applause for a presentation I delivered at this year’s Cloud Expo in Santa Clara. I was extremely pleased with the turnout and had some very good conversations with many of the attendees. Over the next few days I had many more meaningful conversations and was not only happy with the results but also learned a few new things. Here is everything I learned in those three days distilled into three short points.
Nov. 26, 2015 10:00 AM EST Reads: 282
DevOps is about increasing efficiency, but nothing is more inefficient than building the same application twice. However, this is a routine occurrence with enterprise applications that need both a rich desktop web interface and strong mobile support. With recent technological advances from Isomorphic Software and others, rich desktop and tuned mobile experiences can now be created with a single codebase – without compromising functionality, performance or usability. In his session at DevOps Summit, Charles Kendrick, CTO and Chief Architect at Isomorphic Software, demonstrated examples of com...
Nov. 26, 2015 09:45 AM EST Reads: 363
As organizations realize the scope of the Internet of Things, gaining key insights from Big Data, through the use of advanced analytics, becomes crucial. However, IoT also creates the need for petabyte scale storage of data from millions of devices. A new type of Storage is required which seamlessly integrates robust data analytics with massive scale. These storage systems will act as “smart systems” provide in-place analytics that speed discovery and enable businesses to quickly derive meaningful and actionable insights. In his session at @ThingsExpo, Paul Turner, Chief Marketing Officer at...
Nov. 26, 2015 09:30 AM EST Reads: 370
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
Nov. 26, 2015 09:00 AM EST Reads: 474
In his General Session at 17th Cloud Expo, Bruce Swann, Senior Product Marketing Manager for Adobe Campaign, explored the key ingredients of cross-channel marketing in a digital world. Learn how the Adobe Marketing Cloud can help marketers embrace opportunities for personalized, relevant and real-time customer engagement across offline (direct mail, point of sale, call center) and digital (email, website, SMS, mobile apps, social networks, connected objects).
Nov. 26, 2015 08:45 AM EST Reads: 263
The Internet of Everything is re-shaping technology trends–moving away from “request/response” architecture to an “always-on” Streaming Web where data is in constant motion and secure, reliable communication is an absolute necessity. As more and more THINGS go online, the challenges that developers will need to address will only increase exponentially. In his session at @ThingsExpo, Todd Greene, Founder & CEO of PubNub, exploreed the current state of IoT connectivity and review key trends and technology requirements that will drive the Internet of Things from hype to reality.
Nov. 26, 2015 06:45 AM EST Reads: 398
Two weeks ago (November 3-5), I attended the Cloud Expo Silicon Valley as a speaker, where I presented on the security and privacy due diligence requirements for cloud solutions. Cloud security is a topical issue for every CIO, CISO, and technology buyer. Decision-makers are always looking for insights on how to mitigate the security risks of implementing and using cloud solutions. Based on the presentation topics covered at the conference, as well as the general discussions heard between sessions, I wanted to share some of my observations on emerging trends. As cyber security serves as a fou...
Nov. 26, 2015 06:15 AM EST Reads: 300
Continuous processes around the development and deployment of applications are both impacted by -- and a benefit to -- the Internet of Things trend. To help better understand the relationship between DevOps and a plethora of new end-devices and data please welcome Gary Gruver, consultant, author and a former IT executive who has led many large-scale IT transformation projects, and John Jeremiah, Technology Evangelist at Hewlett Packard Enterprise (HPE), on Twitter at @j_jeremiah. The discussion is moderated by me, Dana Gardner, Principal Analyst at Interarbor Solutions.
Nov. 26, 2015 03:45 AM EST Reads: 693
Too often with compelling new technologies market participants become overly enamored with that attractiveness of the technology and neglect underlying business drivers. This tendency, what some call the “newest shiny object syndrome” is understandable given that virtually all of us are heavily engaged in technology. But it is also mistaken. Without concrete business cases driving its deployment, IoT, like many other technologies before it, will fade into obscurity.
Nov. 26, 2015 03:00 AM EST Reads: 307
With all the incredible momentum behind the Internet of Things (IoT) industry, it is easy to forget that not a single CEO wakes up and wonders if “my IoT is broken.” What they wonder is if they are making the right decisions to do all they can to increase revenue, decrease costs, and improve customer experience – effectively the same challenges they have always had in growing their business. The exciting thing about the IoT industry is now these decisions can be better, faster, and smarter. Now all corporate assets – people, objects, and spaces – can share information about themselves and thei...
Nov. 26, 2015 02:00 AM EST Reads: 193
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids and Smart Cities, the Industrial Internet, and more. Cool platforms like Arduino, Raspberry Pi, Intel's Galileo and Edison, and a diverse world of sensors are making the IoT a great toy box for developers in all these areas. In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists discussed what things are the most important, which will have the most profound effect on the world, and what should we expect to see over the next couple of years.
Nov. 26, 2015 01:30 AM EST Reads: 438
PubNub has announced the release of BLOCKS, a set of customizable microservices that give developers a simple way to add code and deploy features for realtime apps.PubNub BLOCKS executes business logic directly on the data streaming through PubNub’s network without splitting it off to an intermediary server controlled by the customer. This revolutionary approach streamlines app development, reduces endpoint-to-endpoint latency, and allows apps to better leverage the enormous scalability of PubNub’s Data Stream Network.
Nov. 26, 2015 12:00 AM EST Reads: 288
Discussions of cloud computing have evolved in recent years from a focus on specific types of cloud, to a world of hybrid cloud, and to a world dominated by the APIs that make today's multi-cloud environments and hybrid clouds possible. In this Power Panel at 17th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the importance of customers being able to use the specific technologies they need, through environments and ecosystems that expose their APIs to make true change and transformation possible.
Nov. 26, 2015 12:00 AM EST Reads: 493
Growth hacking is common for startups to make unheard-of progress in building their business. Career Hacks can help Geek Girls and those who support them (yes, that's you too, Dad!) to excel in this typically male-dominated world. Get ready to learn the facts: Is there a bias against women in the tech / developer communities? Why are women 50% of the workforce, but hold only 24% of the STEM or IT positions? Some beginnings of what to do about it! In her Day 2 Keynote at 17th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, wil...
Nov. 26, 2015 12:00 AM EST Reads: 532
Microservices are a very exciting architectural approach that many organizations are looking to as a way to accelerate innovation. Microservices promise to allow teams to move away from monolithic "ball of mud" systems, but the reality is that, in the vast majority of organizations, different projects and technologies will continue to be developed at different speeds. How to handle the dependencies between these disparate systems with different iteration cycles? Consider the "canoncial problem" in this scenario: microservice A (releases daily) depends on a couple of additions to backend B (re...
Nov. 25, 2015 10:00 PM EST Reads: 398
I recently attended and was a speaker at the 4th International Internet of @ThingsExpo at the Santa Clara Convention Center. I also had the opportunity to attend this event last year and I wrote a blog from that show talking about how the “Enterprise Impact of IoT” was a key theme of last year’s show. I was curious to see if the same theme would still resonate 365 days later and what, if any, changes I would see in the content presented.
Nov. 25, 2015 09:00 PM EST Reads: 373