rrdweb/graph.py
author Tero Marttila <terom@fixme.fi>
Sun, 31 Jan 2010 01:32:48 +0200
branchoo-graphs
changeset 19 58df27d54d2e
parent 17 a1608b66be45
permissions -rw-r--r--
start restructuring graph definitions as a class hierarchy...
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
import rrd
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
import time
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
"""
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
    RRDTool graph output
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
"""
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
def timestamp () :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
    return time.strftime("%Y/%m/%d %H:%M:%S %Z")
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    11
class BaseGraph (object) :
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
    """
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    13
        Construct the data layout and parameters for rendering the rrdtool.graph.
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    16
    # the unit label, used in both the Y scale and overview labels
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    17
    UNIT_LABEL = None
7
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    18
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    19
    def __init__ (self, rrd_path, title) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    20
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    21
            rrd_path        - path to the .rrd file
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    22
            title           - target name to use for the graph title
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    23
        """
7
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    24
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    25
        self.rrd_path = rrd_path
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    26
        self.title = title
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    28
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    29
    def data_sources (self, label_width=0) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    30
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    31
            Yield the data sources to define as a series of
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    32
                (id,    statements)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    33
            tuples.
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    34
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    35
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    36
        pass
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    37
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    38
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    39
    def overview_data (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    40
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    41
            Yield the data lines required to create a single summary data series called 'all'
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    42
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    43
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    44
        ids, statements = zip(self.data_sources())
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    45
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    46
        # draw lines
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    47
        yield statements
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    48
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    49
        # summarized data
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    50
        assert len(ids) == 2
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    51
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    52
        yield "CDEF:all=%s,+" % (ids.join(','))
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    53
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    54
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    55
    def detail_data (self, label_width=4) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    56
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    57
            Yield the data statements required to generate output for each line, as
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    58
                (identifier, statements)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    59
            tuples
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    60
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    61
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    62
        return data_sources(label_width=label_width) 
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    63
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    64
    def data (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    65
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    66
            Yield the data statements to be used for the rrdtool graph
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    67
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    68
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    69
        return []
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    70
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    71
    def options (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    72
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    73
            Yield the options to be used for the rrdtool graph as a dict
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    74
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    75
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    76
        return dict(
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    77
            # output
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    78
            imgformat           = "PNG",
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    79
            #        lazy                = True,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    80
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    81
            color               = [
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    82
                # disable border
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    83
                # border            = 0,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    84
                "SHADEA#ffffff00",
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    85
                "SHADEB#ffffff00",
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    86
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    87
                # keep background transparent
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    88
                "BACK#ffffff00",
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    89
                "SHADEB#ffffff00",
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    90
            ],
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    91
             
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    92
            # labels
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    93
            vertical_label      = self.UNIT_LABEL,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    94
            units               = "si",
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    95
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    96
            # use logarithmic scaling
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    97
            logarithmic         = True,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    98
            
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    99
            # smooth out lines
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   100
            slope_mode          = True,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   101
        )
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   102
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   103
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   104
    def generate (self, out_path) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   105
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   106
            Generate the output PNG file to the given path, using this object's params/data
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   107
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   108
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   109
        return rrd.graph(out_path, *self.data(), **self.options())
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   110
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   111
class OverviewGraph (BaseGraph) :
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
    """
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   113
        A small 600x50 px graph, suitable for showing as part of a long list of targets.
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   114
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   115
        May include some unlabed graph lines, and then a single summarized row of output.
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   116
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   117
    
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   118
    def options (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   119
        yield super(OverviewGraph, self).options()
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   120
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   121
        yield 'width',  600
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   122
        yield 'height', 50
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   123
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   124
    def data (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   125
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   126
            A single summary line
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   127
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   128
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   129
        # recurse
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   130
        yield super(OverviewGraph, self).data()
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   131
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   132
        # have a summarized data series?
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   133
        summarized = self.overview_data()
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   134
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   135
        if summarized :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   136
            # summarize -> all
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   137
            yield summarized
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   138
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   139
            # calculate min/max/avg of the summary value
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   140
            yield "VDEF:min=all,MINIMUM"
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   141
            yield "VDEF:max=all,MAXIMUM"
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   142
            yield "VDEF:avg=all,AVERAGE"
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   143
            
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   144
            # display one line
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   145
            yield "GPRINT:max:%%6.2lf %%S%s max" % self.UNIT_LABEL
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   146
            yield "GPRINT:avg:%%6.2lf %%S%s avg" % self.UNIT_LABEL
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   147
            yield "GPRINT:min:%%6.2lf %%S%s min\\l" % self.UNIT_LABEL
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   148
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   149
class DetailGraph (BaseGraph) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   150
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   151
        A large 600x200 px graph, suitable for showing for a specfic taget.
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   152
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   153
        Can include any number of graph lines, and then a row of summarized data for each.
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   154
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   155
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   156
    def options (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   157
        yield super(OverviewGraph, self).options()
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   158
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   159
        yield 'width',      600
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   160
        yield 'height',     200
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   161
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   162
    def data (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   163
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   164
            A complex breakdown into min/max/avg by line
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   165
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   166
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   167
        # column titles
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   168
        yield "COMMENT:%4s" % ""
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   169
        yield "COMMENT:%11s" % "Minimum"
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   170
        yield "COMMENT:%11s" % "Maximum"
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   171
        yield "COMMENT:%11s\\l" % "Average"
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   172
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   173
        # each row
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   174
        # label isn't wide enough?
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   175
        for id, data in self.detail_data(label_width=4) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   176
            # the defs
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   177
            yield data
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   178
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   179
            # summarize data
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   180
            yield 'VDEF:%s_min=%s,MINIMUM' % (id, id)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   181
            yield 'VDEF:%s_max=%s,MAXIMUM' % (id, id)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   182
            yield 'VDEF:%s_avg=%s,AVERAGE' % (id, id)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   183
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   184
            # the output
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   185
            'GPRINT:%s_min:%%6.2lf %%S%s' % (id, self.UNIT_LABEL)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   186
            'GPRINT:%s_max:%%6.2lf %%S%s' % (id, self.UNIT_LABEL)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   187
            'GPRINT:%s_avg:%%6.2lf %%S%s\\l' % (id, self.UNIT_LABEL)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   188
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   189
        # timestamp
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   190
        yield "COMMENT:Generated %s\\r" % timestamp().replace(':', '\\:')
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   191
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   192
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   193
STYLE_DEFS = {
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   194
    'overview'  : OverviewGraph,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   195
    'detail'    : DetailGraph,
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   196
}
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   197
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   198
class DailyGraph (BaseGraph) :
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   199
    """
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   200
        Provides a grid/interval/title suitable for a 24-hour graph
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   201
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   202
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   203
    def options (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   204
        yield super(DailyGraph, self).options()
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   205
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   206
        
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   207
        # labels
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   208
        yield 'x_grid',     "MINUTE:15:HOUR:1:HOUR:4:0:%H:%M"
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   209
    
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   210
        # title
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   211
        yield 'title',      "Daily %s" % (self.target_title, )
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   212
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   213
        # interval
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   214
        yield 'start',      "-24h"
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   215
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   216
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   217
class WeeklyGraph (BaseGraph) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   218
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   219
        Provides a grid/interval/title suitable for a 7-day graph
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   220
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   221
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   222
    def options (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   223
        yield super(DailyGraph, self).options()
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   224
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   225
        # labels
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   226
        #        x_grid              = "MINUTE:15:HOUR:1:HOUR:4:0:%H:%M",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   227
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   228
        # general info
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   229
        yield 'title',              "Weekly %s" % (self.target_title, )
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   230
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   231
        # interval
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   232
        yield 'start',              "-7d"
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   233
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   234
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   235
class YearlyGraph (BaseGraph) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   236
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   237
        Provides a grid/interval/title suitable for a 1-year graph
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   238
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   239
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   240
    def options (self) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   241
        yield super(DailyGraph, self).option()
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   242
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   243
        # labels
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   244
        #        x_grid              = "MINUTE:15:HOUR:1:HOUR:4:0:%H:%M",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   245
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   246
        # general info
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   247
        yield 'title'               "Yearly %s" % (self.target_title, )
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   248
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   249
        # interval
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   250
        yield 'start',              "-1y"
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   251
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   252
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   253
INTERVAL_DEFS = {
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   254
    'daily'     : DailyGraph,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   255
    'weekly'    : WeeklyGraph,
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   256
    'yearly'    : YearlyGraph,
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   257
}
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   258
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   259
class IfOctetGraph (BaseGraph) :
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   260
    """
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   261
        Defines the data sources for a single bidirectional octet counter
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   262
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   263
    
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   264
    # bits/s
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   265
    UNIT_LABEL = "bps"
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   266
    
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   267
    # the names for the in/out DS's
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   268
    RRD_DS_RX = None
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   269
    RRD_DS_TX = None
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   270
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   271
    def data_source (self, id, ds, color, label_width, label) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   272
        # data source, bytes/s
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   273
        yield "DEF:%s0=%s:%s:AVERAGE" % (id, self.rrd_path, ds)
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   274
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   275
        # convert to bits/s
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   276
        yield "CDEF:%s=%s0,8,*" % (id, id)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   277
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   278
        # draw line with label
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   279
        yield "LINE1:%s%s:%*s" % (id, color, label_width, label)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   280
       
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   281
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   282
    def data_sources (self, label_width=0) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   283
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   284
            Yield the data sources to define as a series of
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   285
                (id,    line-statements)
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   286
            tuples.
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   287
        """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   288
        
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   289
        # yield the table of values
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   290
        for      id,    ds,             color,      label       in (
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   291
                ('rx',  self.RRD_DS_RX, "#0000FF",  "In"    ),
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   292
                ('tx',  self.RRD_DS_TX, "#00CC00",  "Out"   ),
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   293
        ) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   294
            yield id, self.data_source(id, ds, color, label_width, label)
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   295
19
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   296
class MRTGGraph (IfOctetGraph) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   297
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   298
        Data sources for an MRTG .rrd
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   299
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   300
    
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   301
    # the DS names
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   302
    RRD_DS_RX = 'ds0'
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   303
    RRD_DS_TX = 'ds1'
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   304
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   305
class CollectdIfOctetGraph (IfOctetGraph) :
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   306
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   307
        Data sources for an if_octets .rrd from collectd
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   308
    """
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   309
    
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   310
    # the DS names
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   311
    RRD_DS_RX = 'rx'
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   312
    RRD_DS_TX = 'tx'
58df27d54d2e start restructuring graph definitions as a class hierarchy...
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   313
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   314
    
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   315
def _graph (style, interval, title, data_func, rrd_path, out_path) :
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   316
    style_opts, style_vars = STYLE_DEFS[style]()
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   317
    interval_opts = INTERVAL_DEFS[interval](title)
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   318
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   319
    opts = rrd.merge_opts(common_opts(), style_opts, interval_opts)
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   320
    data = data_func(rrd_path) + style_vars
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   321
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   322
    return rrd.graph(out_path, *data, **opts)
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   323
   
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   324
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   325
def mrtg (style, interval, title, rrd_path, out_path) :
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   326
    return _graph(style, interval, title, mrtg_data, rrd_path, out_path)
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   327
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   328
def collectd_ifoctets (style, interval, title, rrd_path, out_path) :
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   329
    return _graph(style, interval, title, collectd_data, rrd_path, out_path)
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   330