src/go/plugin/ibm.d/docgen/README.md
The docgen tool automatically generates metadata.yaml, config_schema.json, and README.md files from the sources of truth in your IBM.D framework module.
The tool extracts information from:
And generates:
go run github.com/netdata/netdata/go/plugins/plugin/ibm.d/docgen \
-module=mymodule \
-contexts=contexts/contexts.yaml \
-config=config.go \
-module-info=module.yaml
Add this to any Go file in your module:
//go:generate go run ../../docgen -module=mymodule -contexts=contexts/contexts.yaml -config=config.go -module-info=module.yaml
Then run:
go generate
Your standard framework contexts file:
System:
labels: []
contexts:
- name: CPU
context: mymodule.cpu_usage
family: cpu
title: CPU Usage
units: percentage
type: line
priority: 1000
dimensions:
- { name: usage, algo: absolute }
Database:
labels: [name, type]
contexts:
- name: Connections
context: mymodule.db_connections
family: databases
title: Database Connections
units: connections
type: line
priority: 2000
dimensions:
- { name: active, algo: absolute }
- { name: idle, algo: absolute }
Your module configuration struct:
type Config struct {
framework.Config `yaml:",inline" json:",inline"`
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint"`
Username string `yaml:"username,omitempty" json:"username"`
Password string `yaml:"password,omitempty" json:"password"`
CollectDatabases bool `yaml:"collect_databases" json:"collect_databases"`
MaxDatabases int `yaml:"max_databases,omitempty" json:"max_databases"`
}
The tool will automatically:
omitemptyModule-specific metadata:
name: mymodule
display_name: My Application Monitor
description: |
Monitors My Application metrics including performance,
connections, and resource utilization.
icon: myapp.svg
categories:
- data-collection.databases
- data-collection.apm
link: https://myapp.com/monitoring
keywords:
- database
- performance
- monitoring
If this file doesn't exist, the tool creates reasonable defaults.
Complete Netdata marketplace metadata including:
Valid JSON Schema for the Netdata web UI:
Comprehensive documentation with:
All generated files are 100% consistent with your code. No more:
When you change contexts.yaml or config.go:
go generateThe docgen tool is designed specifically for the IBM.D framework:
The tool includes smart defaults for common field names, but you can extend it:
// Add field descriptions based on patterns
descriptions := map[string]string{
"ConnectionString": "Database connection string in format server:port/database",
"QueryTimeout": "Maximum time to wait for query response in seconds",
"EnableSSL": "Use SSL/TLS encryption for connections",
}
Use standard Netdata categories in module.yaml:
categories:
- data-collection.databases # Database systems
- data-collection.apm # Application Performance Monitoring
- data-collection.web-servers # Web servers
- data-collection.message-brokers # Message queues
- data-collection.generic # Generic/other
The tool handles various Go types:
string → "string"int, int64 → "integer"bool → "boolean"time.Duration → "integer" (with seconds constraint)"string" (fallback)Always maintain module.yaml with:
Field names like QueryTimeout generate better documentation than QTO.
The tool can extract examples from field comments or provide defaults.
Add go generate to your development workflow:
# After modifying contexts.yaml or config.go
go generate
git add metadata.yaml config_schema.json README.md
The tool generates good defaults, but always review:
jq . config_schema.jsonReview any existing production module (for example modules/mq/) for a complete integration:
modules/mq/
├── contexts/contexts.yaml # Metric definitions
├── config.go # Configuration struct
├── module.yaml # Module metadata
├── generate.go # go:generate directive
├── metadata.yaml # Generated ✓
├── config_schema.json # Generated ✓
└── README.md # Generated ✓
Run go generate in the module directory to see it in action.