Skip to content

Commit 316eabc

Browse files
authored
Add grafana + color support (#2)
1 parent 51209f2 commit 316eabc

15 files changed

+3038
-28
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ vendor/
1818
data/
1919
metrics/
2020
frames/
21-
*.mkv
21+
videos/

README.md

+33-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
1-
# prom_bad_apple
1+
# prometheus_video_renderer
22

3-
Plays videos using [Prometheus](https://prometheus.io/), e.g. [Bad Apple](https://www.youtube.com/watch?v=ApJxFprSTqA).
3+
Plays videos using [Prometheus](https://prometheus.io/) and [Grafana](grafana.com/), e.g. [Bad Apple](https://www.youtube.com/watch?v=ApJxFprSTqA).
44

5-
![preview](preview.gif)
5+
![grafana](docs/img/rgb_grafana.png)
6+
7+
## Modes
8+
9+
Currently 3 different modes are supported.
10+
11+
### Bitmap
12+
13+
The bitmap mode either creates a sample or does not, depending on the brightness of the source image. It is the only mode compatible with the Prometheus UI.
14+
15+
![bitmap-preview](docs/img/demo/bitmap.gif)
16+
17+
Example: https://www.youtube.com/watch?v=ApJxFprSTqA
18+
19+
### Grayscale
20+
21+
The RGB mode creates a metric and sets a brightness label matching an override for each unique brightness.
22+
23+
This is made with 256 unique overrides.
24+
25+
Example coming soon.
26+
27+
### RGB
28+
29+
The RGB mode creates offset metrics for red, green, and blue, and sets a brightness label matching an override for each unique color/brightness.
30+
31+
This is 22-bit color, made with 640 unique overrides.
32+
33+
Example: https://www.youtube.com/watch?v=aLvh0oId3Go
634

735
## Inspiration
836

@@ -16,10 +44,10 @@ A while back I thought [this blog post](https://giedrius.blog/2019/09/21/is-it-a
1644
- If you would like to make sure that the y axis doesn't change, you can add 1px white bars to each frame. e.g.
1745
- `ffmpeg -i frames\out%06d.png -vf "crop=in_w:in_h-1:0:1,pad=iw+0:ih+1:0:1:#FFFFFF@1,format=rgb24" -y frames\out%06d.png`
1846
- `ffmpeg -i frames\out%06d.png -vf "crop=in_w:in_h-1:0:-1,pad=iw+0:ih+1:0:-1:#FFFFFF@1,format=rgb24" -y frames\out%06d.png`
19-
- `go run main.go`
47+
- `go run main.go --project="bad_apple"` (use `--help` to see all arguments)
2048
- Loop over the files and send them to `promtool tsdb create-blocks-from openmetrics`
2149
- `docker compose up`
2250
- Wait for Prometheus to compact etc. so it doesn't take 20 years to render.
23-
- Run `prom_record.ahk` or some other script to record all the frames from the UI.
51+
- Run a script to record all the frames from the UI. (Mediocre examples are in the scripts directory.)
2452
- `cd` to wherever you stored your screenshots.
2553
- Generate the video file `ffmpeg -framerate 30 -i '%06d.png' -c:v libx264 -pix_fmt yuv420p out.mp4`

docker-compose.yaml

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version: '3'
22

3+
networks:
4+
prometheus-video-renderer:
5+
36
services:
47
prometheus:
58
image: prom/prometheus:v2.27.0
@@ -12,4 +15,29 @@ services:
1215
- '--config.file=/etc/prometheus/prometheus.yaml'
1316
- '--storage.tsdb.path=/prometheus'
1417
- '--storage.tsdb.retention.time=20y'
15-
- '--query.lookback-delta=5s'
18+
- '--query.lookback-delta=1s'
19+
networks:
20+
- prometheus-video-renderer
21+
22+
grafana:
23+
image: grafana/grafana:7.5.6
24+
ports:
25+
- 3000:3000
26+
volumes:
27+
- ./grafana/dashboards:/etc/dashboards
28+
- ./grafana/dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml
29+
- ./grafana/datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
30+
environment:
31+
GF_INSTALL_PLUGINS: grafana-image-renderer
32+
GF_RENDERING_SERVER_URL: http://renderer:8081/render
33+
GF_RENDERING_CALLBACK_URL: http://grafana:3000/
34+
GF_LOG_FILTERS: rendering:debug
35+
networks:
36+
- prometheus-video-renderer
37+
38+
renderer:
39+
image: grafana/grafana-image-renderer:2.1.1
40+
ports:
41+
- 8081:8081
42+
networks:
43+
- prometheus-video-renderer
File renamed without changes.

docs/img/rgb_grafana.png

412 KB
Loading

grafana/dashboard.jsonnet

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
local grafana = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet';
2+
local dashboard = grafana.dashboard;
3+
local row = grafana.row;
4+
local graphPanel = grafana.graphPanel;
5+
local prometheus = grafana.prometheus;
6+
local template = grafana.template;
7+
8+
local videoHeight = 100;
9+
10+
local videoPanel =
11+
graphPanel.new(
12+
'Video',
13+
min=0,
14+
max=videoHeight * 3,
15+
fill=0,
16+
linewidth=2,
17+
interval='1s',
18+
transparent=false,
19+
legend_show=false,
20+
shared_tooltip=false,
21+
datasource='Prometheus',
22+
)
23+
.addTarget(
24+
prometheus.target(
25+
'r',
26+
legendFormat='r{{l}}',
27+
intervalFactor=1,
28+
)
29+
)
30+
.addTarget(
31+
prometheus.target(
32+
'g',
33+
legendFormat='g{{l}}',
34+
intervalFactor=1,
35+
)
36+
)
37+
.addTarget(
38+
prometheus.target(
39+
'b',
40+
legendFormat='b{{l}}',
41+
intervalFactor=1,
42+
)
43+
) + {
44+
seriesOverrides+: [
45+
{
46+
alias: 'r%s' % l,
47+
color: 'rgb(%s, 0, 0)' % l,
48+
}
49+
for l in std.range(0, 255)
50+
] + [
51+
{
52+
alias: 'g%s' % l,
53+
color: 'rgb(0, %s, 0)' % l,
54+
}
55+
for l in std.range(0, 255)
56+
] + [
57+
{
58+
alias: 'b%s' % l,
59+
color: 'rgb(0, 0, %s)' % (l * 2),
60+
}
61+
for l in std.range(0, 127)
62+
],
63+
};
64+
65+
dashboard.new(
66+
'Prometheus Video Renderer',
67+
uid='pvr-dash',
68+
timezone='utc',
69+
schemaVersion=16,
70+
)
71+
.addTemplate(
72+
grafana.template.datasource(
73+
'PROMETHEUS_DS',
74+
'prometheus',
75+
'Prometheus',
76+
hide='label',
77+
)
78+
)
79+
.addPanel(
80+
videoPanel, gridPos={
81+
x: 0,
82+
y: 0,
83+
w: 24,
84+
h: 25,
85+
}
86+
)

grafana/dashboards.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: 1
2+
3+
providers:
4+
- name: 'prometheus-video-renderer'
5+
orgId: 1
6+
folder: ''
7+
folderUid: ''
8+
type: file
9+
disableDeletion: false
10+
updateIntervalSeconds: 10
11+
allowUiUpdates: false
12+
options:
13+
path: /etc/dashboards
14+
foldersFromFilesStructure: false

0 commit comments

Comments
 (0)