def SingleStat( title, id, targets, colorValue=False, gauge=Gauge(show=True), valueFontSize='80%', thresholds=None, valueName='avg', valueMaps=None, rangeMaps=None, mappingTypes=None, mappingType=None, postfix=None, sparkline=SparkLine(), prefixFontSize='50%', colors=[ (50, 172, 45, 0.97), (237, 129, 40, 0.89), (245, 54, 54, 0.9), ], span=None, format='none', transparent=None, ): def merge_target(target): return { **{ 'intervalFactor': 2, 'refId': 'A', 'step': 600, }, **target } targets = [merge_target(t) for t in targets] return core.SingleStat( title=title, id=id, colorValue=colorValue, dataSource='${DS_PROMETHEUS}', gauge=gauge, valueFontSize=valueFontSize, thresholds=thresholds, valueName=valueName, valueMaps=valueMaps, rangeMaps=rangeMaps, mappingTypes=mappingTypes, targets=targets, mappingType=mappingType, format=format, colors=colors, span=span, postfix=postfix, sparkline=sparkline, prefixFontSize=prefixFontSize, hideTimeOverride=None, transparent=transparent, )
def test_single_stat(): data_source = 'dummy data source' targets = ['dummy_prom_query'] title = 'dummy title' single_stat = G.SingleStat(data_source, targets, title) data = single_stat.to_json_data() assert data['targets'] == targets assert data['datasource'] == data_source assert data['title'] == title
def make(prefix, title): def target(expr, **kw): return G.Target(expr=expr.format(prefix), **kw) return G.Dashboard( title=title, rows=[ G.Row(panels=[ G.SingleStat( title='Pods up (web)', dataSource='prometheus', valueName='current', sparkline=G.SparkLine(show=True), targets=[ target( expr= 'count by(service) (up{{service="{}-isaacranks-web"}} == 1)' ) ]), G.SingleStat( title='Pods up (rebuild)', dataSource='prometheus', valueName='current', sparkline=G.SparkLine(show=True), targets=[ target( expr= 'count by(service) (up{{service="{}-isaacranks-rebuild"}} == 1)' ) ]), ]), G.Row(panels=[ G.Graph( title='HTTP RPS', dataSource='prometheus', targets=[ target( expr= 'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"1.."}}', legendFormat='1xx', refId='A'), target( expr= 'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"2.."}}', legendFormat='2xx', refId='B'), target( expr= 'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"3.."}}', legendFormat='3xx', refId='C'), target( expr= 'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"4.."}}', legendFormat='4xx', refId='D'), target( expr= 'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"5.."}}', legendFormat='5xx', refId='E'), ], aliasColors=ALIAS_COLORS, yAxes=[ G.YAxis(format=G.OPS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False) ], nullPointMode=G.NULL_AS_ZERO, stack=True, lineWidth=0, fill=10, tooltip=G.Tooltip(valueType=G.INDIVIDUAL)), G.Graph( title='HTTP latency', dataSource='prometheus', targets=[ target( expr= 'service:http_request_duration_seconds:50p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.5q', refId='A'), target( expr= 'service:http_request_duration_seconds:90p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.9q', refId='B'), target( expr= 'service:http_request_duration_seconds:99p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.99q', refId='C'), ], aliasColors=ALIAS_COLORS, yAxes=[ G.YAxis(format=G.MILLISECONDS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False) ]), ]), G.Row(panels=[ G.Graph( title='Ballots', dataSource='prometheus', targets=[ target( expr= 'service_version:isaacranks_ballot_generation_seconds_count:irate{{service="{}-isaacranks-web"}}', legendFormat='{{version}}', refId='A') ], yAxes=[ G.YAxis(format=G.OPS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False), ], nullPointMode=G.NULL_AS_ZERO, stack=True, lineWidth=0, fill=10, tooltip=G.Tooltip(valueType=G.INDIVIDUAL)), G.Graph( title='Ballot latency', dataSource='prometheus', targets=[ target( expr= 'service:isaacranks_ballot_generation_seconds:50p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.5q', refId='A'), target( expr= 'service:isaacranks_ballot_generation_seconds:90p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.9q', refId='B'), target( expr= 'service:isaacranks_ballot_generation_seconds:99p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.99q', refId='C'), ], yAxes=[ G.YAxis(format=G.MILLISECONDS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False) ]), ]), G.Row(panels=[ G.Graph( title='Votes', dataSource='prometheus', targets=[ target( expr= 'service_version:isaacranks_vote_casting_seconds_count:irate{{service="{}-isaacranks-web"}}', legendFormat='{{version}}', refId='A') ], yAxes=[ G.YAxis(format=G.OPS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False) ], nullPointMode=G.NULL_AS_ZERO, stack=True, lineWidth=0, fill=10, tooltip=G.Tooltip(valueType=G.INDIVIDUAL)), G.Graph( title='Vote latency', dataSource='prometheus', targets=[ target( expr= 'service:isaacranks_vote_casting_seconds:50p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.5q', refId='A'), target( expr= 'service:isaacranks_vote_casting_seconds:90p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.9q', refId='B'), target( expr= 'service:isaacranks_vote_casting_seconds:99p{{service="{}-isaacranks-web"}} * 1000', legendFormat='0.99q', refId='C'), ], yAxes=[ G.YAxis(format=G.MILLISECONDS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False) ]), ]), G.Row(panels=[ G.Graph( title='Time since last rebuild', dataSource='prometheus', targets=[ target( expr= 'time() - (isaacranks_last_rebuild_timestamp{{service="{}-isaacranks-rebuild"}} != 0)', legendFormat='Age') ], legend=G.Legend(current=True), yAxes=[ G.YAxis(format=G.SECONDS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False) ]), G.Graph( title='Rebuild duration', dataSource='prometheus', targets=[ target( expr= 'isaacranks_last_rebuild_duration_seconds{{service="{}-isaacranks-rebuild"}} != 0', legendFormat='Duration') ], legend=G.Legend(current=True), yAxes=[ G.YAxis(format=G.SECONDS_FORMAT), G.YAxis(format=G.SHORT_FORMAT, show=False) ]), ]) ]).auto_panel_ids()
def dashboard(): PROMETHEUS = "prometheus" return G.Dashboard( title="S4", rows=[ G.Row(panels=[ G.Graph( title="Signups", dataSource=PROMETHEUS, xAxis=X_TIME, yAxes=[ G.YAxis( format="none", label="Count", ), G.YAxis( format="none", label="Count", ), ], targets=[ G.Target( expr='wormhole_signup_started{pod=~"s4-signup.*"}', legendFormat="Wormhole Signups Started", refId="A", ), G.Target( expr='wormhole_signup_success{pod=~"s4-signup.*"}', legendFormat="Wormhole Signups Completed", refId="B", ), G.Target( expr='wormhole_signup_failure{pod=~"s4-signup.*"}', legendFormat="Wormhole Signups Failed", refId="C", ), ], ), G.Graph( title="Usage", dataSource=PROMETHEUS, # Stack the connection graphs on each other, revealing # both a total and a distribution across different grid # router instances. stack=True, tooltip=G.Tooltip( valueType=G.INDIVIDUAL, ), xAxis=X_TIME, yAxes=[ G.YAxis( format="none", label="Count", ), G.YAxis( format="none", label="Count", ), ], targets=[ G.Target( expr="grid_router_connections", legendFormat="Tahoe-LAFS Connections", refId="D", ), ], ), ]), G.Row( title="Cluster", panels=[ cpu_usage(PROMETHEUS, ["1m", "5m", "10m"]), memory_usage(PROMETHEUS), network_usage(PROMETHEUS), filesystem_usage(PROMETHEUS), ], ), G.Row(panels=[ G.SingleStat( title='Current Customer Deployments', dataSource='prometheus', valueName='current', sparkline=G.SparkLine(show=True), targets=[ G.Target( expr='s4_deployment_gauge', refId="E", ), ], ), G.SingleStat( title='Unhandled Errors', dataSource='prometheus', valueName='current', sparkline=G.SparkLine(show=True), targets=[ G.Target( expr='s4_unhandled_error_counter', refId="F", ), ], ), ]), ], ).auto_panel_ids()
G.SingleStat( editable=True, colorBackground=True, colorValue=False, colors=[G.ORANGE, G.GREEN, G.RED], dataSource="Prometheus", gauge=G.Gauge( maxValue=100, minValue=0, show=False, thresholdLabels=False, thresholdMarkers=True, ), title=app["name"], targets=[ G.Target( expr='up{{instance="{hostname}:{port}"}}'.format( hostname=app["hostname"], port=app["port"]), intervalFactor=2, legendFormat="", step=4, ) ], span=2, thresholds="0.1", transparent=True, valueMaps=[ G.ValueMap(op="=", text="N/A", value="null"), G.ValueMap(op="=", text="Down", value="0"), G.ValueMap(op="=", text="Up", value="1"), ], sparkline=G.SparkLine( fillColor=G.RGBA(31, 118, 109, 0.18), full=False, lineColor=G.RGB(31, 120, 193), show=False, ), rangeMaps=[G.RangeMap(start=None, text="N/A", end=None)], valueName="current", ) for app in APPS
"3xx": BLUE, "4xx": ORANGE, "5xx": RED, "success": GREEN, "error": RED, } dashboard = G.Dashboard( title='UCDAPI', rows=[ G.Row(panels=[ G.SingleStat( title='Pods Up', dataSource='prometheus', valueName='current', sparkline=G.SparkLine(show=True), targets=[ G.Target( expr='count by(service) (up{service="ucdapi"} == 1)', ) ]), ]), G.Row(panels=[ G.Graph( title='HTTP RPS', dataSource='prometheus', targets=[ G.Target( expr= 'service_status:http_request_duration_seconds_count:irate{service="ucdapi",status_code=~"1.."}', legendFormat='1xx', refId='A'),
'kubelet_volume_stats_used_bytes{namespace="cortex"} / kubelet_volume_stats_capacity_bytes{namespace="cortex"}' ), ], yAxes=common.PercentageAxes(), ), ], ), G.Row( title="Last runs", panels=[ G.SingleStat( dataSource=common.PROMETHEUS, title="Last Successful Compactor Run", targets=[ G.Target( '(time()-cortex_compactor_last_successful_run_timestamp_seconds) / 60', refId='A', ), ], format='m', # TODO: Add 'MINUTES_FORMAT' to grafanalib ), G.SingleStat( dataSource=common.PROMETHEUS, title="Last Successful Bucket Index Update", targets=[ G.Target( '(time()-max(cortex_bucket_index_last_successful_update_timestamp_seconds)) / 60', refId='A', ), ], format='m', # TODO: Add 'MINUTES_FORMAT' to grafanalib