@pulzr/perses-pulzr-datasource
v0.3.0
Published
Pulzr Net datasource for Perses: sensor readings, SQL, analytics, field changes and devices
Readme
Pulzr Net datasource for Perses
Sensor readings from Pulzr Net on Perses dashboards: the same data, aggregates and analytics the Pulzr console draws, in your own Perses.
| Plugin | Kind | What it does |
|---|---|---|
| PulzrDatasource | Datasource | Where Pulzr Net is, and how requests reach it |
| PulzrFieldQuery | TimeSeriesQuery | Decoded fields, bucketed and aggregated (mean, time-weighted mean, min, max, p95, rises, …), with an optional target band, display names, a scale, and device positions for a map |
| PulzrSqlQuery | TimeSeriesQuery | A read-only SQL SELECT over your readings, $from and $to set to the dashboard's range |
| PulzrMetricQuery | TimeSeriesQuery | Occupancy rate, turnover, dwell and sensors reporting over time; occupancy by weekday and hour as a grid in metadata.matrix; a parking sensor's figures (parking: occupied, stays, typical and longest stay) and categories (arrivalsByHour, stayLengths) as a series each, one point at the range's end. lookback (28d) reads that far back from the range's end, for a weekly pattern on a board showing a day; hours and weekdays are counted in the viewer's timezone |
| PulzrChangeAnnotation | Annotation | Marks every change of up to four fields, such as a recipe stage or a mode |
| PulzrDeviceVariable | Variable | The devices heard in the last 30 days, by name |
Every request is made as the API key or signed-in user behind it, with the same organization, application and retention limits as the Pulzr console.
Use it in Perses
In Pulzr Net, open API keys and create a key with Data: Read and Devices: Read, limited to the applications the dashboards should see.
Put the plugin archive (
PulzrDatasource-<version>.tar.gz, from this repository's releases) in a folder listed in the Perses server'splugin.archive_paths.Store the key as a Perses secret:
kind: GlobalSecret metadata: name: pulzr-api-key spec: authorization: type: Bearer credentials: pzk_…Add the datasource. The Perses server calls Pulzr Net and adds the key, so it never reaches a viewer's browser:
kind: GlobalDatasource metadata: name: pulzr spec: default: true plugin: kind: PulzrDatasource spec: proxy: kind: HTTPProxy spec: url: https://app.pulzr.net secret: pulzr-api-key allowedEndpoints: - { endpointPattern: /api/v1/data/query, method: POST } - { endpointPattern: /api/v1/data/analytics, method: POST } - { endpointPattern: /api/v1/data/devices, method: GET } - { endpointPattern: /api/v1/data/devices/live, method: GET } - { endpointPattern: /api/v1/data/fields, method: GET }
A panel query looks like this:
kind: TimeSeriesQuery
spec:
plugin:
kind: PulzrFieldQuery
spec:
field: temperature
aggregate: timeWeighted
interval: 15m
devices: $devicedevices is DevEUIs or a variable holding them; empty is every device. The schemas in schemas/ are the full specification of each plugin.
Embed it in a React app
The package also exports every plugin for apps that embed Perses directly, as the Pulzr console does:
npm install @pulzr/perses-pulzr-datasourceimport * as pulzr from '@pulzr/perses-pulzr-datasource';
const pluginLoader = dynamicImportPluginLoader([
{ resource: pulzr.getPluginModule(), importPlugin: async () => pulzr },
]);With directUrl the browser calls Pulzr Net itself, through the fetch from Perses's FetchProvider. Wrap the dashboard in a FetchProvider that adds your sign-in to each request.
Development
Node.js 24 or later, npm 11 or later, and percli.
npm install
npm test # unit tests
percli plugin test-schemas # CUE schema tests
percli plugin lint
npm run build # the npm package and module-federation bundle, in dist/
percli plugin build # the archive a Perses server installsReleasing
Set the new version in package.json and commit. Write the release notes
in notes.md, then tag with them as the tag's message and push it:
git tag -a v0.2.0 --cleanup=whitespace -F notes.md && git push origin v0.2.0The tag's message is the GitHub release's notes; with none, the workflow falls back to GitHub's generated notes, and fails if those are empty too.
The Release workflow tests and builds, publishes the package to npm with provenance, and attaches the Perses plugin archive and the npm tarball to a GitHub release.
License
Apache 2.0
