Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
projects:telegraph [2018/11/11 20:21]
darron
projects:telegraph [2020/09/03 09:12] (current)
darron [User defined function]
Line 1: Line 1:
 ==== Telegraph ==== ==== Telegraph ====
 <wrap right> <wrap right>
 +{{:projects:light.jpg?200}} \\ \\
 +{{:projects:bme280.jpg?200}} \\ \\
 {{:projects:telegraph.png?200}} {{:projects:telegraph.png?200}}
 </wrap> </wrap>
  
-Telegraph is a multi-purpose tool which provides sensor probes, data gathering, web graphing and reporting. It is designed specfically for Raspberry Pi and uses cheap and easily obtained sensors.+Telegraph is a multi-purpose tool which provides sensor processing, data gathering, web graphing and status reporting. It is designed specfically for the Raspberry Pi and uses cheap and easily obtained sensor devices. An example device is the BME280 which can provide readings of ambient temperature, barometric pressure and relative humidity. BME280 boards can cost as little as £2.50.
  
-For sensors, Telegraph provides a number of external Simple Network Management Protocol (SNMP) daemon processes which gather data from various devices on a Raspberry or Banana Pi. The values returned are used to populate a round robin (RRD) or SQL database either with Telegraph or a tool of your own choice.+Telegraph sensor processes are Simple Network Management Protocol (SNMP) daemon extensions which read data from various devices on a Raspberry or similar personal computer. The values returned can be used to populate a round robin (RRD) or SQL database either with Telegraph or a tool of your own choice.
  
-Telegraph can also use ICMP to measure network latency when gathering data. For SNMP polling, Telegraph also supports network interface names which are mapped when querying.+Telegraph also supports networking and can use ICMP to measure network latency (PING) and with SNMP Telegraph can measure network utilisation. Network interface names are supported which are mapped to interface indexes when querying.
  
