rrdweb/graph.py
author Tero Marttila <terom@fixme.fi>
Wed, 03 Nov 2010 00:51:06 +0200
changeset 28 89a4d9879171
parent 17 a1608b66be45
child 32 47e977c23ba2
permissions -rw-r--r--
Add 'Current' column to detail view
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
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
def common_opts () :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
        Common options for all views
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
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
    return dict(
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
        # output
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
        imgformat           = "PNG",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
        #        lazy                = True,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
        color               = [
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
            # disable border
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
            # border            = 0,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
            "SHADEA#ffffff00",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
            "SHADEB#ffffff00",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
            # keep background transparent
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
            "BACK#ffffff00",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
            "SHADEB#ffffff00",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
        ],
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
         
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
        # labels
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
        vertical_label      = "bits/s",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
        units               = "si",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
        # use logarithmic scaling
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
        logarithmic         = True,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
        
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
        # smooth out lines
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
        slope_mode          = True,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
    )
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
def overview_opts () :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
        Common options for the overview graph
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
    return dict(
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
        width               = 600,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
        height              = 50,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
    ), [
7
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    52
        "CDEF:all=in,out,+",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    53
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    54
        "VDEF:max=all,MAXIMUM",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    55
        "VDEF:avg=all,AVERAGE",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    56
        "VDEF:min=all,MINIMUM",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    57
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    58
        "LINE1:in#0000FF:In",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    59
        "LINE1:out#00CC00:Out",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    60
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    61
        "GPRINT:max:%6.2lf %Sbps max",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    62
        "GPRINT:avg:%6.2lf %Sbps avg",
804243b0bcb9 add sum max/avg/min to overview graphs
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
    63
        "GPRINT:min:%6.2lf %Sbps min\\l",
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
    ]
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
def detail_opts () :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
        Common options for the detail graph
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    71
    return dict(
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
        # dimensions
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    73
        width               = 600,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
        height              = 200,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
    ), [
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
        # values
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
        'VDEF:in_max=in,MAXIMUM',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
        'VDEF:in_avg=in,AVERAGE',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
        'VDEF:in_min=in,MINIMUM',
28
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    80
        'VDEF:in_cur=in,LAST',
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    81
        'VDEF:out_max=out,MAXIMUM',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
        'VDEF:out_avg=out,AVERAGE',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    83
        'VDEF:out_min=out,MINIMUM',
28
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    84
        'VDEF:out_cur=out,LAST',
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    85
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    86
        # legend/graph
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    87
        "COMMENT:%4s" % "",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    88
        "COMMENT:%11s" % "Maximum",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    89
        "COMMENT:%11s" % "Average",
28
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    90
        "COMMENT:%11s" % "Minimum",
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    91
        "COMMENT:%11s\\l" % "Current",
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
        "LINE1:in#0000FF:%4s" % "In",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
        'GPRINT:in_max:%6.2lf %Sbps',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
        'GPRINT:in_avg:%6.2lf %Sbps',
28
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    96
        'GPRINT:in_min:%6.2lf %Sbps',
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    97
        'GPRINT:in_cur:%6.2lf %Sbps\\l',
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
        "LINE1:out#00CC00:%4s" % "Out",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
        'GPRINT:out_max:%6.2lf %Sbps',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   101
        'GPRINT:out_avg:%6.2lf %Sbps',
28
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   102
        'GPRINT:out_min:%6.2lf %Sbps',
89a4d9879171 Add 'Current' column to detail view
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   103
        'GPRINT:out_cur:%6.2lf %Sbps\\l',
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   104
        
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   105
        # mark
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   106
        "COMMENT:Generated %s\\r" % timestamp().replace(':', '\\:'),
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   107
    ]
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   108
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   109
STYLE_DEFS = {
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
    'overview': overview_opts,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
    'detail':   detail_opts,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
}
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   113
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
def daily_opts (title) :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
        Common options for the 'daily' view
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   118
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   119
    return dict(
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   120
        # labels
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
        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
   122
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   123
        # general info
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   124
        title               = "Daily %s" % (title, ),
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   126
        # interval
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
        start               = "-24h",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
    )
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   129
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
def weekly_opts (title) :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   131
    return dict(
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   132
        # labels
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   133
        #        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
   134
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   135
        # general info
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
        title               = "Weekly %s" % (title, ),
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   137
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
        # interval
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   139
        start               = "-7d",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   140
    )
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   141
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   142
def yearly_opts (title) :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   143
    return dict(
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   144
        # labels
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   145
        #        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
   146
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   147
        # general info
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   148
        title               = "Yearly %s" % (title, ),
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   149
    
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   150
        # interval
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   151
        start               = "-1y",
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   152
    )
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   153
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
INTERVAL_DEFS = {
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   156
    'daily':    daily_opts,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   157
    'weekly':   weekly_opts,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   158
    'yearly':   yearly_opts,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
}
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   160
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   161
def mrtg_data (rrd_path) :
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   162
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   163
        Data sources for network in/out from an MRTG rrd
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   164
    """
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   165
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   166
    return [
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   167
        # data sources, bytes/s
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
        r'DEF:in0=%s:ds0:AVERAGE' % rrd_path,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   169
        r'DEF:out0=%s:ds1:AVERAGE' % rrd_path,
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
        # data, bits/s
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   172
        'CDEF:in=in0,8,*',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   173
        'CDEF:out=out0,8,*',
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   174
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   175
    ]        
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   177
def collectd_data (rrd_path) :
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   178
    """
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   179
        Data sources for if_octets from a collectd rrd
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   180
    """
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   181
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   182
    return [
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   183
        # data sources, bytes/s
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   184
        r'DEF:in0=%s:rx:AVERAGE' % rrd_path,
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   185
        r'DEF:out0=%s:tx:AVERAGE' % rrd_path,
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   186
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   187
        # data, bits/s
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   188
        'CDEF:in=in0,8,*',
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   189
        'CDEF:out=out0,8,*',
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   190
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   191
    ]        
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   192
    
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   193
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
   194
    style_opts, style_vars = STYLE_DEFS[style]()
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   195
    interval_opts = INTERVAL_DEFS[interval](title)
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
    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
   198
    data = data_func(rrd_path) + style_vars
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   199
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   200
    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
   201
   
5
e716718482c3 hack hack hack some HTML output
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   202
17
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   203
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
   204
    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
   205
a1608b66be45 add support for collectd_ifoctets in addition to mrtg
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   206
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
   207
    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
   208