The Calculated Performance (ZenPacks.zenoss.CalculatedPerformance) ZenPack adds two new datasources types to Zenoss: Calculated Performance, and Datapoint Aggregator.
The Calculated Performance datasource type allows datapoints to be collected that are derived from numeric model properties and the most recent value of other datapoints on the same device or component. This means that only model properties and datapoint values for the device or component the template is bound to can be used to calculated the derived datapoint value.
Example usages of the Calculated Performance datasource type:
- (cpuUser + cpuSystem) = cpuUsage
- (usedBytes / totalBytes) * 100 = usedPercent
The Datapoint Aggregator datasource type addresses the single device or component restriction of the Calculated Performance datasource type. It allows the following aggregation operations such as count, sum, avg, min, and max to be used on many device or components that have a datapoint by the same name.
Example usages of the Datapoint Aggregator datasource type:
- sum(ifInOctets on all interfaces)
- sum(ifInOctets on some interfaces)
Let's walk through an example of using a Datapoint Aggregator datasource to collect and graph the total network throughput on all of a device's interfaces. We'll use a Cisco C2960 as an example.
-
Create a new monitoring template named Network SNMP in the /Network device class.
-
Add a Datapoint Aggregator datasource named ifHCInOctets.
-
Edit the ifHCInOctets datasource, set the following fields, then save.
- Method:
os.interfaces
- Datasource:
ifHCInOctets
- Datapoint:
ifHCInOctets
- Method:
-
Add a datapoint named sum to the ifHCInOctets datasource.
-
Edit the ifHCInOctets.sum datapoint, set the following fields, then save.
- Operation:
sum
- Operation:
-
-
Repeat step 2 replacing ifHCInOctets with ifHCOutOctets.
-
Add a graph named Total Network Throughput.
-
Edit the Total Network Throughput graph, set the following fields, then save.
- Units:
bits/sec
- Min Y:
0
- Units:
-
Choose Manage Graph Points from the Graph Definitions gear menu.
-
Click the + to add both datapoints to the graph.
-
Edit each graph point, set the following fields, then save.
- Name:
Inbound
(or Outbound for ifHCOutOctets_sum) - Format:
%7.2lf%s
- RPN:
8,*
The RPN multiplies the value by 8 to convert from octets (bytes) to the bits that we want to display.
- Name:
-
Click Save on the Manage Graph Points dialog.
-
-
Bind the Network SNMP template to an appropriate device or device class.
For testing, I'll just bind it to a single device. Once it's working the way we want on our one device we might want to bind it to an entire device class.
Aggregating network throughput across all interfaces was easy enough, but what if we only wanted to get the total throughput of some interfaces we know to be used for a specific purpose. Perhaps just uplink interfaces, or something like that. It can be done, but it's a bit more involved.
The only thing that's different for aggregating some interfaces instead of all interfaces is the method defined in our datapoint aggregator datasource. Referring to all interfaces was easy, we just used "os.interfaces". Refering to a group of potentially arbitrary interfaces will require a way for us to define which interfaces are part of the group. We'll also have to create a script that returns just those interfaces instead of all interfaces. This script will become the method for our datapoint aggregator datasource.
-
Create the new custom property.
-
Navigate to the Infrastructure page.
-
Click the Details button at the top of the left pane with the root DEVICES selected.
-
Click Custom Schema on the left pane.
-
Add a property with the following fields set.
- Label:
Interface Group 1
- Name:
cInterfaceGroup1
- Type:
lines
- Label:
-
-
Set a value for the custom property on a device.
-
Navigate to your test device and click Custom Properties on the left pane.
-
Set the value of Interface Group 1 to something like the following.
GigabitEthernet0_1 GigabitEthernet0_2
Note that it is one interface id per line. You'll note that the interface id is slightly different than its name. For example, the forward slash (/) has been replaced with an underscore (_). The best way to make sure you have the id correct is to navigate to the interface in the web interface, then look at the end of the brower's URL bar.
-
-
Navigate to http://zenoss.example.com/zport/dmd/Devices/manage.
The Manager role is required to do this.
-
Choose Script (Python) from the Add drop-down near the top-right.
-
Set Id to in_cInterfaceGroup1 then click Add and Edit.
-
Replace the contents of the big text area with the following.
interfaces = [] names = getattr(context, 'cInterfaceGroup1', None) if names: for name in names: if name: try: interfaces.append(context.getObjByPath('os/interfaces/{}'.format(name))) except Exception: pass return interfaces
-
Click Save Changes.
-
You can test that the script works in zendmd as follows.
find("device-id").in_cInterfaceGroup1()
Now the only thing left to do is to update the datasources in our Network
SNMP monitoring template to use in_cInterfaceGroup1
as their method instead
of os.interfaces
. You might also want to change the graph's name from Total Network Throughput to something like Total Uplink Network Throughput.
To aggregate across devices use a script that looks something like:
Obviously I've used the same cProp, and have selected everything under the /Devices/Network/Cisco branch - both of those can be changed according to your needs.