code.gitea.io/gitea@v1.21.7/contrib/gitea-monitoring-mixin/dashboards/overview.libsonnet (about) 1 local grafana = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet'; 2 local prometheus = grafana.prometheus; 3 4 local addIssueLabelsOverrides(labels) = 5 { 6 fieldConfig+: { 7 overrides+: [ 8 { 9 matcher: { 10 id: 'byRegexp', 11 options: label.label, 12 }, 13 properties: [ 14 { 15 id: 'color', 16 value: { 17 fixedColor: label.color, 18 mode: 'fixed', 19 }, 20 }, 21 ], 22 } 23 for label in labels 24 ], 25 }, 26 }; 27 28 { 29 30 grafanaDashboards+:: { 31 32 local giteaSelector = 'job=~"$job", instance=~"$instance"', 33 local giteaStatsPanel = 34 grafana.statPanel.new( 35 'Gitea stats', 36 datasource='$datasource', 37 reducerFunction='lastNotNull', 38 graphMode='none', 39 colorMode='value', 40 ) 41 .addTargets( 42 [ 43 prometheus.target(expr='%s{%s}' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=10) 44 for metric in $._config.giteaStatMetrics 45 ] 46 ) 47 + { 48 fieldConfig+: { 49 defaults+: { 50 color: { 51 fixedColor: 'blue', 52 mode: 'fixed', 53 }, 54 }, 55 }, 56 }, 57 58 local giteaUptimePanel = 59 grafana.statPanel.new( 60 'Uptime', 61 datasource='$datasource', 62 reducerFunction='last', 63 graphMode='area', 64 colorMode='value', 65 ) 66 .addTarget(prometheus.target(expr='time()-process_start_time_seconds{%s}' % giteaSelector, intervalFactor=1)) 67 + { 68 fieldConfig+: { 69 defaults+: { 70 color: { 71 fixedColor: 'blue', 72 mode: 'fixed', 73 }, 74 unit: 's', 75 }, 76 }, 77 }, 78 79 local giteaMemoryPanel = 80 grafana.graphPanel.new( 81 'Memory usage', 82 datasource='$datasource' 83 ) 84 .addTarget(prometheus.target(expr='process_resident_memory_bytes{%s}' % giteaSelector, intervalFactor=2)) 85 + { 86 type: 'timeseries', 87 options+: { 88 tooltip: { 89 mode: 'multi', 90 }, 91 legend+: { 92 displayMode: 'hidden', 93 }, 94 }, 95 fieldConfig+: { 96 defaults+: { 97 custom+: { 98 lineInterpolation: 'smooth', 99 fillOpacity: 15, 100 }, 101 color: { 102 fixedColor: 'green', 103 mode: 'fixed', 104 }, 105 unit: 'decbytes', 106 }, 107 }, 108 }, 109 110 local giteaCpuPanel = 111 grafana.graphPanel.new( 112 'CPU usage', 113 datasource='$datasource' 114 ) 115 .addTarget(prometheus.target(expr='rate(process_cpu_seconds_total{%s}[$__rate_interval])*100' % giteaSelector, intervalFactor=2)) 116 + { 117 type: 'timeseries', 118 options+: { 119 tooltip: { 120 mode: 'multi', 121 }, 122 legend+: { 123 displayMode: 'hidden', 124 }, 125 }, 126 fieldConfig+: { 127 defaults+: { 128 custom+: { 129 lineInterpolation: 'smooth', 130 gradientMode: 'scheme', 131 fillOpacity: 15, 132 axisSoftMin: 0, 133 axisSoftMax: 0, 134 }, 135 color: { 136 mode: 'continuous-GrYlRd', // from green to red (100%) 137 }, 138 unit: 'percent', 139 }, 140 overrides: [ 141 { 142 matcher: { 143 id: 'byRegexp', 144 options: '.+', 145 }, 146 properties: [ 147 { 148 id: 'max', 149 value: 100, 150 }, 151 { 152 id: 'min', 153 value: 0, 154 }, 155 ], 156 }, 157 ], 158 }, 159 }, 160 161 local giteaFileDescriptorsPanel = 162 grafana.graphPanel.new( 163 'File descriptors usage', 164 datasource='$datasource', 165 ) 166 .addTarget(prometheus.target(expr='process_open_fds{%s}' % giteaSelector, intervalFactor=2)) 167 .addTarget(prometheus.target(expr='process_max_fds{%s}' % giteaSelector, intervalFactor=2)) 168 .addSeriesOverride( 169 { 170 alias: '/process_max_fds.+/', 171 color: '#F2495C', // red 172 dashes: true, 173 fill: 0, 174 }, 175 ) 176 + { 177 type: 'timeseries', 178 options+: { 179 tooltip: { 180 mode: 'multi', 181 }, 182 legend+: { 183 displayMode: 'hidden', 184 }, 185 }, 186 fieldConfig+: { 187 defaults+: { 188 custom+: { 189 lineInterpolation: 'smooth', 190 gradientMode: 'scheme', 191 fillOpacity: 0, 192 }, 193 color: { 194 fixedColor: 'green', 195 mode: 'fixed', 196 }, 197 unit: '', 198 }, 199 overrides: [ 200 { 201 matcher: { 202 id: 'byFrameRefID', 203 options: 'B', 204 }, 205 properties: [ 206 { 207 id: 'custom.lineStyle', 208 value: { 209 fill: 'dash', 210 dash: [ 211 10, 212 10, 213 ], 214 }, 215 }, 216 { 217 id: 'color', 218 value: { 219 mode: 'fixed', 220 fixedColor: 'red', 221 }, 222 }, 223 ], 224 }, 225 ], 226 }, 227 }, 228 229 local giteaChangesPanelPrototype = 230 grafana.graphPanel.new( 231 '', 232 datasource='$datasource', 233 interval='$agg_interval', 234 maxDataPoints=10000, 235 ) 236 + { 237 type: 'timeseries', 238 options+: { 239 tooltip: { 240 mode: 'multi', 241 }, 242 legend+: { 243 calcs+: [ 244 'sum', 245 ], 246 }, 247 }, 248 fieldConfig+: { 249 defaults+: { 250 noValue: '0', 251 custom+: { 252 drawStyle: 'bars', 253 barAlignment: -1, 254 fillOpacity: 50, 255 gradientMode: 'hue', 256 pointSize: 1, 257 lineWidth: 0, 258 stacking: { 259 group: 'A', 260 mode: 'normal', 261 }, 262 }, 263 }, 264 }, 265 }, 266 267 local giteaChangesPanelAll = 268 giteaChangesPanelPrototype 269 .addTarget(prometheus.target(expr='changes(process_start_time_seconds{%s}[$__interval]) > 0' % [giteaSelector], legendFormat='Restarts', intervalFactor=1)) 270 .addTargets( 271 [ 272 prometheus.target(expr='floor(delta(%s{%s}[$__interval])) > 0' % [metric.name, giteaSelector], legendFormat=metric.description, intervalFactor=1) 273 for metric in $._config.giteaStatMetrics 274 ] 275 ) + { id: 200 }, // some unique number, beyond the maximum number of panels in the dashboard, 276 277 local giteaChangesPanelTotal = 278 grafana.statPanel.new( 279 'Changes', 280 datasource='-- Dashboard --', 281 reducerFunction='sum', 282 graphMode='none', 283 textMode='value_and_name', 284 colorMode='value', 285 ) 286 + { 287 targets+: [ 288 { 289 panelId: giteaChangesPanelAll.id, 290 refId: 'A', 291 }, 292 ], 293 } 294 + { 295 fieldConfig+: { 296 defaults+: { 297 color: { 298 mode: 'palette-classic', 299 }, 300 }, 301 }, 302 }, 303 304 local giteaChangesByRepositories = 305 giteaChangesPanelPrototype 306 .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_repository{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ repository }}', intervalFactor=1)) 307 + { id: 210 }, // some unique number, beyond the maximum number of panels in the dashboard, 308 309 local giteaChangesByRepositoriesTotal = 310 grafana.statPanel.new( 311 'Issues by repository', 312 datasource='-- Dashboard --', 313 reducerFunction='sum', 314 graphMode='none', 315 textMode='value_and_name', 316 colorMode='value', 317 ) 318 + { 319 id: 211, 320 targets+: [ 321 { 322 panelId: giteaChangesByRepositories.id, 323 refId: 'A', 324 }, 325 ], 326 } 327 + { 328 fieldConfig+: { 329 defaults+: { 330 color: { 331 mode: 'palette-classic', 332 }, 333 }, 334 }, 335 }, 336 337 local giteaChangesByLabel = 338 giteaChangesPanelPrototype 339 .addTarget(prometheus.target(expr='floor(increase(gitea_issues_by_label{%s}[$__interval])) > 0' % [giteaSelector], legendFormat='{{ label }}', intervalFactor=1)) 340 + addIssueLabelsOverrides($._config.issueLabels) 341 + { id: 220 }, // some unique number, beyond the maximum number of panels in the dashboard, 342 343 local giteaChangesByLabelTotal = 344 grafana.statPanel.new( 345 'Issues by labels', 346 datasource='-- Dashboard --', 347 reducerFunction='sum', 348 graphMode='none', 349 textMode='value_and_name', 350 colorMode='value', 351 ) 352 + addIssueLabelsOverrides($._config.issueLabels) 353 + { 354 id: 221, 355 targets+: [ 356 { 357 panelId: giteaChangesByLabel.id, 358 refId: 'A', 359 }, 360 ], 361 } 362 + { 363 fieldConfig+: { 364 defaults+: { 365 color: { 366 mode: 'palette-classic', 367 }, 368 }, 369 }, 370 }, 371 372 'gitea-overview.json': 373 grafana.dashboard.new( 374 '%s Overview' % $._config.dashboardNamePrefix, 375 time_from='%s' % $._config.dashboardPeriod, 376 editable=false, 377 tags=($._config.dashboardTags), 378 timezone='%s' % $._config.dashboardTimezone, 379 refresh='%s' % $._config.dashboardRefresh, 380 graphTooltip='shared_crosshair', 381 uid='gitea-overview' 382 ) 383 .addTemplate( 384 { 385 current: { 386 text: 'Prometheus', 387 value: 'Prometheus', 388 }, 389 hide: 0, 390 label: 'Data Source', 391 name: 'datasource', 392 options: [], 393 query: 'prometheus', 394 refresh: 1, 395 regex: '', 396 type: 'datasource', 397 }, 398 ) 399 .addTemplate( 400 { 401 hide: 0, 402 label: 'job', 403 name: 'job', 404 options: [], 405 datasource: '$datasource', 406 query: 'label_values(gitea_organizations, job)', 407 refresh: 1, 408 regex: '', 409 type: 'query', 410 multi: true, 411 allValue: '.+' 412 }, 413 ) 414 .addTemplate( 415 { 416 hide: 0, 417 label: 'instance', 418 name: 'instance', 419 options: [], 420 datasource: '$datasource', 421 query: 'label_values(gitea_organizations{job="$job"}, instance)', 422 refresh: 1, 423 regex: '', 424 type: 'query', 425 multi: true, 426 allValue: '.+' 427 }, 428 ) 429 .addTemplate( 430 { 431 hide: 0, 432 label: 'aggregation interval', 433 name: 'agg_interval', 434 auto_min: '1m', 435 auto: true, 436 query: '1m,10m,1h,1d,7d', 437 type: 'interval', 438 }, 439 ) 440 .addPanel(grafana.row.new(title='General'), gridPos={ x: 0, y: 0, w: 0, h: 0 },) 441 .addPanel(giteaStatsPanel, gridPos={ x: 0, y: 0, w: 16, h: 4 }) 442 .addPanel(giteaUptimePanel, gridPos={ x: 16, y: 0, w: 8, h: 4 }) 443 .addPanel(giteaMemoryPanel, gridPos={ x: 0, y: 4, w: 8, h: 6 }) 444 .addPanel(giteaCpuPanel, gridPos={ x: 8, y: 4, w: 8, h: 6 }) 445 .addPanel(giteaFileDescriptorsPanel, gridPos={ x: 16, y: 4, w: 8, h: 6 }) 446 .addPanel(grafana.row.new(title='Changes', collapse=false), gridPos={ x: 0, y: 10, w: 24, h: 8 }) 447 .addPanel(giteaChangesPanelTotal, gridPos={ x: 0, y: 12, w: 6, h: 8 }) 448 + // use patching instead of .addPanel() to keep static ids 449 { 450 panels+: std.flattenArrays([ 451 [ 452 giteaChangesPanelAll { gridPos: { x: 6, y: 12, w: 18, h: 8 } }, 453 ], 454 if $._config.showIssuesByRepository then 455 [ 456 giteaChangesByRepositoriesTotal { gridPos: { x: 0, y: 20, w: 6, h: 8 } }, 457 giteaChangesByRepositories { gridPos: { x: 6, y: 20, w: 18, h: 8 } }, 458 ] else [], 459 if $._config.showIssuesByLabel then 460 [ 461 giteaChangesByLabelTotal { gridPos: { x: 0, y: 28, w: 6, h: 8 } }, 462 giteaChangesByLabel { gridPos: { x: 6, y: 28, w: 18, h: 8 } }, 463 ] else [], 464 ]), 465 }, 466 }, 467 }