Skip to content

Monitoring

This page explains how to check that BastionXP is healthy, and how to collect its numbers in Prometheus. It is for people who run BastionXP themselves. If you use the BastionXP cloud service, BastionXP monitors it for you.

BastionXP gives you four ways to see what it is doing:

What What it tells you Where to read it
The health check Whether this server can do its work right now. https://<domain>/health
The metrics How many certificates BastionXP issued, and how many requests it refused. A Prometheus endpoint that you turn on
The log How the server is doing, and why something failed. journalctl -u bastionxp
The audit log Who did what. The portal's Activity page, and syslog

The health check

BastionXP answers requests to /health on its HTTPS port. The address needs no sign-in. It is made for load balancers and for monitoring tools.

curl https://ca.example.com/health

When the server is healthy, the answer is 200 with this body:

{"status":"ok"}

BastionXP is healthy when it can reach its database, and, if you configured Redis, Redis. When it cannot, the answer is 503, and the body says what is not reachable:

{"status":"unavailable","unavailable":"database"}

The value of unavailable is database or redis. The answer never contains the error message, because the address is public and an error message could name hosts or users. The reason is in the log.

Use /health for:

  • the health check of your load balancer, so that it stops sending requests to a server that cannot reach its database. See High availability,
  • an uptime monitor, and
  • the readiness check of a container platform.

The metrics

BastionXP can publish its metrics in the format that Prometheus reads. The metrics are off until you turn them on. They are on a port of their own, so that you can keep it private. Only numbers are in the metrics. They never contain names, serial numbers or user names.

Turn on the metrics

Add a metrics section to the configuration file, and restart BastionXP:

metrics:
  address: 127.0.0.1:9100
  token_file: /etc/bastionxp/metrics.token
Setting What it means
address The address and the port where BastionXP serves the metrics, as host:port. Use 127.0.0.1 if Prometheus runs on the same machine. The port must not be the server's own HTTPS port or HTTP port.
token_file The path of a file that holds a secret token. Prometheus must send it, as a bearer token. This is optional. We recommend it, unless only this machine can reach the address.

Create the token file with a long random token, and make it readable only by its owner:

openssl rand -hex 32 | sudo tee /etc/bastionxp/metrics.token > /dev/null
sudo chmod 600 /etc/bastionxp/metrics.token

The token file must not be empty. If it is, BastionXP does not start, because it would turn off the protection without saying so.

When BastionXP starts, it writes a line to the log that confirms the address:

level=INFO msg="metrics served" url=http://127.0.0.1:9100/metrics token_required=true

Check it:

curl -H "Authorization: Bearer $(sudo cat /etc/bastionxp/metrics.token)" http://127.0.0.1:9100/metrics

Without the token, the answer is 401 unauthorized.

Collect them with Prometheus

Add a job to your Prometheus configuration:

scrape_configs:
  - job_name: bastionxp
    metrics_path: /metrics
    authorization:
      type: Bearer
      credentials_file: /etc/prometheus/bastionxp.token
    static_configs:
      - targets: ["ca.example.com:9100"]

The file /etc/prometheus/bastionxp.token holds the same token as BastionXP's token file. The metrics are served over plain HTTP. If Prometheus is on another machine, keep the traffic on a private network.

The metrics

Metric Type Labels What it counts
bastionxp_certificates_issued_total counter authority, kind, protocol The certificates issued since BastionXP started. kind is the kind of certificate, for example a server or a client certificate. protocol is how the client asked: api for bxp-cli with a token or a login, acme, or scep.
bastionxp_requests_refused_total counter authority, reason The certificate requests that BastionXP refused, since it started.

The counters start at zero when BastionXP starts. Use the Prometheus functions rate() and increase(), which handle this for you.

The reason label says why a request was refused:

Reason What it means
bad_request The request was not acceptable, for example a certificate request that is wrong.
not_allowed The request asked for a name that the verifier's name policy does not allow.
already_used A one-time token or another one-time credential was used before.
unavailable The authority cannot sign now, for example because it is being deleted.
audit_unavailable BastionXP could not write the audit event, so it did not issue the certificate. See Audit logging.
internal Signing or saving the certificate failed inside BastionXP. Look in the log.

Alerts to consider

Alert An example condition
The server is not healthy The /health check fails for more than a minute.
Requests fail inside BastionXP increase(bastionxp_requests_refused_total{reason="internal"}[15m]) > 0, and the same for the reason audit_unavailable. Look at the log and at the database.
A burst of refused requests increase(bastionxp_requests_refused_total[15m]) is much higher than normal. It can be a client in a loop, or an attack.
No certificates for a long time increase(bastionxp_certificates_issued_total[24h]) == 0 on a system that normally issues certificates every day.

The expiry of your CAs is not a metric. BastionXP warns you about it in the audit log, as events of the type ca_expiring. Send the audit log to your SIEM, and alert on them.

The log

BastionXP writes its log to its standard error output. When it runs as a systemd service, read it with:

sudo journalctl -u bastionxp -f

Set the format to json to send it to a log collector. See The log.

The log tells you how the server is doing: when it started, which authorities it loaded, and why something failed. Watch it for the levels WARN and ERROR.

The audit log

The audit log is a different record. It tells you who did what, for example who revoked a certificate. Keep it for your compliance needs, and send it to your SIEM. See Audit logging.