Pushing Metrics

The push endpoint, payload format and integration patterns.

The push endpoint

POST https://api.shxrk.systems/api/v1/uptime/api-monitoring/push
Authorization: Bearer <push_key>
Content-Type: application/json

The push key is created with the monitor and shown in its settings. Rotate it any time with POST /api-monitoring/monitors/:id/regenerate-key.

Payload

{
  "endpoint": "/api/checkout",
  "method": "POST",
  "status_code": 200,
  "latency_ms": 42,
  "is_error": false,
  "metrics": {
    "queue_depth": 17,
    "db_ms": 12
  }
}
Field Type Description
endpoint string Logical endpoint name — groups metrics in the UI
method string HTTP method
status_code int Response status code
latency_ms int Measured latency in milliseconds
is_error bool Explicit error flag (status-code-independent)
metrics object Arbitrary custom metrics — graphed via widgets

Every accepted push also records a successful check on the monitor, resetting its staleness timer.

Integration patterns

Middleware — the common case: wrap your HTTP framework's middleware to time every request and push asynchronously. Batching every few seconds keeps overhead near zero.

Node.js (Express) — fire-and-forget push per request:

const PUSH_URL = 'https://api.shxrk.systems/api/v1/uptime/api-monitoring/push';
const PUSH_KEY = process.env.SHXRK_PUSH_KEY;

app.use((req, res, next) => {
  const start = process.hrtime.bigint();
  res.on('finish', () => {
    const latency_ms = Number(process.hrtime.bigint() - start) / 1e6;
    fetch(PUSH_URL, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${PUSH_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        endpoint: req.route?.path || req.path,
        method: req.method,
        status_code: res.statusCode,
        latency_ms: Math.round(latency_ms),
        is_error: res.statusCode >= 500,
      }),
    }).catch(() => {});
  });
  next();
});

Go — same pattern as middleware:

func PushMetrics(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()
		rec := &statusRecorder{ResponseWriter: w, status: 200}
		next.ServeHTTP(rec, r)
		go func() {
			payload, _ := json.Marshal(map[string]any{
				"endpoint":    r.URL.Path,
				"method":      r.Method,
				"status_code": rec.status,
				"latency_ms":  time.Since(start).Milliseconds(),
				"is_error":    rec.status >= 500,
			})
			req, _ := http.NewRequest("POST", "https://api.shxrk.systems/api/v1/uptime/api-monitoring/push", bytes.NewReader(payload))
			req.Header.Set("Authorization", "Bearer "+os.Getenv("SHXRK_PUSH_KEY"))
			req.Header.Set("Content-Type", "application/json")
			http.DefaultClient.Do(req)
		}()
	})
}

Cron/sidecar — a separate process sampling your API's health endpoint and pushing the result.

Synthetic client — a script calling your real endpoints from inside your VPC, pushing the observed latency. This measures true internal behavior, not the internet path our checkers see.

Errors

401 invalid or missing push key, 400 malformed JSON, 500 storage failure (safe to retry).