-Telegraph is run from CRON at regular 5 minute intervals for data gathering and the probes are configured within the net-snmp config. Although the probes are designed for the Raspberry Pi, the gathering host need only run Linux.+Telegraph is run from CRON at 5 minute intervals for data gathering and the sensor processes are configured within the SNMP (net-snmpconfig. Sensors generally depend on a computer like the Raspberry Pi for interfacingbut data gathering can run on any networked Linux host.
  
-PHP scripts demonstrate how you can access the RRD files and generate graphs on web page like the one shown above.+At each CRON iteration Telegraph can fork a process and supply it with gathered data. This allows for user defined function and custom processing.
  
-Telegraph can also report via e-mail, XMPP, or HTTP POST when either a target is offline or a retrieved value falls outside a specified range.+PHP scripts demonstrate how you can access the RRD files containing the data to generate graphs for the web like the one shown above. 
 + 
 +Telegraph can send reports via E-mail, XMPP, or with HTTP POST when either a target is offline or returns back online or if a retrieved value falls outside a specified range.
  
 === Install === === Install ===
Line 28: Line 32:
 Now view the instructions found in the README file in the telegraph directory which explains the installation process. Now view the instructions found in the README file in the telegraph directory which explains the installation process.
  
-=== Sensor probes ===+=== Sensor processing ===
  
-For the SNMP (simple network management protocol) daemon, Telegraph supplies the following sensor probe processes which may be used.+For the SNMP (simple network management protocol) daemon, Telegraph supplies the following sensor processes.
  
 ^ Process ^ Use ^ ^ Process ^ Use ^
Line 56: Line 60:
 | LEVEL      | Value scaled 0..1       | | | LEVEL      | Value scaled 0..1       | |
 | SCALE LEVEL| value scaled 0..N       | | | SCALE LEVEL| value scaled 0..N       | |
-| RESISTANCE | Resistance calculation  |VCC - R - LEVEL - R? - GND|+| RESISTANCE | Resistance calculation  |VCC - R - VINPUT - R? - GND|
 | VOLTAGE    | Voltage calculation     | | | VOLTAGE    | Voltage calculation     | |
 | LM19       | Temperature             | | | LM19       | Temperature             | |
Line 64: Line 68:
 | MCP9701    | Temperature             | | | MCP9701    | Temperature             | |
 | TMP36      | Temperature             | | | TMP36      | Temperature             | |
-| LDR        | Light  calculation      |VCC - R - LEVEL - LDR - GND| +| LDR        | Light  calculation      |VCC - R - VINPUT - LDR - GND| 
-| NTC        | Temperature calculation |VCC - R - LEVEL - NTC - GND|+| NTC        | Temperature calculation |VCC - R - VINPUT - NTC - GND|
  
-Each probe has a set of command line arguments specific to that probe type.+Each process has a set of command line arguments specific to that probe type.
  
 <code> <code>
Line 118: Line 122:
 B is known as the NTC B25 value and Ro is R25 on the datasheet for the device. R is the known resistance of the device at the current temperature and the B25/R25 values are representative of room temperature at 25'C. B is known as the NTC B25 value and Ro is R25 on the datasheet for the device. R is the known resistance of the device at the current temperature and the B25/R25 values are representative of room temperature at 25'C.
  
-=== SNMP ===+=== Simple Network Management Protocol ===
  
-The SNMP configuration uses the net-snmp extend feature to configure SNMPD to return values when probed. The extend feature +The SNMP server configuration uses the net-snmp extend feature which allows process to return a text string to the SNMP client. For RRD and Telegraph, this value is text string representing a numerical value, else U which means UKNOWN.
-allows an arbitrary process to report a text string which is returned to the client. For RRD and Telegraph, this value is +
-text string representing a numerical value, else U which means UKNOWN.+
  
 /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf
 <code> <code>
-rocommunity public X.X.X.X/24+rocommunity public 192.168.0.0/24
 extend cpu /usr/local/bin/soc /sys/class/thermal/thermal_zone0/temp extend cpu /usr/local/bin/soc /sys/class/thermal/thermal_zone0/temp
 </code> </code>
  
-In this simple example, a net-snmp extend is set to return the CPU temperature when queried.+In this simple example, a net-snmp extend is set to return the CPU temperature when queried. The first line is access control with rocommunity describing a read-only group and public being that groups authentication. The network range limits any queries for this group to that range.
  
-After changing the snmp config it must be restart for the new setting to take efect.+Any number of extend entries can be made with each having a unique name and purpose.
  
 +Whenever a change to the SNMP server configuration is made the server must be restarted for any new settings to take effect.
 <code> <code>
 /etc/init.d/snmpd restart /etc/init.d/snmpd restart
 </code> </code>
 +
 === Data gathering === === Data gathering ===
  
-This configuration file sets up a query for the above cpu temperature in snmpd.conf.+At periodic intervals Telegraph is run from CRON to gather data. The data can represent gauges which are ranges of values, like temperature, or counters which are used to measure packet throughput on network interfaces. 
 + 
 +The type of data is configured as a gauge by default, but this can be overriden to any type supported by RRDTOOL when using an RRD. For SQL, this is user defined, and not documented here, please refer to the meter demo for assistance. 
 + 
 +This configuration file sets up a query for cpu temperature as configured in snmpd.conf in the section above.
  
 /etc/telegraph/cpu.xml /etc/telegraph/cpu.xml
Line 147: Line 155:
  <graph label="C" />  <graph label="C" />
  <database type="rrd" filename="cpu.rrd" />  <database type="rrd" filename="cpu.rrd" />
- <query source="0" name="cpu" host="X.X.X.X" community="public" extend="cpu" />+ <query source="0" name="RPi" host="192.168.0.100" community="public" extend="cpu" />
 </telegraph> </telegraph>
 </code> </code>
Line 154: Line 162:
 the head of a graph and with reporting it will be the subject of the report. the head of a graph and with reporting it will be the subject of the report.
  
-The rrd file is where data is stored, by default this will be in /var/lib/telegraph+The RRD file is where data is stored, by default this will be in /var/lib/telegraph/
 but a path may be specified if required. but a path may be specified if required.
  
Line 160: Line 168:
 each new query. each new query.
  
-Only similar data types can exist in one configuration file, for example, only+Only the same data types can exist in any one configuration file, for example, only
 temperature or only network activity. Data types cannot be mixed and demand temperature or only network activity. Data types cannot be mixed and demand
-separate configurations and databases.+separate configuration files and RRD files.
  
 If an RRD file exists and a new query is added, it will not work and a new column If an RRD file exists and a new query is added, it will not work and a new column
Line 169: Line 177:
 Telegraph supplies a command line tool 'rrdadd' which will add 1 or more blank columns Telegraph supplies a command line tool 'rrdadd' which will add 1 or more blank columns
 to allow new sources to be added easily to an already existing RRD file. to allow new sources to be added easily to an already existing RRD file.
- 
- 
- 
- 
  
 === CRON === === CRON ===
  
-CRON  should run Telegraph every 5 minutes to gather data.+CRON is a daemon in Unix which invokes processes at specific times and intervals. 
 + 
 +CRON should run Telegraph every 5 minutes to gather data like this.
 <code> <code>
 */5 * * * * /usr/local/bin/telegraph -d 0 cpu.xml */5 * * * * /usr/local/bin/telegraph -d 0 cpu.xml
 </code> </code>
  
-This cron job will fetch values and store them in the database as configured by cpu.xml+CRON configuration is in TABLES, or CRONTABS, and is edited like this for Telegraph. It should be noted that Telegraph only uses root to set up ICMP and runs as an unprivileged user otherwise. 
 +<code> 
 +sudo crontab -e 
 +</code> 
 + 
 +This CRON job will fetch values and store them in the database as configured by cpu.xml
  
-The -d option is a delay value, it can be used to delay the process from cron+The -d option is a delay value, it can be used to delay the process from CRON
 when multiple telegraph processes are executed in parallel to stagger their when multiple telegraph processes are executed in parallel to stagger their
 processing and potential load on the system or target systems. processing and potential load on the system or target systems.
  
 <code> <code>
-*/5 * * * * /usr/local/bin/telegraph -d 0  cpu.xml+*/5 * * * * /usr/local/bin/telegraph cpu.xml
 */5 * * * * /usr/local/bin/telegraph -d 30 network.xml */5 * * * * /usr/local/bin/telegraph -d 30 network.xml
 </code> </code>
-=== World wide web === 
  
-Example configuration exists in the demo directory of the project which is used to demonstrate its operation +In these CRON entries every 5 minutes a Telegraph process gathers cpu data whilst another waits 30 seconds before gathering network statistics. 
-with PHP scripts that are installed in /var/www/telegraph+ 
 +=== User defined function === 
 + 
 +A user defined function may be forked every time Telegraph fetches new data. Forking allows a new process to be created and run in parallel by the process creating the fork. 
 + 
 +The user option in the configuration file informs telegraph to fork the named process. 
 + 
 +<code> 
 +<user fork="/usr/local/bin/myprocess" /> 
 +</code> 
 + 
 +With this line, the executable /usr/local/bin/myprocess is forked after Telegraph has finished gathering data. 
 + 
 +The command line arguments for the process are the process name, the telegraph title and then every result for each source in turn. This means that argv[2] would represent source 0 and argv[3] source 1, etc. 
 + 
 +=== Web graphing === 
 + 
 +Example configuration exists in the demo directory of the project which is used to demonstrate its operation with PHP scripts that are installed in /var/www/telegraph/
  
-The london demo can be seen [[http://london.c2n.uk/|here]]. This demo uses a proxy cache so the resultant +The london demo can be seen [[http://london.c2n.uk/|here]]. This demo uses a proxy cache so the resultant graphs may be slightly dated.
-graphs may be slightly dated.+
  
 The demo has been designed to work with apache2 but nginx will also work well. The demo has been designed to work with apache2 but nginx will also work well.
  
-=== Reporting ===+=== Status reporting ===
  
 Telegraph can report problems it finds when gathering data or when a returned value is out of range. Telegraph can report problems it finds when gathering data or when a returned value is out of range.
Line 213: Line 239:
 Three types of report delivery exist, e-mail, XMPP and HTTP POST. Three types of report delivery exist, e-mail, XMPP and HTTP POST.
  
-E-mail reporting requires sendmail or equivalent to be installed and XMPP demands a valid jabber/xmpp account to use as a sender. HTTP POST is set up to work with the RUN/STOP watchdog service at runstop.uk+E-mail reporting requires sendmail or equivalent to be installed and XMPP demands a valid jabber/xmpp account to use as a sender. HTTP POST is set up to work with the RUN/STOP watchdog service at [[https://runstop.uk|runstop.uk]]
  
 The Telegraph XML configuration file is updated for reporting. The Telegraph XML configuration file is updated for reporting.
  
-<Code+<code
-<monitor host="raspberry-pi" filename="cpu.db" init="monitor.sql" table="monitor" /> +<monitor filename="cpu.db" /> 
-<report type="email"    active="1" to="me@example.com" /> +<report type="email"    to="me@example.com" /> 
-<report type="xmpp"     active="1" to="me@xmpp.example.com" auth="xmpp" /> +<report type="xmpp"     to="me@xmpp.example.com" auth="xmpp" /> 
-<report type="watchdog" active="1" to="https://cgi.runstop.uk/watchdog/" auth="watchdog" />+<report type="watchdog" to="https://cgi.runstop.uk/watchdog/" auth="watchdog" />
 </code> </code>
  
Line 227: Line 253:
  
 The three report lines demonstrate sending reports. The first is e-mail, the second sends a jabber message to the destination using credentials found in The three report lines demonstrate sending reports. The first is e-mail, the second sends a jabber message to the destination using credentials found in
-the file /etc/telegraph/xmpp. This file is two lines, one being jabber identity and then second password. This file cannot be world readable. The last line post an HTTP message to the runstop.uk server using the credentials in NETRC format found in /etc/telegraph/watchdog. This file may not be world readable either.+the file /etc/telegraph/xmpp. This file is two lines, one being jabber identity and the second password. This file cannot be world readable. The last line post an HTTP message to the runstop.uk server using the credentials in NETRC format found in /etc/telegraph/watchdog. This file may not be world readable either.
  
 The content of a report contains 1 or more lines in CSV format. The content of a report contains 1 or more lines in CSV format.
Line 246: Line 272:
 </code> </code>
  
-This report show that a HIGH level or 20 has been reached by a temperature probe. +This report show that a HIGH level of 20 has been reached by a temperature probe.
  
 === Other tools === === Other tools ===
Line 269: Line 294:
  
 <code> <code>
-$ snmpget -v2c -c public X.X.X.1.3.6.1.4.1.8072.1.3.2.3.1.1.3.99.112.117+$ snmpget -v2c -c public 192.168.0.100 1.3.6.1.4.1.8072.1.3.2.3.1.1.3.99.112.117
 NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."cpu" = STRING: 34.166 NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."cpu" = STRING: 34.166
 </code> </code>
  
 How you use the MIB in other tools is of course, tool specific. How you use the MIB in other tools is of course, tool specific.
 +