- Publicity: Public Only All
rrd-procs.tcl
RRD-procs - nx based monitoring and graphing
This file defines the following Objects and Classes: ::rrd::Graph, ::rrd::TrendLine, ::rrd::DataSource, ::rrd::DataLine, ::rrd::DataElement, ::rrd::Plugin, ::rrd::DataArea, ::rrd::VolatileObject, ::rrd::plugin::dbstats::pool3-statements, ::rrd::plugin::dbstats::pool2-statements, ::rrd::plugin::dbstats::pool2-gethandles, ::rrd::plugin::dbstats::pool2-waittime, ::rrd::plugin::dbstats::pool1-statements, ::rrd::plugin::users::authenticated, ::rrd::plugin::dbstats::pool1-gethandles, ::rrd::plugin::dbstats::pool1-waittime, ::rrd::plugin::memsize::rss, ::rrd::plugin::dbstats::pool3-waittime, ::rrd::plugin::dbstats::pool3-gethandles, ::rrd::plugin::dbstats::pool1-sqltime, ::rrd::plugin::memsize::vsize, ::rrd::plugin::dbstats::pool3-sqltime, ::rrd::plugin::dbstats::pool2-sqltime, ::rrd::plugin::responsetime::responsetime, ::rrd::plugin::users::anonymous, ::rrd::plugin::responsetime, ::rrd::plugin::memsize, ::rrd::plugin::users, ::rrd::plugin::dbstats, ::rrd::plugin::users, ::rrd::plugin::responsetime, ::rrd::plugin::memsize, ::rrd::Plugin, ::rrd::plugin::memsize, ::rrd::TrendLine, ::rrd::DataSource, ::rrd::plugin::dbstats, ::rrd::Plugin, ::rrd::plugin::users, ::rrd::Plugin, ::rrd::DataSource
- Location:
- packages/rrd-tool/tcl/rrd-procs.tcl
- Created:
- 2015-11-01
- Author:
- Gustaf Neumann
- CVS Identification:
$Id: xowiki-procs.tcl,v 1.485.2.15 2015/10/22 08:28:42 gustafn Exp $
Procedures in this file
- Class ::rrd::DataArea (public)
- Class ::rrd::DataElement (public)
- Class ::rrd::DataLine (public)
- Class ::rrd::DataSource (public)
- Class ::rrd::Graph (public)
- Class ::rrd::Plugin (public)
- Class ::rrd::TrendLine (public)
- Class ::rrd::VolatileObject (public)
- Object ::rrd::plugin::dbstats (public)
- Object ::rrd::plugin::dbstats::pool1-gethandles (public)
- Object ::rrd::plugin::dbstats::pool1-sqltime (public)
- Object ::rrd::plugin::dbstats::pool1-statements (public)
- Object ::rrd::plugin::dbstats::pool1-waittime (public)
- Object ::rrd::plugin::dbstats::pool2-gethandles (public)
- Object ::rrd::plugin::dbstats::pool2-sqltime (public)
- Object ::rrd::plugin::dbstats::pool2-statements (public)
- Object ::rrd::plugin::dbstats::pool2-waittime (public)
- Object ::rrd::plugin::dbstats::pool3-gethandles (public)
- Object ::rrd::plugin::dbstats::pool3-sqltime (public)
- Object ::rrd::plugin::dbstats::pool3-statements (public)
- Object ::rrd::plugin::dbstats::pool3-waittime (public)
- Object ::rrd::plugin::memsize (public)
- Object ::rrd::plugin::memsize::rss (public)
- Object ::rrd::plugin::memsize::vsize (public)
- Object ::rrd::plugin::responsetime (public)
- Object ::rrd::plugin::responsetime::responsetime (public)
- Object ::rrd::plugin::users (public)
- Object ::rrd::plugin::users::anonymous (public)
- Object ::rrd::plugin::users::authenticated (public)
- rrd::DataArea instproc render (public)
- rrd::DataElement instproc render (public)
- rrd::DataLine instproc render (public)
- rrd::DataSource instproc deleteRRD (public)
- rrd::DataSource instproc lastupdate (public)
- rrd::DataSource instproc requireRRD (public)
- rrd::DataSource instproc update (public)
- rrd::Graph instproc imgName (public)
- rrd::Graph instproc render (public)
- rrd::Plugin instproc baseResolution (public)
- rrd::Plugin instproc datasource (public)
- rrd::Plugin instproc datasources (public)
- rrd::Plugin instproc updateDataSource (public)
- rrd::Plugin proc update (public)
- rrd::TrendLine instproc render (public)
- rrd::plugin::dbstats proc update (public)
- rrd::plugin::memsize proc update (public)
- rrd::plugin::responsetime proc update (public)
- rrd::plugin::users proc update (public)
Detailed information
Class ::rrd::VolatileObject (public)
::nx::Class ::rrd::VolatileObject
- Testcases:
- No testcase defined.
Object ::rrd::plugin::dbstats (public)
::rrd::Plugin ::rrd::plugin::dbstats
- pool1-statementsC
- pool3-gethandlesC
- pool3-statementsC
- pool1-waittimeC
- pool3-waittimeC
- pool1-sqltimeC
- pool2-gethandlesC
- pool2-sqltimeC
- pool2-statementsC
- pool3-sqltimeC
- ::rrd::plugin::dbstats update
- pool2-waittimeC
- pool1-gethandlesC
- ::rrd::plugin::dbstats updateDataSource /varName/ /value/
- ::rrd::plugin::dbstats datasources
- ::rrd::plugin::dbstats datasource /varName/
- ::rrd::plugin::dbstats baseResolution
- Testcases:
- No testcase defined.
Object ::rrd::plugin::dbstats::pool1-gethandles (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool1-gethandles
Object ::rrd::plugin::dbstats::pool1-sqltime (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool1-sqltime
Object ::rrd::plugin::dbstats::pool1-statements (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool1-statements
Object ::rrd::plugin::dbstats::pool1-waittime (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool1-waittime
Object ::rrd::plugin::dbstats::pool2-gethandles (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool2-gethandles
Object ::rrd::plugin::dbstats::pool2-sqltime (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool2-sqltime
Object ::rrd::plugin::dbstats::pool2-statements (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool2-statements
Object ::rrd::plugin::dbstats::pool2-waittime (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool2-waittime
Object ::rrd::plugin::dbstats::pool3-gethandles (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool3-gethandles
Object ::rrd::plugin::dbstats::pool3-sqltime (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool3-sqltime
Object ::rrd::plugin::dbstats::pool3-statements (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool3-statements
Object ::rrd::plugin::dbstats::pool3-waittime (public)
::rrd::DataSource ::rrd::plugin::dbstats::pool3-waittime
Object ::rrd::plugin::responsetime::responsetime (public)
::rrd::DataSource ::rrd::plugin::responsetime::responsetime
Object ::rrd::plugin::users (public)
::rrd::Plugin ::rrd::plugin::users
- Testcases:
- No testcase defined.
Object ::rrd::plugin::users::authenticated (public)
::rrd::DataSource ::rrd::plugin::users::authenticated
rrd::DataArea method render (public)
<instance of rrd::DataArea> render
- Testcases:
- No testcase defined.
rrd::DataElement method render (public)
<instance of rrd::DataElement> render
- Testcases:
- No testcase defined.
rrd::DataLine method render (public)
<instance of rrd::DataLine> render
- Testcases:
- No testcase defined.
rrd::DataSource method deleteRRD (public)
<instance of rrd::DataSource> deleteRRD
- Testcases:
- No testcase defined.
rrd::DataSource method lastupdate (public)
<instance of rrd::DataSource> lastupdate
- Testcases:
- No testcase defined.
rrd::DataSource method requireRRD (public)
<instance of rrd::DataSource> requireRRD
- Testcases:
- No testcase defined.
rrd::DataSource method update (public)
<instance of rrd::DataSource> update [ -timestamp timestamp ] \ value
- Switches:
- -timestamp (optional, defaults to
"N"
)- Parameters:
- value (required)
- Testcases:
- No testcase defined.
rrd::Plugin method baseResolution (public)
<instance of rrd::Plugin> baseResolution
- Testcases:
- No testcase defined.
rrd::Plugin method datasource (public)
<instance of rrd::Plugin> datasource varName
- Parameters:
- varName (required)
- Testcases:
- No testcase defined.
rrd::Plugin method datasources (public)
<instance of rrd::Plugin> datasources
- Testcases:
- No testcase defined.
rrd::Plugin method updateDataSource (public)
<instance of rrd::Plugin> updateDataSource varName value
- Parameters:
- varName (required)
- value (required)
- Testcases:
- No testcase defined.
rrd::Plugin object method update (public)
rrd::Plugin update plugins
- Parameters:
- plugins (required)
- Testcases:
- No testcase defined.
rrd::TrendLine method render (public)
<instance of rrd::TrendLine> render
- Testcases:
- No testcase defined.
rrd::plugin::dbstats proc update (public)
rrd::plugin::dbstats update
Get db-statistics from [ns_db stats]
- Testcases:
- No testcase defined.
rrd::plugin::memsize proc update (public)
rrd::plugin::memsize update
- Testcases:
- No testcase defined.
rrd::plugin::responsetime proc update (public)
rrd::plugin::responsetime update
- Testcases:
- No testcase defined.
Content File Source
::xo::library doc { RRD-procs - nx based monitoring and graphing @creation-date 2015-11-01 @author Gustaf Neumann @cvs-id $Id: xowiki-procs.tcl,v 1.485.2.15 2015/10/22 08:28:42 gustafn Exp $ } if {[catch { package require Rrd } errorMsg]} { ns_log warning "Can't load Tcl package Rrd: $errorMsg" namespace eval ::Rrd { proc ::Rrd::create {args} {ns_log warning "Would call Rrd::create $args"} proc ::Rrd::update {args} {ns_log warning "Would call Rrd::update $args"} proc ::Rrd::lastupdate {args} {ns_log warning "Would call Rrd::lastupdate $args"} } #return } namespace eval rrd { # # ::rrd::VolatileObject # # Graphical Object, we want auto-cleanup # nx::Class create ::rrd::VolatileObject { :method init {} { :destroy_on_cleanup } } # # rrd:Graph # nx::Class create ::rrd::Graph -superclass ::rrd::VolatileObject { :property filename :property name :property -incremental {elements:0..n ""} :property {period seconds} # time range properties :property start :property end :property step # labels :property title :property vertical-label # size :property {width:integer 400} :property {height:integer 175} :property only-graph:switch :property fill-size-mode:switch # limits :property upper-limit :property lower-limit :property rigid:switch :property alt-autoscale:switch :property alt-autoscale-min:switch :property alt-autoscale-max:switch :property no-gridfit:switch # x-axis :property x-grid :property x-grid-none:switch :property week-fmt # y-axis :property y-grid :property y-grid-none:switch :property left-axis-formatter :property left-axis-format :property alt-y-grid:switch :property logarithmic:switch :property units-exponent:integer :property units-length:integer # --units=si? :property right-axis :property right-axis-label :property right-axis-formatter :property right-axis-format # legend :property no-legend:switch :property force-rules-legend:switch :property legend-position :property legend-direction # misc :property lazy:switch :property daemon :property imginfo :property {color:0..n {FONT#666666 ARROW#CFD6F8}} ;# can be specified multiple times :property grid-dash :property border:integer :property dynamic-labels:switch :property zoom :property {font:0..n { "DEFAULT:0:DejaVuSans,DejaVu Sans,DejaVu LGC Sans,Bitstream Vera Sans" LEGEND:7:monospace TITLE:12 AXIS:8 UNIT:8 }} :property font-render-mode :property font-smoothing-threshold :property pango-markup:switch :property graph-render-mode :property slope-mode:switch :property {imgformat PNG} :property interlaced:switch :property tabwidth:integer :property {base:integer 1000} :property {watermark "nx-rrd 0.1"} :property use-nan-for-all-missing-data:swtich :method init {} { next if {![info exists name]} { set :name [namespace tail [self]] } if {![info exists filename]} { set :imgname ${:name}.[string tolower ${:imgformat}] set :filename $::acs::rootdir/www/${:imgname} } } :public method imgName {} { return ${:imgname} } :public method render {} { set defs [list ${:filename}] foreach v [[current class] info variables] { set varName [:info variable name $v] # # the following four varnames are NOT from rrd, so don't pass # these as is to rrd. # if {$varName in {elements filename name period}} { continue } # # These are configuration variables from rrd # if {[info exists :$varName]} { switch -glob -- [lindex [:info variable parameter $v] 0] { *:boolean { if {[set :$varName]} {lappend defs --$varName} } *:0..n { foreach e [set :$varName] { lappend defs --$varName $e } } default { lappend defs --$varName [set :$varName]} } } } switch ${:period} { day {set scale 34560} hours {set scale 1440} minutes {set scale 60} seconds - default {set scale 1} } foreach e ${:elements} { $e configure -scale $scale } lappend defs "COMMENT: \t\t Cur\tMin\t Avg\t Max\\l" foreach e ${:elements} { lappend defs {*}[$e render] } # get the lastupdate from the last element lassign [[$e cget -datasource] lastupdate] ds secs value regsub -all {:} [clock format [string trimright $secs :]] {\:} ts lappend defs "COMMENT:Last update\\: $ts\\r" #append ::_ "<p>GRAPH<br>[join $defs <br>\n]<br>\n" return $defs } } # # Graphical elements # nx::Class create ::rrd::Element -superclass ::rrd::VolatileObject { } # # ::rrd::DataElement # # Graphical elements with attached data # nx::Class create ::rrd::DataElement -superclass ::rrd::Element { :property name :property datasource:required :property {ds-name 42} :property {scale 1} :method init {} { next if {![info exists :name]} { set :name [${:datasource} cget -name] } } :public method render {} { set rrdFile [${:datasource} cget -rrdFile] regsub -all {[-]} ${:name} _ :name lappend defs \ DEF:${:name}avg=${rrdFile}:${:ds-name}:AVERAGE \ DEF:${:name}cur=${rrdFile}:${:ds-name}:LAST \ DEF:${:name}min=${rrdFile}:${:ds-name}:MIN \ DEF:${:name}max=${rrdFile}:${:ds-name}:MAX \ CDEF:${:name}avgscaled=${:name}avg,${:scale},* \ CDEF:${:name}curscaled=${:name}cur,${:scale},* \ CDEF:${:name}minscaled=${:name}min,${:scale},* \ CDEF:${:name}maxscaled=${:name}max,${:scale},* return $defs } :method gprintLegend {} { return [list \ GPRINT:${:name}curscaled:LAST:%6.2lf%s\t \ GPRINT:${:name}minscaled:MIN:%6.2lf%s\t \ GPRINT:${:name}avgscaled:AVERAGE:%6.2lf%s\t \ GPRINT:${:name}maxscaled:MAX:%6.2lf%s\\l ] } } # # ::rrd::DataLine # # Line with some data attached # nx::Class create ::rrd::DataLine -superclass ::rrd::DataElement { :property {width 1} :property color :property legend :public method render {} { set defs [next] if {[info exists :legend]} { set legend "[format %-20s ${:legend}]\t" } else { set legend "[format %-20s ${:name}]\t" } lappend defs \ LINE${:width}:${:name}avgscaled#${:color}:$legend \ {*}[:gprintLegend] return $defs } } # # ::rrd::TrendLine # # TrendLine, based on scaled avg data # nx::Class create ::rrd::TrendLine -superclass ::rrd::DataElement { :property {width 1} :property color :property {legend ""} :property {window 1800} :public method render {} { if {[info exists :legend]} { set legend "[format %-20s ${:legend}]\t" } else { set legend "[format %-20s ${:name}]\t" } lappend defs \ CDEF:${:name}trend=${:name}avgscaled,${:window},TREND \ LINE${:width}:${:name}trend#${:color} return $defs } } # # ::rrd::DataArea # # Area with some data attached # nx::Class create ::rrd::DataArea -superclass ::rrd::DataElement { :property color :property color2 :property legend :property {gradheight 50} :public method render {} { set defs [next] if {[info exists :legend]} { set legend "[format %-20s ${:legend}]\t" } else { set legend "[format %-20s ${:name}]\t" } set colors ${:color} if {[info exists :color2]} {append colors \#${:color2}} lappend defs \ AREA:${:name}avgscaled#${colors}:$legend:gradheight=${:gradheight} \ {*}[:gprintLegend] return $defs } } # # ::rrd::DataSource # nx::Class create ::rrd::DataSource { :property name :property baseResolution :property rrdFile :property {type DERIVE} :method createRRDfile {} { set durations [[:info parent] cget -durations] foreach duration ${durations} { set d [clock scan $duration -timezone :UTC -base 0] set multiple($duration) [expr {$d / ${:baseResolution}}] if {$multiple($duration) * ${:baseResolution} != $d} { error "duration '$duration' is not a multiple of the base resolution ${:baseResolution} secs" } } set RRA {} foreach {res duration} ${durations} { set m [expr {$multiple($duration)/$multiple($res)}] if {$m * $multiple($res) != $multiple($duration)} { error "duration '$duration' is not a multiple of the resolution $res" } #ns_log notice "$multiple($res) [expr {$multiple($duration)/$multiple($res)}]" lappend RRA \ "RRA:AVERAGE:0.5:$multiple($res):$m" \ "RRA:MIN:0.5:$multiple($res):$m" \ "RRA:MAX:0.5:$multiple($res):$m" } ns_log notice "try to create: Rrd::create ${:rrdFile} --step ${:baseResolution} DS:42:DERIVE:10m:0:U {*}$RRA" Rrd::create ${:rrdFile} --step ${:baseResolution} "DS:42:${:type}:10m:0:U" {*}$RRA } :public method update {{-timestamp N} value} { ns_log notice "Rrd::update ${:rrdFile} ${timestamp}:$value" Rrd::update ${:rrdFile} ${timestamp}:$value } :public method lastupdate {} { return [Rrd::lastupdate ${:rrdFile}] } :public method requireRRD {} { if {![file exists ${:rrdFile}]} { :createRRDfile } } :public method deleteRRD {} { if {[file exists ${:rrdFile}]} { file delete ${:rrdFile} } } :method init {} { next if {![info exists :name]} { set :name [namespace tail [self]] } set :rrdFile [[:info parent] cget -rrdPath]_${:name}-d.rrd append ::log "rrdFile of [self] is ${:rrdFile}<br>\n" :requireRRD } } # # ::rrd::Plugin # nx::Class create ::rrd::Plugin { :property vars :property name :property {rrdRoot /var/lib/munin/localdomain/localhost.localdomain} :property rrdPath :property {type DERIVE} :property {durations { "5 min" "2 days" "30 min" "9 days" "2 hours" "45 days" "1 day" "450 days" }} :public object method update {plugins} { foreach p $plugins { if {[info commands $p] eq ""} { ns_log warning "::rrd::Plugin: $p is not a command, ignore update" continue } $p update } } :method init {} { next if {![info exists :name]} { set :name [namespace tail [self]]} set :rrdPath ${:rrdRoot}_${:name} set :baseResolution [clock scan [lindex ${:durations} 0] -timezone :UTC -base 0] foreach varName ${:vars} { ::rrd::DataSource create [self]::$varName -baseResolution ${:baseResolution} -type ${:type} } } :public method baseResolution {} { return ${:baseResolution} } :public method datasource {varName} { if {[info commands [self]::$varName] ne ""} { return [self]::$varName } else { error "no data source $varName exists for plugin ${:name}" } } :public method datasources {} { return [:info children -type ::rrd::DataSource] } :public method updateDataSource {varName value} { [self]::$varName update $value } } } ::xo::library source_dependent # Local variables: # mode: tcl # tcl-indent-level: 2 # indent-tabs-mode: nil # End: