diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fa55399 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +** + +# Allowed things +!src/** +!Cargo.lock +!Cargo.toml +!LICENSE + +# Extra exclude from allowed things +**/*~ +**/*.log +**/.DS_Store +**/Thumbs.db +**/__pycache__ +**/*.md +**/*.rst diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..a5d069d --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,71 @@ +name: Publish Docker image + +on: + push: + branches: ["main"] + tags: ["v*"] + +permissions: read-all + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the container registry + uses: docker/login-action@v3 + with: + registry: ${{ vars.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_REPOSITORY }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + release: + runs-on: ubuntu-latest + if: startsWith(github.event.ref, 'refs/tags/v') + needs: [build-and-push-image] + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Create release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + + - name: Update Docker Hub repository description + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: ${{ vars.DOCKER_REPOSITORY }} diff --git a/.gitignore b/.gitignore index 6eb628e..dd0d8c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ lcov.info *.log +.env # Created by https://www.toptal.com/developers/gitignore/api/osx,rust,linux,windows,visualstudiocode # Edit at https://www.toptal.com/developers/gitignore?templates=osx,rust,linux,windows,visualstudiocode diff --git a/Cargo.lock b/Cargo.lock index ef33169..faf39a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -758,7 +758,7 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "onepassword-exporter" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 5aee5fb..b016031 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "onepassword-exporter" -version = "0.1.0" +version = "0.2.0" edition = "2021" [dependencies] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23fb8d7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM rustlang/rust:nightly-bookworm-slim AS builder + +WORKDIR /build +COPY . . +RUN cargo build --release + +FROM 1password/op:2 AS runtime + +COPY --from=builder /build/target/release/onepassword-exporter /usr/local/bin/onepassword-exporter + +ENTRYPOINT ["onepassword-exporter"] +CMD ["--host", "0.0.0.0"] diff --git a/examples/grafana-dashboard/.env.example b/examples/grafana-dashboard/.env.example new file mode 100644 index 0000000..41e1a08 --- /dev/null +++ b/examples/grafana-dashboard/.env.example @@ -0,0 +1 @@ +OP_SERVICE_ACCOUNT_TOKEN="ops_ey..." diff --git a/examples/grafana-dashboard/README.md b/examples/grafana-dashboard/README.md new file mode 100644 index 0000000..565621c --- /dev/null +++ b/examples/grafana-dashboard/README.md @@ -0,0 +1,21 @@ +# Grafana Dashboard Example + +This example shows example setup using Docker Compose with preconfigured Grafana dashboard for 1Password Exporter. + +## Usage + +Create `.env` file with appropriate values (see `.env.example` for required values): + +```dotenv +OP_SERVICE_ACCOUNT_TOKEN='ops_...' +``` + +Start Docker Compose: + +```bash +$ docker compose up -d +``` + +Then open Grafana running at http://localhost:3000 (default admin username and password are both `"admin"`) then go to Dashboards and you will find 1Password Exporter dashboard. + +![Dashboard Screenshot](dashboard-screenshot.png) diff --git a/examples/grafana-dashboard/dashboard-screenshot.png b/examples/grafana-dashboard/dashboard-screenshot.png new file mode 100644 index 0000000..2130165 Binary files /dev/null and b/examples/grafana-dashboard/dashboard-screenshot.png differ diff --git a/examples/grafana-dashboard/dashboard.json b/examples/grafana-dashboard/dashboard.json index 1d2386f..b22ef17 100644 --- a/examples/grafana-dashboard/dashboard.json +++ b/examples/grafana-dashboard/dashboard.json @@ -18,9 +18,21 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": 2, "links": [], "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 24, + "panels": [], + "title": "Summary", + "type": "row" + }, { "datasource": { "type": "prometheus", @@ -38,6 +50,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -84,7 +97,7 @@ "h": 16, "w": 24, "x": 0, - "y": 0 + "y": 1 }, "id": 22, "options": { @@ -191,13 +204,15 @@ "type": "timeseries" }, { + "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, - "y": 16 + "y": 17 }, "id": 12, + "panels": [], "title": "Account", "type": "row" }, @@ -239,7 +254,7 @@ "h": 20, "w": 8, "x": 0, - "y": 17 + "y": 18 }, "id": 2, "options": { @@ -254,7 +269,7 @@ }, "showHeader": true }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -320,7 +335,7 @@ "h": 3, "w": 3, "x": 8, - "y": 17 + "y": 18 }, "id": 16, "options": { @@ -340,7 +355,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -379,6 +394,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -425,7 +441,7 @@ "h": 10, "w": 13, "x": 11, - "y": 17 + "y": 18 }, "id": 13, "options": { @@ -532,7 +548,7 @@ "h": 7, "w": 3, "x": 8, - "y": 20 + "y": 21 }, "id": 15, "options": { @@ -550,7 +566,7 @@ "showThresholdMarkers": true, "sizing": "auto" }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -620,6 +636,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -666,7 +683,7 @@ "h": 10, "w": 8, "x": 8, - "y": 27 + "y": 28 }, "id": 4, "options": { @@ -720,6 +737,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -766,7 +784,7 @@ "h": 10, "w": 8, "x": 16, - "y": 27 + "y": 28 }, "id": 3, "options": { @@ -809,7 +827,7 @@ "h": 1, "w": 24, "x": 0, - "y": 37 + "y": 38 }, "id": 11, "panels": [], @@ -838,7 +856,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -853,7 +872,7 @@ "h": 20, "w": 8, "x": 0, - "y": 38 + "y": 39 }, "id": 5, "options": { @@ -868,7 +887,7 @@ }, "showHeader": true }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -919,7 +938,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null } ] }, @@ -931,7 +951,7 @@ "h": 3, "w": 3, "x": 8, - "y": 38 + "y": 39 }, "id": 19, "options": { @@ -951,7 +971,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -990,6 +1010,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -1020,7 +1041,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1035,7 +1057,7 @@ "h": 10, "w": 13, "x": 11, - "y": 38 + "y": 39 }, "id": 6, "options": { @@ -1120,7 +1142,8 @@ "mode": "percentage", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "#EAB839", @@ -1140,7 +1163,7 @@ "h": 7, "w": 3, "x": 8, - "y": 41 + "y": 42 }, "id": 18, "options": { @@ -1158,7 +1181,7 @@ "showThresholdMarkers": true, "sizing": "auto" }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -1226,7 +1249,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null } ] }, @@ -1238,7 +1262,7 @@ "h": 3, "w": 3, "x": 8, - "y": 48 + "y": 49 }, "id": 21, "options": { @@ -1258,7 +1282,7 @@ "textMode": "auto", "wideLayout": true }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -1297,6 +1321,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -1327,7 +1352,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1342,7 +1368,7 @@ "h": 10, "w": 13, "x": 11, - "y": 48 + "y": 49 }, "id": 14, "options": { @@ -1427,7 +1453,8 @@ "mode": "percentage", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "#EAB839", @@ -1447,7 +1474,7 @@ "h": 7, "w": 3, "x": 8, - "y": 51 + "y": 52 }, "id": 20, "options": { @@ -1465,7 +1492,7 @@ "showThresholdMarkers": true, "sizing": "auto" }, - "pluginVersion": "11.1.3", + "pluginVersion": "11.2.0", "targets": [ { "datasource": { @@ -1518,6 +1545,19 @@ ], "type": "gauge" }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 59 + }, + "id": 23, + "panels": [], + "title": "Vault", + "type": "row" + }, { "datasource": { "type": "prometheus", @@ -1535,6 +1575,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -1565,7 +1606,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1580,7 +1622,7 @@ "h": 10, "w": 8, "x": 0, - "y": 58 + "y": 60 }, "id": 9, "options": { @@ -1619,6 +1661,7 @@ }, { "datasource": { + "default": true, "type": "prometheus", "uid": "PBFA97CFB590B2093" }, @@ -1634,6 +1677,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -1664,7 +1708,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1679,9 +1724,9 @@ "h": 10, "w": 8, "x": 8, - "y": 58 + "y": 60 }, - "id": 8, + "id": 31, "options": { "legend": { "calcs": [], @@ -1703,21 +1748,23 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "op_item_count_total", + "expr": "op_item_count_per_vault", "fullMetaSearch": false, + "hide": false, "includeNullMetadata": true, "instant": false, "legendFormat": "__auto", "range": true, - "refId": "A", + "refId": "B", "useBackend": false } ], - "title": "Number of Items", + "title": "Items per Vault", "type": "timeseries" }, { "datasource": { + "default": true, "type": "prometheus", "uid": "PBFA97CFB590B2093" }, @@ -1733,6 +1780,7 @@ "axisLabel": "", "axisPlacement": "auto", "barAlignment": 0, + "barWidthFactor": 0.6, "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", @@ -1763,7 +1811,8 @@ "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1778,9 +1827,9 @@ "h": 10, "w": 8, "x": 16, - "y": 58 + "y": 60 }, - "id": 7, + "id": 28, "options": { "legend": { "calcs": [], @@ -1802,7 +1851,7 @@ }, "disableTextWrap": false, "editorMode": "builder", - "expr": "op_document_count_total", + "expr": "op_document_count_per_vault", "fullMetaSearch": false, "includeNullMetadata": true, "instant": false, @@ -1812,7 +1861,7 @@ "useBackend": false } ], - "title": "Number of Documents", + "title": "Documents per Vault", "type": "timeseries" }, { @@ -1821,36 +1870,64 @@ "h": 1, "w": 24, "x": 0, - "y": 68 + "y": 70 }, - "id": 10, + "id": 25, "panels": [], - "title": "Misc", + "title": "Item", "type": "row" }, { "datasource": { + "default": true, "type": "prometheus", "uid": "PBFA97CFB590B2093" }, "fieldConfig": { "defaults": { "color": { - "mode": "thresholds" + "mode": "palette-classic" }, "custom": { - "align": "auto", - "cellOptions": { - "type": "auto" + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false }, - "inspect": false + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { - "color": "green" + "color": "green", + "value": null }, { "color": "red", @@ -1862,25 +1939,535 @@ "overrides": [] }, "gridPos": { - "h": 11, + "h": 10, "w": 8, "x": 0, - "y": 69 + "y": 71 }, - "id": 1, + "id": 8, "options": { - "cellHeight": "sm", - "footer": { - "countRows": false, - "fields": "", - "reducer": [ - "sum" - ], - "show": false + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true }, - "showHeader": true + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.1.3", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "op_item_count_total", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Number of Items", + "type": "timeseries" + }, + { + "datasource": { + "default": true, + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 8, + "x": 8, + "y": 71 + }, + "id": 29, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } }, "pluginVersion": "11.1.3", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "op_item_count_per_category", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Items per Category", + "type": "timeseries" + }, + { + "datasource": { + "default": true, + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 8, + "x": 16, + "y": 71 + }, + "id": 30, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.1.3", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "op_item_count_per_tag", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Items per Tag", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 81 + }, + "id": 26, + "panels": [], + "title": "Document", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 8, + "x": 0, + "y": 82 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.1.3", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "op_document_count_total", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Number of Documents", + "type": "timeseries" + }, + { + "datasource": { + "default": true, + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 10, + "w": 8, + "x": 8, + "y": 82 + }, + "id": 27, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.1.3", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "op_document_count_per_tag", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Documents per Tag", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 92 + }, + "id": 10, + "panels": [], + "title": "Misc", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "PBFA97CFB590B2093" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 8, + "x": 0, + "y": 93 + }, + "id": 1, + "options": { + "cellHeight": "sm", + "footer": { + "countRows": false, + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true + }, + "pluginVersion": "11.2.0", "targets": [ { "datasource": { diff --git a/examples/grafana-dashboard/docker-compose.yaml b/examples/grafana-dashboard/docker-compose.yaml index 768900e..7aaf582 100644 --- a/examples/grafana-dashboard/docker-compose.yaml +++ b/examples/grafana-dashboard/docker-compose.yaml @@ -1,10 +1,18 @@ services: + onepassword-exporter: + image: lasuillard/1password-exporter:main + ports: + - ${OP_EXPORTER_HOST:-127.0.0.1}:${OP_EXPORTER_PORT:-9999}:9999 + environment: + OP_SERVICE_ACCOUNT_TOKEN: ${OP_SERVICE_ACCOUNT_TOKEN:?} + command: --log-level DEBUG --host 0.0.0.0 --metrics account build-info document group item service-account user vault + prometheus: image: prom/prometheus:latest extra_hosts: - host.docker.internal:host-gateway ports: - - 9090:9090 + - ${PROMETHEUS_HOST:-127.0.0.1}:${PROMETHEUS_PORT:-9090}:9090 volumes: - prometheus-data:/prometheus configs: @@ -16,7 +24,7 @@ services: grafana: image: grafana/grafana:latest ports: - - 3000:3000 + - ${GRAFANA_HOST:-127.0.0.1}:${GRAFANA_PORT:-3000}:3000 volumes: - ./dashboard.json:/var/lib/grafana/dashboards/dashboard.json configs: @@ -69,13 +77,13 @@ configs: scrape_configs: - job_name: onepassword honor_timestamps: true - scrape_interval: 30s - scrape_timeout: 15s + scrape_interval: 180s + scrape_timeout: 30s metrics_path: /metrics scheme: http static_configs: - targets: - - host.docker.internal:9999 + - onepassword-exporter:9999 volumes: prometheus-data: diff --git a/src/main.rs b/src/main.rs index b49d630..fa69be4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,6 @@ struct Args { #[arg(long, default_value = "127.0.0.1")] host: String, - // TODO: Pick a different port later /// Port to bind the server to. #[arg(short, long, default_value_t = 9999)] port: u16, @@ -116,7 +115,7 @@ op_document_count_per_vault{vault="36vhq4xz3r6hnemzadk33evi4a"} 1 op_document_count_total 1 # HELP op_exporter_buildinfo Build information of this exporter. # TYPE op_exporter_buildinfo gauge -op_exporter_buildinfo{version="0.1.0"} 1 +op_exporter_buildinfo{version="0.2.0"} 1 # HELP op_group_count_total Total number of groups. # TYPE op_group_count_total gauge op_group_count_total 4 diff --git a/src/metrics_collector/build_info.rs b/src/metrics_collector/build_info.rs index 8134e16..7be37dc 100644 --- a/src/metrics_collector/build_info.rs +++ b/src/metrics_collector/build_info.rs @@ -36,7 +36,7 @@ mod tests { // Assert assert_eq!( OP_EXPORTER_BUILDINFO - .get_metric_with_label_values(&["0.1.0"])? + .get_metric_with_label_values(&["0.2.0"])? .get(), 1 );