Skip to content

Add multiple output formats to nchan_stub_status directive#710

Open
lloydzhou wants to merge 1 commit intoslact:masterfrom
lloydzhou:master
Open

Add multiple output formats to nchan_stub_status directive#710
lloydzhou wants to merge 1 commit intoslact:masterfrom
lloydzhou:master

Conversation

@lloydzhou
Copy link

Summary

Extend nchan_stub_status directive to support multiple output formats: plain text, JSON, HTML, and Prometheus metrics. related #381 (comment)

Changes

  • Directive Enhancement: nchan_stub_status now accepts an optional format argument (plain, json, html, prometheus)
  • New Files: src/util/nchan_stub_status_formats.h and src/util/nchan_stub_status_formats.c
  • Modified Files:
    • src/nchan_types.h - Added stub_status_format configuration field
    • src/nchan_commands.rb - Updated directive to accept 0..1 arguments
    • src/nchan_setup.c - Added format parsing logic
    • src/nchan_module.c - Refactored handler to dispatch based on format
    • config - Added new source file to build

Output Formats

Plain Text (default, backward compatible)

total published messages: 0
shared memory used: 16K
...

JSON (formatted with nested structure)

{
  "interprocess": {
    "alerts": {
      "sent": 0,
      "received": 0,
      "in_transit": 0
    },
    ...
  },
  "version": "1.3.7"
}

HTML (styled table)

<!DOCTYPE html>
<html>
<head><title>Nchan Status</title>
<style>table{border-collapse:collapse}...</style>
</head>
<body>
<h1>Nchan Status</h1>
<table>
  <tr><th>Metric</th><th>Value</th></tr>
  <tr><td>Total Published Messages</td><td>0</td></tr>
  ...
</table>
</body>
</html>

Prometheus Metrics

nchan_published_messages_total 0
nchan_shared_memory_used_kb 16
...

Configuration Example

location = /nchan_status {
    nchan_stub_status;  # plain text
}

location = /nchan_status.json {
    nchan_stub_status json;
}

location = /nchan_status.html {
    nchan_stub_status html;
}

location = /metrics {
    nchan_stub_status prometheus;
}

Backward Compatibility

Fully backward compatible - omitting the format argument defaults to plain text format.

  Extend the nchan_stub_status directive to support four output formats:
  - plain (default): original text format
  - json: formatted JSON with nested structure
  - html: HTML table with styling
  - prometheus: Prometheus metrics format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments