Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
goos: [linux]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"

Expand All @@ -31,7 +31,7 @@ jobs:
make static BIN=plausible-exporter-${{matrix.goos}}-${{matrix.goarch}}

- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v6
with:
name: myapp-${{ matrix.goos }}-${{ matrix.goarch }}
path: myapp-${{ matrix.goos }}-${{ matrix.goarch }}
15 changes: 4 additions & 11 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ name: Docker Container
on:
workflow_dispatch:
push:
branches: [ "main" ]
branches: ["main"]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
tags: ["v*.*.*"]
pull_request:
branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
# Target platforms
PLATFORMS: linux/amd64,linux/arm/v7,linux/arm64
branches: ["main"]

jobs:
build:
uses: riesinger/github-workflows/.github/workflows/build-docker.yml@main
with:
image-name: plausible-exporter
platforms: linux/amd64,linux/arm/v7,linux/arm64
secrets: inherit
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine as builder
FROM golang:1.26-alpine as builder

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / build / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

WORKDIR /go/src/app

Expand All @@ -11,7 +11,7 @@
RUN CGO_ENABLED=0 go install -ldflags '-s -w -extldflags "-static"' -tags timetzdata ./cmd
RUN ls -l /go/bin

FROM scratch as runner

Check warning on line 14 in Dockerfile

View workflow job for this annotation

GitHub Actions / build / build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Copy the built binary
COPY --from=builder /go/bin/cmd /plausible-exporter
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ All options can be set in the config file or environment variables, with environ

### Prometheus

This exporter creates 4 metrics:
This exporter creates 5 metrics:

- `plausible_visitors` - How many visitors were on your site on the current day
- `plausible_visit_duration` - How long an average visit to your site was (in seconds)
- `plausible_pageviews` - How many page views your site had today
- `plausible_bounce_rate` - How many visitors left your site (in percent, 0-100)
- `plausible_health` - Health status of Plausible API components (1 for healthy, 0 for unhealthy)

In case you've configured multiple sites to be scraped, you can differentiate between them with the `site_id` label.
In case you've configured multiple sites to be scraped, you can differentiate between them with the `site_id` label. The health metric uses a `component` label.

### Grafana

Expand Down
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
for _, siteID := range siteIDs {
plausibleClients[siteID] = &plausible.Client{HostAPIBase: plausibleHost, SiteID: siteID, Token: token}
}
plausibleApp := &plausible.Client{HostAPIBase: plausibleHost}

metrics := prometheus.NewServer(siteIDs)

Expand All @@ -40,6 +41,13 @@ func main() {
metrics.UpdateDataForSite(siteID, data)
log.Printf("Data for site %s was refreshed from plausible", siteID)
}

status, err := plausibleApp.GetHealth()
if err != nil {
log.Printf("Refreshing health status failed: %v", err)
return
}
metrics.UpdateHealthStatusForSite(status)
}

go func() {
Expand Down
99 changes: 93 additions & 6 deletions examples/grafana-dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,102 @@
],
"title": "Bounce Rate",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "fixed"
},
"custom": {
"axisPlacement": "auto",
"fillOpacity": 70,
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineWidth": 0,
"spanNulls": false
},
"mappings": [
{
"options": {
"0": {
"color": "red",
"index": 0,
"text": "DOWN"
},
"1": {
"color": "green",
"index": 1,
"text": "UP"
}
},
"type": "value"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 5,
"w": 24,
"x": 0,
"y": 10
},
"id": 14,
"options": {
"alignValue": "left",
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": false
},
"mergeValues": true,
"rowHeight": 0.9,
"showValue": "auto",
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.0.9",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "plausible_health",
"format": "time_series",
"legendFormat": "{{component}}",
"range": true,
"refId": "A"
}
],
"title": "Health",
"type": "state-timeline"
}
],
"schemaVersion": 37,
"style": "dark",
"tags": [
"plausible",
"analytics",
"website"
],
"tags": ["plausible", "analytics", "website"],
"templating": {
"list": [
{
Expand Down Expand Up @@ -533,4 +620,4 @@
"uid": "ABqIcJ2Vk",
"version": 5,
"weekStart": ""
}
}
46 changes: 21 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
module github.com/riesinger/plausible-exporter

go 1.22
go 1.26

require (
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.13.0
github.com/spf13/viper v1.13.0
github.com/prometheus/client_golang v1.23.2
github.com/spf13/viper v1.21.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
github.com/sagikazarmark/locafero v0.12.0 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)
Loading
Loading