Skip to content

Latest commit

 

History

History
120 lines (77 loc) · 3.76 KB

File metadata and controls

120 lines (77 loc) · 3.76 KB

API

Plotix has one simple HTTP API. You push data to a topic with a request, and you read it back the same way. There are no accounts or API keys yet. A topic is just a name in the URL, and it gets created the first time you push to it.

Replace http://localhost:8080 below with your own server address.


Seeing your data in the app

Pushing data with curl doesn't show up on its own. The Plotix app doesn't come with any server added by default, so you have to point it at one first:

  1. Go to Settings and add your server under "Servers". This is just the address you'd type into your browser to open Plotix, for example http://localhost:8080, or https://plotix.example.com if you're behind a reverse proxy. Don't add a port or path on top of that unless you actually need one to reach the site.
  2. Go to Subscribe, pick that server, and enter the topic name you're pushing to.
  3. Go to Home to see the chart.

You only have to add the server once. After that, subscribing to a new topic on that server is just steps 2 and 3.


Push data

curl -d "60" http://localhost:8080/mytopic

You can push a plain number, or a JSON object if you want more than one value per point:

curl -d '{"cpu":60,"gpu":45}' http://localhost:8080/mytopic

Each field in the object becomes its own series on the chart. Returns 201 ok on success, or 400 if the value isn't a number or a plain object of numbers.


Read data

Get every point stored for a topic, newest first:

curl http://localhost:8080/mytopic
[{ "id": 12, "topic": "mytopic", "ts": 1735689600000, "fields": { "cpu": 60, "gpu": 45 } }]

Get just the latest point:

curl http://localhost:8080/mytopic/latest

Returns 404 no data if the topic has nothing in it yet.

Get the field names seen recently on a topic:

curl http://localhost:8080/mytopic/fields
["cpu", "gpu"]

Live updates

Subscribe to a topic and get new points pushed to you as they are stored:

curl http://localhost:8080/mytopic/stream

You'll get an event each time someone pushes to the topic:

event: point
data: {"id":13,"topic":"mytopic","ts":1735689601000,"fields":{"cpu":62,"gpu":48}}

A ping event is sent every 15 seconds to keep the connection open. This is what the Plotix home page itself uses to update charts live, so you don't need to poll.

Note: this only works against a single Plotix instance. If you run more than one instance behind a load balancer, a stream connected to instance A won't see pushes that land on instance B.


Topic settings

Each topic can have a description and a point limit. Read them:

curl http://localhost:8080/mytopic/meta

Set them:

curl -X PUT -d '{"description":"Server CPU usage","max_points":500}' http://localhost:8080/mytopic/meta

max_points controls how many points Plotix keeps for that topic before it starts dropping the oldest ones. Default is 1000.


Endpoint summary

Method Path What it does
POST /:topic Push a value or set of values
GET /:topic Get all points, newest first
GET /:topic/latest Get the latest point
GET /:topic/fields Get recent field names
GET /:topic/meta Get topic description and max points
PUT /:topic/meta Set topic description and max points
GET /:topic/stream Live stream of new points (SSE)

There's no auth on any of this. Anyone who can reach your server can push to and read any topic. Keep that in mind when you decide how to expose Plotix to the internet.