Skip to content

Session state

pmesh API exposes a set of endpoints that allow you to interact with the current session of the server. Session information includes the current git repository of the server, state of the HTTP server, and the current services.

Project Revision | /repo

Returns information about the current git repository of the server.

The result is an object with the following structure:

ResultTypeDescription
sysstringThe version control system.
ref.branchstringThe current branch.
ref.hashstringThe current commit hash.
ref.authorstringThe author of the current commit.
ref.messagestringThe message of the current commit.
remote.branchstringThe current branch of the remote.
remote.hashstringThe current commit hash of the remote.
remote.authorstringThe author of the current commit of the remote.
remote.messagestringThe message of the current commit of the remote.
urlstringThe URL of the repository.
Terminal window
$ curl http://pm3/repo?pretty
{
"sys": "git",
"ref": {
"branch": "main",
"hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"author": "can1357",
"message": "..."
},
"remote": {
"branch": "origin/main",
"hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"author": "can1357",
"message": "..."
},
"url": "[email protected]:pme-sh/pmesh-docs.git"
}

Revision update | /repo/update

ParameterTypeDescription
invalidatebooleanIf true, forces a rebuild of all services.

Updates the current revision of the server to the latest commit of the remote branch, and restarts all services accordingly.

The result is an object with the following structure:

ResultTypeDescription
from.branchstringThe previous branch.
from.hashstringThe previous commit hash.
from.authorstringThe author of the previous commit.
from.messagestringThe message of the previous commit.
to.branchstringThe new branch.
to.hashstringThe new commit hash.
to.authorstringThe author of the new commit.
to.messagestringThe message of the new commit.
Terminal window
$ curl http://pm3/repo/update
{
"from": {
"branch": "main",
"hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"author": "can1357",
"message": "..."
},
"to": {
"branch": "origin/main",
"hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"author": "can1357",
"message": "..."
}
}

Reload | /reload

ParameterTypeDescription
invalidatebooleanIf true, forces a rebuild of all services.

Reads the manifest from the file system and restarts all services accordingly.

Terminal window
$ curl http://pm3/reload
{}
$ curl -X POST http://pm3/reload -d '{"invalidate": true}'
{}

Service list | /service

Returns a list of services that are currently running mapped to their unique session IDs.

Terminal window
$ curl http://pm3/service?pretty
{
"my-api": "23829859410058122",
"assets": "23829859410058122",
}

Service restart | /service/restart/?:svc

ParameterTypeDescription
invalidatebooleanIf true, forces a rebuild of all services.

If a service name is provided, restarts the service with the given name. If no service name is provided, restarts all services.

The result is an object with the following structure:

ResultTypeDescription
countnumberThe number of services restarted.
Terminal window
$ curl http://pm3/service/restart/my-api
{ count: 1 }

Service stop | /service/stop/?:svc

If a service name is provided, stops the service with the given name. If no service name is provided, stops all services.

The result is an object with the following structure:

ResultTypeDescription
countnumberThe number of services stopped.
Terminal window
$ curl http://pm3/service/stop/my-api
{ count: 1 }

Health | /service/health/?:svc

If a service name is provided, returns the health of the service with the given name. If no service name is provided, returns the health of all services as an object with the service names as keys.

The result is an object with the following structure:

ResultTypeDescription
statusstringThe status of the service.
healthynumberThe number of healthy processes.
totalnumberThe total number of processes.
errstring?The error message if the service is unhealthy.
Terminal window
$ curl http://pm3/service/health/my-api?pretty
{
"status": "OK",
"healthy": 1,
"total": 1
}

Metrics | /service/metrics/?:svc

If a service name is provided, returns metrics about the service with the given name. If no service name is provided, returns metrics about all services as an object with the service names as keys.

The result is an object with the following structure:

ResultTypeDescription
idstringThe unique session ID of the service.
typestringThe type of the service.
serverobjectThe server information.
processesarrayThe process information.
statusstringThe status of the service.
healthynumberThe number of healthy processes.
totalnumberThe total number of processes.
errstring?The error message if the service is unhealthy.
Terminal window
$ curl http://pm3/service/metrics/my-api?pretty
{
"id": "24658195541820102",
"type": "app",
"server": {
"upstreams": [
{
"address": "127.1.0.2:70",
"healthy": true
}
]
},
"processes": [
{
"pid": 26792,
"create_time": "2024-03-09T02:02:52.662+01:00",
"cmd": "node app.js",
"cpu": 0.000052471819240181423,
"rss": 61931520,
"vms": 73318400,
"hwm": 61931520,
"io_read": 2315553,
"io_write": 112,
"tree": {
"26792": {
"pid": 26792,
"create_time": "2024-03-09T02:02:52.662+01:00",
"cmd": "node app.js",
"cpu": 0.000052471819240181423,
"rss": 61931520,
"vms": 73318400,
"hwm": 61931520,
"io_read": 2315553,
"io_write": 112
}
}
}
],
"status": "OK",
"healthy": 1,
"total": 1
}

Client sessions | /session

Returns information about the current client sessions.

The result is an object with the following structure:

ResultTypeDescription
num_clientsnumberThe number of clients.
sessions[ip].avg_rpsnumberThe average requests per second.
sessions[ip].num_reqsnumberThe number of requests.
sessions[ip].first_seenstringThe time the client was first seen.
sessions[ip].blocked_untilstringThe time the client is blocked until.
Terminal window
$ curl http://pm3/session?pretty
{
"num_clients": 68,
"sessions": {
"xx.xxx.xxx.xx": {
"avg_rps": 0.01168477551931604,
"num_reqs": 275,
"first_seen": "2024-03-08T20:21:43.418Z",
"blocked_until": "0001-01-01T00:00:00Z"
},
...
}
}