docs: rewrite device setup and RRDtool graphing guides (#328)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
This commit is contained in:
Thomas Vincent authored and GitHub committed 2026-12-03 00:14:19 -08:00
1 parent 24dbcb4992
commit 008b36f19d
3 files changed
+213 -764

No files matched your search

+88 -129
View File
@@ -1,153 +1,112 @@
# Device Management
This section will describe **Device** management in Cacti.
A device tells Cacti where to collect measurements and which data collector
should collect them. Adding a device gives you a place to configure polling.
Choose the measurements to graph after you save it.
Adding a **Device** to Cacti can be done in a few different ways, either via
the Web GUI, Cacti's Automation, or the Command Line Interface (CLI).
## Add a device in the console
## Web GUI Option
1. Open **Console > Management > Devices** and select **Add** (+).
2. Enter a **Description** that operators will recognize in lists and graph
titles. In **Hostname**, enter a DNS name that the collector can resolve
or an IP address. Enclose an IPv6 address in brackets, as in
`[2001:db8::15]`.
3. Under **Poller Association**, choose the collector that can reach the device.
Select a **Device Template** that supplies the graph templates and data
queries you need. For an interface graph, the device's SNMP agent must expose
the interface counters used by the query. Check the available templates
and their requirements in [Device Templates](Device-Templates.md).
4. Choose the **Downed Device Detection** method and configure the credentials
required by your data inputs. To stage the device before polling begins,
select **Disable Device**. Save the device.
To add a device via the Web GUI first click on `Console > Management > Devices` and
you will see the below device console window which will show existing devices
if any
![Hostname, collector and template fields](images/add-device-screen.png)
![Device Console](images/device-console-window.png)
**Device Site Association** groups devices by site. **Location** records a more
specific place, such as a rack. Use **External ID** to associate the device
with an inventory record and **Notes** for local context. Installed plugins
can add fields such as notification settings. Configure those fields according
to the plugin that owns them.
You will now select the + on the top right hand corner
## Choose an availability check
![Add Device Button](images/add-device-button.png)
A failed availability check can stop the poller from collecting otherwise
reachable measurements. Choose a test that the assigned collector can perform
and that the device is configured to answer.
Once you select the + otherwise known as the add device button you will see the
below screen which will ask you for device specific information
| Downed Device Detection | When to use it |
| --- | --- |
| None | Skip the availability probe. Useful for a local script or another input that has no device to probe. |
| Ping | Determine reachability with the selected ICMP, TCP or UDP method. Set the destination port for a port-based check. **TCP Ping Closed** also accepts a connection refusal as evidence that the host answered. |
| SNMP Uptime | Check whether the device answers an uptime query. The PHP poller tries `sysUpTime.0` and falls back to `snmpEngineTime.0`. |
| Ping and SNMP Uptime | Require both checks to succeed. Use this when the collector can reach both services. |
| Ping or SNMP Uptime | Accept a successful response from either check. Use this when one protocol may be filtered. |
| SNMP Desc | Query `sysDescr.0` on a device that exposes its description. |
| SNMP getNext | The PHP poller requests the next accessible OID after `sysUpTime.0` (`.1.3.6.1.2.1.1.3.0`). If that fails, it tries after `snmpEngineTime.0` (`.1.3.6.1.6.3.10.2.1.3.0`). Reproduce the check with the same SNMP view and starting OIDs. |
Some of the most important information about the device will be required in this
window which includes
## Configure collection
- **Description** - The name that will appear on **Graphs** by default
- **Hostname** - The DNS or IP address of the actual **Device**. Insert an IPv6 address into brackets (example: [2001:abcd:1234::1])
- **Poller Association** - Defines which **Data Collector** is responsible for
pulling information about the **Device**
- **Device Template** - Cisco, Net-SNMP, Linux, etc - The Cacti object that
holds all the **Graph Templates** and **Data Queries** to be graphed
- **Device Site Association, Location** - Very important for performing Meta
queries, or for
Site level Graph organization on Cacti **Graph Trees**
- **Availability/Reachability** - Settings that describe **Device**
timeouts and availability methods.
- **SNMP information** - SNMP Credentials for connecting to the **Device**
- **Notes** - Arbitrary unstructured information about the **Device**
For a script-only device, select **Not In Use** for **SNMP Version** and choose
an availability method the script host supports. For an SNMP query or an SNMP
availability check, match the version and credentials to the agent.
![Add Device Info Screen](images/add-device-screen.png)
| SNMP version | Collector settings |
| --- | --- |
| Version 1 | Supply the read community. Use this for agents that require v1. Interface monitoring is limited to 32-bit counters. |
| Version 2c | Supply the read community. Use 64-bit interface counters when the device exposes them. The community travels in clear text. |
| Version 3 | Supply the username. For authenticated requests, match the authentication protocol and passphrase. For encrypted requests, also match the privacy protocol and passphrase. Set the context when the agent requires one. Available algorithms depend on the SNMP software on the collector. |
Cacti requires this basic information to be able to monitor the device and once
entered, click save on the bottom right corner. With the device created you will
need to add graphs for the device by clicking **Create Graphs for this Device**
on the top right hand corner.
**Maximum OIDs Per Get Request** controls how many values the collector asks
for together. If individual requests succeed but larger requests time out,
reduce the batch size and repeat the check from the assigned collector.
Response size, device limits and the network path all matter.
Choose a [device template](Device-Templates.md) for the device's exposed
measurements. The [template overview](Templates.md) explains bundled examples
and import choices. If no dedicated template is available, generic SNMP
interface monitoring may still work. Vendor and template names do not
guarantee support for every model, firmware version or metric. Check the
device's SNMP agent and permitted view, then inspect its returned query rows
before selecting graphs. For script-based templates, also check the script's
dependencies and access requirements.
**Number of Collection Threads** applies to the Spine poller. For a slow
device with many measurements, compare polling time and timeout counts before
and after increasing this value. A device that limits concurrent requests
can take longer to poll.
## Availability/Reachability Settings
## Add a device from the command line
Cacti prefers to use the Simple Network Management Protocol (SNMP) to communicate
with **Devices**. Therefore, when creating a **Device**, you need to provide SNMP
credentials to obtain information about the **Device** in order to collect data from
it. Before Cacti will query the **Device** for data, it first verifies that the
**Device** is up and responding. When doing so, you have several options.
They include:
Run the following commands from the Cacti application directory with the PHP
runtime and account used for polling. List the templates to find their IDs.
- **None** - Always assume the device is up. This is generally reserved for **Device**
objects that do not have a state.
- **SNMP Uptime** - Query the SNMP Uptime Instance OID
- **Ping and SNMP Uptime** - Ping the device but also check the SNMP Uptime
Instance OID
- **Ping** - Either ICMP, TCP at a port, or UDP as a port. Newer versions have an additional method, TCP Ping Closed.
The device is considered UP even if the TCP ping returns closed
- **Ping or SNMP Uptime** - Only one needs to be working for Cacti to collect data
- **SNMP Desc** - Query the SNMP sysDescr in cases where the SNMP Uptime OID
is not available
- **SNMP getNext** - Query the first available OID in the OID tree for the **Device**.
Used for certain devices that have limited SNMP support.
## SNMP Credentials
When providing the SNMP credentials, Cacti currently supports the following versions:
- **Version 1** - Rarely used any more. Reserved for very old hardware
- **Version 2** - SNMPv2c supports 64-bit counters when the device's agent
exposes them.
- **Version 3** - Fully supported, including advanced settings such as SHA224+
or AES192+ with SNMPv3. Cacti automatically leverages the Net-SNMP binaries
where needed, so there is no need to uninstall the php-snmp module.
When providing the SNMP Credentials, Cacti will warn you if you have provided
incomplete information depending on the SNMP Version and SNMP Security Level
you have specified.
## Additional Important Options
There are some additional options that you should note before starting to use Cacti.
They include the following:
- **Number of Collection Threads** - If your device is far away, and can tolerate multiple threads
querying information, you can increase this number to reduce the time it takes
to collect all information.
- **Maximum OIDs Per Get Request** - Otherwise known as MaxOIDs, this SNMP option
will allow the SNMP client to gather more metrics per get request. Please keep
in mind that the higher you make this number, the longer an SNMP response may take.
So, you have to be sensitive about the SNMP timeout as the number gets larger.
Since, by default, SNMP is generally collected over UDP, you will also be limited
in the number of responses depending on how many routers or VPNs you traverse
to reach a device. When traversing VPN connections, many VPNs limit the MTU
to around 500 bytes, which will significantly limit how large the Max OIDs can
be. In some cases, it may be better to deploy a **Remote Data Collector** when
your device is either far away from a latency perspective, or that you must
traverse VPNs to communicate with.
- **External ID** - This field is normally used for Asset Tracking information for
the **Device**, but its use is entirely up to the System Administrator.
## Plugin Behavior
Many Cacti Plugins can and do add additional columns to the Device table in Cacti.
Depending on the Plugin you have installed, you will find other information that
you can provide about the device including things like:
- **Notification Settings** - Who to notify when the **Device** changes state
- **Criticality** - How important is the device
- **Failure and Recovery Counts** - How long till a device is treated as truly
down.
- **Ping Thresholds** - What RTL is considered bad when reaching a device
## Creating devices via CLI script
You can also create a device by using the CLI script located at /cactidir/cli/
```console
usage: add_device.php --description=[description] --ip=[IP] --template=[ID] [--notes="[]"] [--disable]
[--poller=[id]] [--site=[id] [--external-id=[S]] [--proxy] [--threads=[1]
[--avail=[ping]] --ping_method=[icmp] --ping_port=[N/A, 1-65534] --ping_timeout=[N] --ping_retries=[2]
[--version=[0|1|2|3]] [--community=] [--port=161] [--timeout=500]
[--username= --password=] [--authproto=] [--privpass= --privproto=] [--context=] [--engineid=]
[--quiet]
Required:
--description the name that will be displayed by Cacti in the graphs
--ip self explanatory (can also be a FQDN)
```sh
php cli/add_device.php --list-host-templates
```
To add a device using the bare minimum information would look something like this
This example creates a disabled device for later configuration. Template
`0` selects no template, version `0` disables SNMP, and `--avail=none`
skips availability checks. Replace the description and address with an unused
pair in your installation. The CLI can update an existing record when either
value matches.
```console
$ php add_device.php --description=test --ip=192.168.1.15
Adding test (192.168.1.15) as "Cacti Stats" using SNMP v3 with community "public"
Success - new device-id: (45)
```sh
php cli/add_device.php --description="Lab edge switch" --ip=192.0.2.15 \
--template=0 --version=0 --avail=none --disable=1
```
Open the new device in **Console > Management > Devices**. Confirm its
collector. Set the intended template, credentials and availability method,
then clear **Disable Device** and save. For rule-based onboarding, see
[Automation Networks](Automation-Networks.md).
## Verify collection and create graphs
1. Reopen the device. If it uses SNMP, check the returned device information.
If the check fails, verify the collector, address, port, credentials and
the OIDs the agent permits that account to read.
2. Review **Associated Data Queries**. For an interface graph, confirm that
the query returns the intended interfaces. Run the verbose query if the
rows are missing. See [Data Queries](Data-Queries.md).
3. Select **Create Graphs for this Device**, choose the template or query rows
and create the graphs. Allow enough poll cycles for the first valid
measurement. A counter rate requires two readings.
4. Open the graph under **Console > Management > Graphs**. If it stays blank,
check the data source's last update and the collector log. See
[Data Source Debugging](Data-Debug.md) and
[How to Graph Your Network](How-to-Graph-Your-Network.md).
---
Copyright (c) 2004-2026 The Cacti Group
+125 -635
View File
@@ -1,671 +1,161 @@
# RRDtool Specific Features
Cacti supports most RRDtool features. In this chapter, many of those features,
and some Cacti implementation specifics around them, will be discussed. As
RRDtool is a continually changing Time Series Database (TSDB) and **Graph**
rendering framework, this guide may be a little behind on all the RRDtool
features that Cacti supports.
When a graph shows the wrong value, trace one measurement from collection to
display. The RRDtool data-source type determines what gets stored. A **DEF**
reads a series from an archive. A **CDEF** calculates a value at each point
in time. A **VDEF** summarizes the series over the displayed interval.
A **GPRINT** formats a result in the graph legend.
## Database Data Types
For example, store used and free disk space as gauges. Use a CDEF to draw the
percentage used, a VDEF to find the peak percentage and a GPRINT to label it.
A working example appears below.
There are several different Database **Data Types** that RRDfile supports. They
include all those listed below. Cacti claims to support all, but `COMPUTE`
remains untested.
## Choose a data-source type
| Type | Supported | Description |
| -------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GAUGE | Yes | This is as the term refers to a floating point number that tracks the value reported directly. Unlike the COUNTER, it has no comprehension of past data. |
| COUNTER | Yes | This is a floating point number that tracks the difference between samples to come up with effectively a rate calculation. Used for things like Traffic Graphs where the number reported in SNMP continually increases |
| DCOUNTER | Yes | This is the same as a COUNTER, but in Double Precision. It is offered when RRDtool 1.5 or higher is installed. |
| DERIVE | Yes | This data type measures the Rate of Change of a value, otherwise known as the first derivative to the value. As such, it relies on previous data in order to report the change. |
| DDERIVE | Yes | This is the same as the DERIVE, but in Double Precision. It is offered when RRDtool 1.5 or higher is installed. |
| ABSOLUTE | Yes | Is for counters that get reset upon reading. This is often used for fast counters. It is also similar to the DERIVE, or acts very much like it. |
| COMPUTE | Yes | Though Cacti claims to support this Data Type, it's not clear that it's presently working. |
Set the type on the data-source item in the
[Data Source Template](Data-Source-Templates.md).
Match it to what the collector returns. For example, an interface that reports
total octets needs a rate calculation, while a sensor that already reports
octets per second needs a gauge.
> **NOTE**: Presently `Holt-Winters Forecasting` is not supported in Cacti and
> The Cacti Group has no plans on supporting it. If you would like
> `Holt-Winters Forecasting` supported in Cacti, you will need to submit a pull
> request including documentation if you require its functionality.
| Type | What RRDtool does with the reading |
| --- | --- |
| GAUGE | Stores the measured level, such as bytes free, degrees or the number of active sessions. |
| COUNTER | Converts differences between successive readings of a monotonically increasing integer counter into a per-second rate. A decrease is treated as a possible counter wrap. Choose a realistic maximum rate to help reject reset spikes. |
| DERIVE | Converts the signed difference between successive readings into a per-second rate. For a counter that can reset, a minimum of zero rejects negative rates. |
| ABSOLUTE | Divides each reading by the elapsed time. Use it when each reading counts events since the previous read and the device then resets the count. |
| DCOUNTER | Computes a rate from a floating-point counter. RRDtool detects its increasing or decreasing direction. Cacti offers this type with RRDtool 1.5 or later. |
| DDERIVE | Computes a signed rate of change from floating-point readings. Cacti offers this type with RRDtool 1.5 or later. |
| COMPUTE | Unsupported in Cacti's standard data-template creation workflow. RRDtool requires an expression such as `used,free,+`. Cacti's create command supplies heartbeat, minimum and maximum in that position. For a display calculation, use a CDEF. |
## GPRINT Presets
A heartbeat sets the longest acceptable interval between readings. A gap longer
than the heartbeat, or a calculated value outside the configured bounds,
produces unknown data. When troubleshooting a gap, check the polling interval,
heartbeat and units of the stored value. For data-source syntax and archive
types, including Holt-Winters forecasting in RRDtool itself, see the
[rrdcreate](https://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html).
A GPRINT is a graph item type that enables you to print the values of data
sources on a graph. They are typically used to represent legend values on the
graph. The output format of these numbers is controlled by a printf-like format
string. Cacti enables you to keep a global list of these strings that can be
applied to any graph item throughout Cacti. You can see the list of available
formats described on the
[RRDtool Website](https://oss.oetiker.ch/rrdtool/doc/rrdgraph_graph.en.html#PRINT).
## Build a graph calculation in Cacti
### Creating a GPRINT Preset
1. **Calculate a series.** Open **Console > Presets > CDEFs**, add a named
CDEF and save it. Add its items in evaluation order. To convert octets per
second to bits per second, select the special data source **Current Graph
Item Data Source**, enter the custom string `8`, then add the multiplication
operator. Assign that CDEF to the graph item that draws the traffic series.
2. **Summarize the interval.** Open **Console > Presets > VDEFs** to create or
inspect a summary such as a maximum or a percentile. Apply the VDEF to a
graph item that uses the summary. Zooming into a shorter interval can
change the result.
3. **Label the result.** Under **Console > Presets > GPRINTs**, add a preset,
give it a name and enter a format such as `%6.1lf` for one decimal place.
On the graph template, add a GPRINT item for the measurement, select the
preset and enter its legend text. Apply the same unit conversion as the
plotted series if the legend should report the same units.
To create a new GPRINT preset, select GPRINTs under the `Console > Presets`
sub-menu section. Click Add to the right and you
will be presented with an edit page containing two fields. Enter a name for your
GPRINT preset, and the actual printf-like string in the GPRINT Text field. When
you are finished, click the Create button to create your new GPRINT preset.
![CDEF items in evaluation order](images/cdefs-default-example.png)
In the image below, you can see the default GPRINT Presets included in the base
Cacti. These generally cover just about all use cases presently.
The editor uses reverse Polish notation. In `CURRENT_DATA_SOURCE,8,*`,
the operator consumes the two preceding values. Cacti resolves the special
data source when it builds the graph command. In a raw RRDtool command, use
the name assigned by a DEF. For the editor fields, see
[CDEFs](CDEFs.md), [VDEFs](VDEFs.md) and [GPRINT Presets](GPRINTs.md).
![Default Cacti GPRINT's](images/gprint-presets-default.png)
## Total or count graph items
## CDEF's
Cacti builds its all-source and similar-source calculations from AREA, STACK
and LINE1 through LINE3 items that reference a data source. It looks up a
DEF for the consolidation function used by the calculation. A measurement
that appears only in a GPRINT or a comment contributes nothing. For a
similar-source calculation, associate the calculating item with the RRDtool
data-source name you want to match, such as `traffic_in`.
CDEF's allow you to apply mathematical functions to graph data to alter output.
The concept of a CDEF comes straight from RRDtool, and they are written in
reverse polish notation (RPN). For more information regarding the syntax of
CDEF's, check out the
[CDEF tutorial](https://oss.oetiker.ch/rrdtool/tut/cdeftutorial.en.html).
Suppose two interfaces report inbound rates of 10 and 20 octets/s. The graph
also draws an outbound rate of 3 octets/s and draws the first inbound series
a second time. With known samples and the same consolidation function, these
are the contributions from those four items.
From the image below, you can see that Cacti provides a rich set of CDEF's out
of the box. These CDEF's can be imported and exported and are globally assigned
for portability.
| Special data source | Values included | Sum | Count |
| --- | --- | ---: | ---: |
| All Data Sources, exclude duplicates | 10, 20, 3 | 33 | 3 |
| All Data Sources, include duplicates | 10, 20, 3, 10 | 43 | 4 |
| All Similar Data Sources, exclude duplicates, matching `traffic_in` | 10, 20 | 30 | 2 |
| All Similar Data Sources, include duplicates, matching `traffic_in` | 10, 20, 10 | 40 | 3 |
![Default Cacti CDEF's](images/cdefs-default.png)
To calculate the average of the two distinct inbound sources, build the CDEF
`SIMILAR_DATA_SOURCES_NODUPS,COUNT_SIMILAR_DS_NODUPS,/`. For the values
above, the result is 15 octets/s. Check which items qualify, especially if
you attach the calculation to another drawing item. Repeating a source can
change an include-duplicates total.
### Creating a CDEF
Other special data sources expose the current item's configured minimum,
maximum and polling interval, or the graph's configured lower and upper limits.
For the observed maximum over the displayed interval, use a VDEF.
To create a new CDEF in Cacti, select CDEF's under `Console > Presets` sub-menu
section. Once at this screen, click Add to the right. You will be prompted for a
CDEF name, for which you can type anything used to describe your CDEF. Click the
Create button so you are redirected back to the edit page, now with an empty
CDEF Items box. Construct your CDEF by adding an item for each element in the
CDEF string; common types such as operators and functions are enumerated for
your convenience. Below is a basic description of each CDEF item type. You can
see from the image below that CDEF's follow a Reverse Polish Notation (RPN),
which was a very popular way of computing back in the 70s and 80s when
computing devices had much less memory. However, RPN is elegant in its
simplicity.
## Graph disk use as a percentage
![Default Cacti CDEF Example](images/cdefs-default-example.png)
In a Cacti graph template that draws only disk used and disk free, add each
source as a LINE item. Give those two items the CDEF `CURRENT_DATA_SOURCE,0,*`
and color **None** so the raw byte values do not set the percentage scale.
Add an AREA for the used source and apply
`CURRENT_DATA_SOURCE,ALL_DATA_SOURCES_NODUPS,/,100,*`. The denominator now
contains used and free once each. Adding a third distinct plotted source would
change the denominator. A missing reading or zero capacity can leave a gap.
###### Table 19-1. CDEF Item Types
Cacti provides several CDEF Item Types to represent a **Data Source** in order
to provide additional functionality. See below for the documentation. Cacti
presently does not allow you to specify a VNAME for your DEFS, CDEF's and
VDEF's, but instead uses a string pattern to assign them. You will have to take
note of them when creating a **Graph Template**. Those Special Data Source types
are documented below in the next few sections.
| Type | Description |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Function | You can choose a CDEF function to use as the item. [The RRDtool's graph manual](https://oss.oetiker.ch/rrdtool/doc/rrdgraph_data.en.html#CDEF) describes the purpose of each CDEF function. |
| Operator | Just your standard math operators, including modulo (%). |
| Special Data Source | A special data source is basically a flag to tell Cacti to do some special processing when it encounters this CDEF item. The "Current Graph Item Data Source" type basically inserts the name of the data source that is referenced by the graph item that references to this CDEF. Both of the "All Data Sources" types insert a summation of all data sources used on a graph. |
| Another CDEF | You can recursively use another CDEF within this CDEF. |
| Custom String | Sometimes it's just easier to type out the literal CDEF string manually. When referencing to data sources on the graph, remember that Cacti names them 'a', 'b', 'c', '...', starting with the first data source on the graph. |
## VDEF's
VDEF's provide greater functionality than their ancestor CDEF's and may be able
to replace some legacy Cacti functionality like Nth Percentile **Graph
Template** logic. They should be used whenever possible for your **Graph
Templates**.
You can see from the image below that 95th percentile and total bandwidth could
be replaced by using one of the VDEF's below.
![Default Cacti VDEF's](images/vdefs-default.png)
### Creating a VDEF
To create a new VDEF in Cacti, select VDEF's under `Console > Presets` sub-menu
section. Once at this screen, click Add to the right. You will be prompted for a
VDEF name, for which you can type anything used to describe your VDEF. Click the
Create button so you are redirected back to the edit page, now with an empty
VDEF Items box. Construct your VDEF by adding an item for each element in the
VDEF string; common types such as operators and functions are enumerated for
your convenience. Below is a basic description of each VDEF item type. The image
below shows an example VDEF for the Bandwidth type VDEF.
![Default Cacti VDEF Example](images/vdefs-default-example.png)
For additional information on CDEF's and VDEF's see that specific section of the
documentation. Additionally, you can find examples on the
[RRDtool Website](https://oss.oetiker.ch/rrdtool/doc/rrdgraph_data.en.html#VDEF).
### Special Data Sources
The Special Data Source selection introduces some variables not known to plain
vanilla RRDtool. Let's spend a few words on them to unleash their power.
###### Table 19-2. CDEF Special Data Source
| Special Data Source | Description |
| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Current Graph Item Data Source | Will be replaced by the DEF name of the RRDtool data source referred by the graph item this CDEF is associated to. |
| All Data Sources (Do not Include Duplicates) | Will add up all data sources of the whole graph to form a total. A data source that appears more than once will be counted only once. Data sources that differ by consolidation functions only are NOT counted as different data sources (e.g. traffic_in:AVERAGE and traffic_in:MAX are counted only once). It is NOT required to associate the graph item to any data source! |
| All Data Sources (Include Duplicates) | Will add up all data sources of the whole graph to form a total. A data source that appears more than once will be counted for each time of its appearance. Data sources that differ by consolidation functions only are NOT counted as different data sources (e.g. traffic_in:AVERAGE and traffic_in:MAX are counted only once). It is NOT required to associate the graph item to any data source! |
| All Similar Data Sources (Do not Include Duplicates) | It is REQUIRED to associate the graph item to the data source that shall be totaled! Let's assume the data source is named "traffic_in". Then, Cacti will add up all data sources "traffic_in" of the whole graph to form a data source specific total (e.g. Total traffic In). Data sources with different consolidation functions are counted as same data sources (e.g. traffic_in:AVERAGE and traffic_in:MAX are counted once) |
| All Similar Data Sources (Include Duplicates) | It is REQUIRED to associate the graph item to the data source that shall be totaled! If a data source appears multiple times, it will be added this many times. |
| Current Graph Item Polling Interval | Will be replaced by the step, in seconds, of the RRDfile of the data source referred by the graph item this CDEF is associated to. If the graph item has no data source, the `Poller Interval` setting is used. |
| All Similar Data Sources (Do not Include Duplicates) Polling Interval | Will be replaced by the step, in seconds, of the RRDfile of the data source referred by the graph item this CDEF is associated to, in the same way as `Current Graph Item Polling Interval`. If the graph item has no data source, the `Poller Interval` setting is used. |
| Current Data Source Item: Minimum Value | Taken from the Data Template - Data Source Item related to this graph item: fetches the minimum value defined for the given data template. Caution: This is NOT the smallest entry of the given data source! |
| Current Data Source Item: Maximum Value | Taken from the Data Template - Data Source Item related to this graph item: fetches the maximum value defined for the given data template. Caution: This is NOT the highest entry of the given data source! |
| Graph: Lower Limit | Taken from the Graph Template: fetches the Lower Limit defined to the Graph Template. This is independent of all --alt-autoscaling options. It is NOT the dynamically determined lower boundary of the graph! |
| Graph: Upper Limit | Taken from the Graph Template: fetches the Upper Limit defined to the Graph Template. This is independent of all --alt-autoscaling options. It is NOT the dynamically determined upper boundary of the graph! |
| Count of All Data Sources (Do not Include Duplicates) | Will count the number of all data sources of the whole graph. A data source that appears more than once will be counted only once. Data sources that differ by consolidation functions only are NOT counted as different data sources (e.g. traffic_in:AVERAGE and traffic_in:MAX are counted only once). It is NOT required to associate the graph item to any data source! |
| Count of All Data Sources (Include Duplicates) | Will count the number of all data sources of the whole graph. A data source that appears more than once will be counted for each time of its appearance. Data sources that differ by consolidation functions only are NOT counted as different data sources (e.g. traffic_in:AVERAGE and traffic_in:MAX are counted only once). It is NOT required to associate the graph item to any data source! |
| Count of All Similar Data Sources (Do not Include Duplicates) | It is REQUIRED to associate the graph item to the data source that shall be counted! Let's assume the data source is named "traffic_in". Then, Cacti will count all data sources "traffic_in" of the whole graph. Data sources with different consolidation functions are counted as same data sources (e.g. traffic_in:AVERAGE and traffic_in:MAX are counted once) |
| Count of All Similar Data Sources (Include Duplicates) | It is REQUIRED to associate the graph item to the data source that shall be counted! If a data source appears multiple times, it will be counted this many times. |
While the `All Data Sources/Similar Data Sources` pseudo CDEF variables perform
_totaling_, the `Count All Data Sources/Count Similar Data Sources` pseudo CDEF
Variables simply _count_ the occurrences of the related data sources. Thus, it
is easy to compute e.g. an average of all similar data sources by creating the
CDEF:
`CDEF=SIMILAR_DATA_SOURCES_NODUPS,COUNT_SIMILAR_DS_NODUPS,/`
### Using Special Data Source
Let's have some examples:
This is the list of graph items defined. Please note that Item numbers 17-20
are duplicates of Item numbers 1-4. Even if it usually does not make sense, for
this discussion it is very valuable. Item numbers 21-24 are related to a
`cdef=ALL_DATA_SOURCES_NODUPS`.
| Graph Item | Data Source | Graph Item Type | CF Type |
| :--------- | :--------------------------------------- | --------------: | ------: |
| Item # 1 | (traffic_in): 1. Target Traffic In | LINE1 | AVERAGE |
| Item # 2 | (traffic_in): Current: | GPRINT | LAST |
| Item # 3 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 4 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 5 | (traffic_in): 2. Target Traffic In | LINE1 | AVERAGE |
| Item # 6 | (traffic_in): Current: | GPRINT | LAST |
| Item # 7 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 8 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 9 | (traffic_out): 1. Target Traffic Out | LINE1 | AVERAGE |
| Item # 10 | (traffic_out): Current: | GPRINT | LAST |
| Item # 11 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 12 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 13 | (traffic_out): 2. Target Traffic Out | LINE1 | AVERAGE |
| Item # 14 | (traffic_out): Current: | GPRINT | LAST |
| Item # 15 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 16 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 17 | (traffic_in): 1. Target Again Traffic In | LINE1 | AVERAGE |
| Item # 18 | (traffic_in): Current: | GPRINT | LAST |
| Item # 19 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 20 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 21 | (No Task): AllDsNoDups | LINE1 | AVERAGE |
| Item # 22 | (No Task): Current: | GPRINT | LAST |
| Item # 23 | (No Task): Average: | GPRINT | AVERAGE |
| Item # 24 | (No Task): Maximum:[HR] | GPRINT | MAX |
And this is the rrd graph statement:
To see the calculation independently, run these commands in a new, empty
directory with RRDtool on your path. The two gauges use the same units. Each
update is five minutes apart, starting just after midnight UTC on 1 January
2025.
```sh
/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Traffic AllDsNoDups" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:AVERAGE \
DEF:b="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:MAX \
DEF:c="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:AVERAGE \
DEF:d="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:MAX \
DEF:e="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:AVERAGE \
DEF:f="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:MAX \
DEF:g="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:AVERAGE \
DEF:h="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:MAX \
CDEF:cdefca=TIME,1202925514,GT,a,a,UN,0,a,IF,IF,TIME,1202925514,GT,c,c,UN,0,c,IF,IF,TIME,1202925514,GT,e,e,UN,0,e,IF,IF,TIME,1202925514,GT,g,g,UN,0,g,IF,IF,+,+, \
LINE1:a#FFFF00FF:"1. Target Traffic In" \
GPRINT:a:LAST:" Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:c#FFD660FF:"2. Target Traffic In" \
GPRINT:c:LAST:" Current:%8.2lf%s" \
GPRINT:c:AVERAGE:"Average:%8.2lf%s" \
GPRINT:d:MAX:"Maximum:%8.2lf%sn" \
LINE1:e#CAF100FF:"1. Target Traffic Out" \
GPRINT:e:LAST:" Current:%8.2lf%s" \
GPRINT:e:AVERAGE:"Average:%8.2lf%s" \
GPRINT:f:MAX:"Maximum:%8.2lf%sn" \
LINE1:g#CCBB00FF:"2. Target Traffic Out" \
GPRINT:g:LAST:" Current:%8.2lf%s" \
GPRINT:g:AVERAGE:"Average:%8.2lf%s" \
GPRINT:h:MAX:"Maximum:%8.2lf%sn" \
LINE1:a#FF0000FF:"1. Target Again Traffic In" \
GPRINT:a:LAST:"Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:cdefca#000000FF:"AllDsNoDups" \
GPRINT:cdefca:LAST:" Current:%8.2lf%s" \
GPRINT:cdefca:AVERAGE:"Average:%8.2lf%s" \
GPRINT:cdefca:MAX:"Maximum:%8.2lf%sn"
rrdtool create disk.rrd --start 1735689600 --step 300 \
DS:used:GAUGE:600:0:U DS:free:GAUGE:600:0:U RRA:AVERAGE:0.5:1:24
rrdtool update disk.rrd \
1735689900:40:60 1735690200:44:56 1735690500:50:50 \
1735690800:48:52 1735691100:55:45 1735691400:60:40 \
1735691700:58:42 1735692000:65:35 1735692300:72:28 \
1735692600:68:32 1735692900:66:34 1735693200:70:30
```
The data sources are denoted by the letters `a` to `h`. `cdefca` represents the
important part. You surely notice that all data sources using consolidation
function `AVERAGE` are taken into account while `MAX` is skipped. Please pay
attention to the data source denoted by `a`. Even though the data source appears
twice, the cdef shows it only once. This is due to the duplicate suppression.
This is the list of graph items defined. Please note that Item numbers 17-20
are duplicates of Item numbers 1-4. Even if it usually does not make sense, for
this discussion it is very valuable. Item numbers 21-24 are related to a
`cdef=ALL_DATA_SOURCES_DUPS`
| Graph Item | Data Source | Graph Item Type | CF Type |
| :--------- | :--------------------------------------- | --------------: | ------: |
| Item # 1 | (traffic_in): 1. Target Traffic In | LINE1 | AVERAGE |
| Item # 2 | (traffic_in): Current: | GPRINT | LAST |
| Item # 3 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 4 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 5 | (traffic_in): 2. Target Traffic In | LINE1 | AVERAGE |
| Item # 6 | (traffic_in): Current: | GPRINT | LAST |
| Item # 7 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 8 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 9 | (traffic_out): 1. Target Traffic Out | LINE1 | AVERAGE |
| Item # 10 | (traffic_out): Current: | GPRINT | LAST |
| Item # 11 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 12 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 13 | (traffic_out): 2. Target Traffic Out | LINE1 | AVERAGE |
| Item # 14 | (traffic_out): Current: | GPRINT | LAST |
| Item # 15 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 16 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 17 | (traffic_in): 1. Target Again Traffic In | LINE1 | AVERAGE |
| Item # 18 | (traffic_in): Current: | GPRINT | LAST |
| Item # 19 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 20 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 21 | (No Task): AllDsDups | LINE1 | AVERAGE |
| Item # 22 | (No Task): Current: | GPRINT | LAST |
| Item # 23 | (No Task): Average: | GPRINT | AVERAGE |
| Item # 24 | (No Task): Maximum:[HR] | GPRINT | MAX |
And this is the rrd graph statement:
Give each input a DEF name. The CDEF below computes
`100 × used / (used + free)` at each step. The two VDEFs take the last and
largest values. A literal colon in GPRINT legend text is escaped as `\:`.
```sh
/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Traffic AllDsDups" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:AVERAGE \
DEF:b="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:MAX \
DEF:c="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:AVERAGE \
DEF:d="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:MAX \
DEF:e="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:AVERAGE \
DEF:f="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:MAX \
DEF:g="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:AVERAGE \
DEF:h="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:MAX \
CDEF:cdefca=TIME,1202925583,GT,a,a,UN,0,a,IF,IF,TIME,1202925583,GT,c,c,UN,0,c,IF,IF,TIME,1202925583,GT,e,e,UN,0,e,IF,IF,TIME,1202925583,GT,g,g,UN,0,g,IF,IF,TIME,1202925583,GT,a,a,UN,0,a,IF,IF,+,+,+,+ \
LINE1:a#FFFF00FF:"1. Target Traffic In" \
GPRINT:a:LAST:" Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:c#FFD660FF:"2. Target Traffic In" \
GPRINT:c:LAST:" Current:%8.2lf%s" \
GPRINT:c:AVERAGE:"Average:%8.2lf%s" \
GPRINT:d:MAX:"Maximum:%8.2lf%sn" \
LINE1:e#CAF100FF:"1. Target Traffic Out" \
GPRINT:e:LAST:" Current:%8.2lf%s" \
GPRINT:e:AVERAGE:"Average:%8.2lf%s" \
GPRINT:f:MAX:"Maximum:%8.2lf%sn" \
LINE1:g#CCBB00FF:"2. Target Traffic Out" \
GPRINT:g:LAST:" Current:%8.2lf%s" \
GPRINT:g:AVERAGE:"Average:%8.2lf%s" \
GPRINT:h:MAX:"Maximum:%8.2lf%sn" \
LINE1:a#FF0000FF:"1. Target Again Traffic In" \
GPRINT:a:LAST:"Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:cdefca#000000FF:"AllDsDups" \
GPRINT:cdefca:LAST:" Current:%8.2lf%s" \
GPRINT:cdefca:AVERAGE:"Average:%8.2lf%s" \
GPRINT:cdefca:MAX:"Maximum:%8.2lf%sn"
TZ=UTC LC_ALL=C rrdtool graph disk-use.png \
--start 1735689600 --end 1735693200 --step 300 \
--width 540 --height 160 --title 'Disk use' --vertical-label 'Percent used' \
--lower-limit 0 --upper-limit 100 --rigid \
DEF:used=disk.rrd:used:AVERAGE DEF:free=disk.rrd:free:AVERAGE \
'CDEF:pct=used,used,free,+,/,100,*' \
VDEF:lastpct=pct,LAST VDEF:peakpct=pct,MAXIMUM \
'AREA:pct#99CBBE:Used' 'LINE2:pct#126653' \
'GPRINT:lastpct:Last\: %.0lf%%' 'GPRINT:peakpct:Peak\: %.0lf%%'
```
Again, the data sources are denoted by the letters `a` to `h` and `cdefca`
represents the important part. Please pay attention to the data source denoted
by `a` appearing twice in this cdef. This is because it appears twice (Item
numbers 17-20) in the graph item list and duplicate suppression is not in
effect.
![Disk use ending at 70% after a 72% peak](images/rrd-disk-use-example.png)
Everything is very much like the above; again Item numbers 17-20 are duplicates
of Item numbers 1-4. Item numbers 21-24 are related to a
`cdef=SIMILAR_DATA_SOURCES_NODUPS` and are associated with the data source
`traffic_in` of the `1`. target (it does not matter which target is chosen, as
long as you only choose a `traffic_in` data source).
The legend should read **Last: 70%** and **Peak: 72%**. In Cacti, open the
graph in **Console > Management > Graphs** and enable graph debug mode to
inspect the DEFs, calculation and legend arguments for your own graph.
| Graph Item | Data Source | Graph Item Type | CF Type |
| :--------- | :--------------------------------------- | --------------: | ------: |
| Item # 1 | (traffic_in): 1. Target Traffic In | LINE1 | AVERAGE |
| Item # 2 | (traffic_in): Current: | GPRINT | LAST |
| Item # 3 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 4 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 5 | (traffic_in): 2. Target Traffic In | LINE1 | AVERAGE |
| Item # 6 | (traffic_in): Current: | GPRINT | LAST |
| Item # 7 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 8 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 9 | (traffic_out): 1. Target Traffic Out | LINE1 | AVERAGE |
| Item # 10 | (traffic_out): Current: | GPRINT | LAST |
| Item # 11 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 12 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 13 | (traffic_out): 2. Target Traffic Out | LINE1 | AVERAGE |
| Item # 14 | (traffic_out): Current: | GPRINT | LAST |
| Item # 15 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 16 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 17 | (traffic_in): 1. Target Again Traffic In | LINE1 | AVERAGE |
| Item # 18 | (traffic_in): Current: | GPRINT | LAST |
| Item # 19 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 20 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 21 | (traffic_in): SimilarDsNoDups | LINE1 | AVERAGE |
| Item # 22 | (traffic_in): Current: | GPRINT | LAST |
| Item # 23 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 24 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
## Shade days, nights and weekends
And this is the rrd graph statement:
To mark a time window behind a series, put a translucent AREA before the
measurement in the graph item order. Use a CDEF that returns infinity inside
the window and an unknown value outside it. `LTIME` uses the local time of
the RRDtool process. Include a reference to the current series so RRDtool
can determine the time step.
```sh
/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Traffic SimilarDsNoDups" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:AVERAGE \
DEF:b="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:MAX \
DEF:c="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:AVERAGE \
DEF:d="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:MAX \
DEF:e="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:AVERAGE \
DEF:f="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:MAX \
DEF:g="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:AVERAGE \
DEF:h="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:MAX \
CDEF:cdefca=TIME,1202924474,GT,a,a,UN,0,a,IF,IF,TIME,1202924474,GT,c,c,UN,0,c,IF,IF,+ \
CDEF:cdefcd=TIME,1202924474,GT,b,b,UN,0,b,IF,IF,TIME,1202924474,GT,d,d,UN,0,d,IF,IF,+ \
LINE1:a#FFFF00FF:"1. Target Traffic In" \
GPRINT:a:LAST:" Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:c#FFD660FF:"2. Target Traffic In" \
GPRINT:c:LAST:" Current:%8.2lf%s" \
GPRINT:c:AVERAGE:"Average:%8.2lf%s" \
GPRINT:d:MAX:"Maximum:%8.2lf%sn" \
LINE1:e#CAF100FF:"1. Target Traffic Out" \
GPRINT:e:LAST:" \
Current:%8.2lf%s" \
GPRINT:e:AVERAGE:"Average:%8.2lf%s" \
GPRINT:f:MAX:"Maximum:%8.2lf%sn" \
LINE1:g#CCBB00FF:"2. Target Traffic Out" \
GPRINT:g:LAST:" Current:%8.2lf%s" \
GPRINT:g:AVERAGE:"Average:%8.2lf%s" \
GPRINT:h:MAX:"Maximum:%8.2lf%sn" \
LINE1:a#FF0000FF:"1. Target Again Traffic In" \
GPRINT:a:LAST:"Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:cdefca#000000FF:"SimilarDsNoDups" \
GPRINT:cdefca:LAST:" Current:%8.2lf%s" \
GPRINT:cdefca:AVERAGE:"Average:%8.2lf%s" \
GPRINT:cdefcd:MAX:"Maximum:%8.2lf%sn"
```
| Window | Cacti CDEF expression |
| --- | --- |
| Day, 08:00 up to 18:00 | `LTIME,86400,%,28800,GE,LTIME,86400,%,64800,LT,*,INF,CURRENT_DATA_SOURCE,UNKN,*,IF` |
| Night, 18:00 up to 08:00 | `LTIME,86400,%,28800,LT,LTIME,86400,%,64800,GE,+,INF,CURRENT_DATA_SOURCE,UNKN,*,IF` |
| Weekend, Saturday and Sunday | `LTIME,604800,%,172800,GE,LTIME,604800,%,345600,LT,*,INF,CURRENT_DATA_SOURCE,UNKN,*,IF` |
`cdefca` calculates the `SUM` of `all traffic_in` data sources, but pays
attention only to consolidation function `AVERAGE`. Duplicate suppression makes
sure that the second occurrence of the `1`. target is not taken into account.
So it's only summing data source `a` and `c`. `cdefca` is used for the `LINE1`
graph item with exact match for consolidation function `AVERAGE` as well as for
the best matched consolidation functions `LAST` and `MIN`.
`cdefcd` calculates the `SUM` of all `traffic_in` data sources, but pays
attention only to consolidation function `MAX`. Again, duplicate suppression is
in effect. So it's only summing data source `b` and `d`. `cdefcd` is used for
the graph item with exact match for consolidation function `MAX` only. This is
because my rra settings only define `AVERAGE` and `MAX`, where `LAST` and `MIN`
are omitted. This may differ for installations defining `LAST` and `MIN` as
well.
Again, please note that Item numbers 17-20 are duplicates of Item numbers 1-4.
Item numbers 21-24 are related to a `cdef=SIMILAR_DATA_SOURCES_DUPS` and are
associated with the data source `traffic_in` of the `1` target (it does not
matter which target is chosen, as long as you only choose a `traffic_in` data
source).
| Graph Item | Data Source | Graph Item Type | CF Type |
| :--------- | :--------------------------------------- | --------------: | ------: |
| Item # 1 | (traffic_in): 1. Target Traffic In | LINE1 | AVERAGE |
| Item # 2 | (traffic_in): Current: | GPRINT | LAST |
| Item # 3 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 4 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 5 | (traffic_in): 2. Target Traffic In | LINE1 | AVERAGE |
| Item # 6 | (traffic_in): Current: | GPRINT | LAST |
| Item # 7 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 8 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 9 | (traffic_out): 1. Target Traffic Out | LINE1 | AVERAGE |
| Item # 10 | (traffic_out): Current: | GPRINT | LAST |
| Item # 11 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 12 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 13 | (traffic_out): 2. Target Traffic Out | LINE1 | AVERAGE |
| Item # 14 | (traffic_out): Current: | GPRINT | LAST |
| Item # 15 | (traffic_out): Average: | GPRINT | AVERAGE |
| Item # 16 | (traffic_out): Maximum:[HR] | GPRINT | MAX |
| Item # 17 | (traffic_in): 1. Target Again Traffic In | LINE1 | AVERAGE |
| Item # 18 | (traffic_in): Current: | GPRINT | LAST |
| Item # 19 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 20 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
| Item # 21 | (traffic_in): SimilarDsDups | LINE1 | AVERAGE |
| Item # 22 | (traffic_in): Current: | GPRINT | LAST |
| Item # 23 | (traffic_in): Average: | GPRINT | AVERAGE |
| Item # 24 | (traffic_in): Maximum:[HR] | GPRINT | MAX |
And this is the rrd graph statement:
```sh
/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Traffic SimilarDsDups" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:AVERAGE \
DEF:b="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_in:MAX \
DEF:c="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:AVERAGE \
DEF:d="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_in:MAX \
DEF:e="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:AVERAGE \
DEF:f="/var/www/html/cacti/rra/target1_traffic_in_235.rrd":traffic_out:MAX \
DEF:g="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:AVERAGE \
DEF:h="/var/www/html/cacti/rra/target2_traffic_in_8.rrd":traffic_out:MAX \
CDEF:cdefca=TIME,1202925634,GT,a,a,UN,0,a,IF,IF,TIME,1202925634,GT,c,c,UN,0,c,IF,IF,TIME,1202925634,GT,a,a,UN,0,a,IF,IF,+,+ \
CDEF:cdefcd=TIME,1202925634,GT,b,b,UN,0,b,IF,IF,TIME,1202925634,GT,d,d,UN,0,d,IF,IF,TIME,1202925634,GT,b,b,UN,0,b,IF,IF,+,+ \
LINE1:a#FFFF00FF:"1. Target Traffic In" \
GPRINT:a:LAST:" Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:c#FFD660FF:"2. Target Traffic In" \
GPRINT:c:LAST:" Current:%8.2lf%s" \
GPRINT:c:AVERAGE:"Average:%8.2lf%s" \
GPRINT:d:MAX:"Maximum:%8.2lf%sn" \
LINE1:e#CAF100FF:"1. Target Traffic Out" \
GPRINT:e:LAST:" Current:%8.2lf%s" \
GPRINT:e:AVERAGE:"Average:%8.2lf%s" \
GPRINT:f:MAX:"Maximum:%8.2lf%sn" \
LINE1:g#CCBB00FF:"2. Target Traffic Out" \
GPRINT:g:LAST:" Current:%8.2lf%s" \
GPRINT:g:AVERAGE:"Average:%8.2lf%s" \
GPRINT:h:MAX:"Maximum:%8.2lf%sn" \
LINE1:a#FF0000FF:"1. Target Again Traffic In" \
GPRINT:a:LAST:"Current:%8.2lf%s" \
GPRINT:a:AVERAGE:"Average:%8.2lf%s" \
GPRINT:b:MAX:"Maximum:%8.2lf%sn" \
LINE1:cdefca#000000FF:"SimilarDsDups" \
GPRINT:cdefca:LAST:Current:%8.2lf%s" \
GPRINT:cdefca:AVERAGE:"Average:%8.2lf%s" \
GPRINT:cdefcd:MAX:"Maximum:%8.2lf%sn"
```
`cdefca` and `cdefcd` represent the important part. You surely notice that all
data sources using consolidation function AVERAGE are taken into account for
calculation `cdefca`, while `MAX` is calculated with `cdefcd`. Please pay
attention to the data source denoted by `a` and `b`, respectively, appearing
twice in those CDEFs as expected.
### More CDEF Examples
This example is based on the standard data template
`ucd/net - Hard Drive Space`. Cacti ships an associated graph template named
`ucd/net - Available Disk Space`. Often, users complain about the fact that
this template prints free and used space as absolute figures only. But instead
of knowing that your data partition has about 10GB used space, you may be
interested in the percentage used. So let's create a simple example to show the
power of the recently introduced special data sources.
To make it work, we need two new CDEFs. The first one may come in useful for a
bunch of different graph templates. It's named `Make Current Data Source 0`. On
a first glance, you may wonder why this CDEF is needed. It is used for those
data sources that will be used for calculations but shall not show up
themselves. Here's the definition
`cdef=CURRENT_DATA_SOURCE,0,*`
Now, the other one, named `Current DS as Percentage of all DS`
`cdef=CURRENT_DATA_SOURCE,ALL_DATA_SOURCES_NODUPS,/,100,*`
Here's a short discussion. The first three elements read: Take the current data
source and divide it by `All Data Sources (Do not Include Duplicates)`. To
form a percentage, you will have to multiply by 100. This is done by adding the
elements four and five.
Now, let's build up the new graph
| Graph Item | Data Source | Graph Item Type | CF Type | Item Color |
| :--------- | :----------------- | --------------: | ------: | :--------- |
| Item # 1 | (hdd_used): | LINE1 | AVERAGE | |
| Item # 2 | (hdd_free): | LINE1 | AVERAGE | |
| Item # 3 | (hdd_used): % Used | AREA | AVERAGE | FF0000 |
Item numbers 1 and 2 in most cases will exceed the maximum percentage of 100 by
magnitudes. So they are associated with the CDEF named
`Make Current Data Source 0` to make them zero. This adds the data sources to
the graph but avoids them showing up. The pseudo-color of `None` is associated
to both of them.
Item number 3 is associated to the data source `hdd_used` as we want to print
the `% Used` of the partition. The CDEF is `Current DS as Percentage of all DS`,
the color is set to `red (FF0000)`.
And this is the rrd graph statement:
```sh
/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="gandalf - Disk Space - / %used" \
--rigid \
--base=1024 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="Percent" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/var/www/html/cacti/rra/target1_hdd_free_236.rrd":hdd_used:AVERAGE \
DEF:b="/var/www/html/cacti/rra/target1_hdd_free_236.rrd":hdd_free:AVERAGE \
CDEF:cdefa=a,0,* \
CDEF:cdefb=b,0,* \
CDEF:cdefc=a,TIME,1203272123,GT,a,a,UN,0,a,IF,IF,TIME,1203272123,GT,b,b,UN,0,b,IF,IF,+,/,100,* \
LINE1:cdefa:"" \
LINE1:cdefb:"" \
AREA:cdefc#FF0000FF:"% Used"
```
`cdefa` and `cdefb` are used to make the corresponding graph items zero. `cdefc`
performs the percentage calculation.
You may of course add `GPRINT` legends as usual. If you do this for the "% Used"
entry only, you will get surprising results if your RRDfile holds either
`MAXIMUM`, `LAST` and/or `MINIMUM` consolidation function(s). This is left as an
exercise to you :)
This set of CDEFs is used to colorize the background of a graph with different
colors for day, night and weekends. The CDEFs are created as usual; we will show
the CDEF definition only. Examples are taken from RRDtool-users mailing list
courtesy Erik de Mare. Here are the definitions
#### Background for Daytime
`cdef=LTIME,86400,%,28800,GT,LTIME,86400,%,64800,LT,INF,UNKN,CURRENT_DATA_SOURCE,*,IF,UNKN,CURRENT_DATA_SOURCE,*,IF`
#### Background for Nighttime
`cdef=LTIME,86400,%,28800,LT,INF,LTIME,86400,%,64800,GT,INF,UNKN,CURRENT_DATA_SOURCE,*,IF,IF`
#### Background for Weekend
`cdef=LTIME,604800,%,172800,GT,LTIME,604800,%,345600,LT,INF,UNKN,CURRENT_DATA_SOURCE,*,IF,UNKN,CURRENT_DATA_SOURCE,*,IF`
The value of `86400` represents the number of seconds of a day, whereas `28800`
represents `8:00`, defined as the start of the day. The end of the day, `64800`,
is assumed at `18:00`. Please replace those values if required. For weekends,
the same logic applies.
Now, let's apply those new CDEFs to a Graph Template. For this example, I've
chosen the `Unix - Processes` that applies to `localhost` only. In turn, please
create three new graph items, associate the processes data source, make them
AREAs, select a color and opacity. Choose the `daytime`, `nighttime` and
`weekend` CDEF in this sequence. As a last step, move those three new graph
items to the top. I've chosen an opacity of `20%` for Item numbers 1 to 3.
| Graph Item | Data Source | Graph Item Type | CF Type | Item Color |
| :--------- | :------------------------ | --------------: | ------: | :--------- |
| Item # 1 | (proc): | AREA | AVERAGE | FFFF00 |
| Item # 2 | (proc): | AREA | AVERAGE | 0000FF |
| Item # 3 | (proc): | AREA | AVERAGE | 2E3127 |
| Item # 4 | (proc): Running Processes | AREA | AVERAGE | F51D30 |
| Item # 5 | (proc): Current: | GPRINT | LAST | |
| Item # 6 | (proc): Average: | GPRINT | AVERAGE | |
| Item # 7 | (proc): Maximum: | GPRINT | MAX | |
The weekend offsets count from Thursday, the weekday of the Unix epoch.
Check a known Saturday in the graph's time zone when adapting this expression.
For the full operator list, see the
[RRDtool RPN](https://oss.oetiker.ch/rrdtool/doc/rrdgraph_rpn.en.html).
---
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB