dotnet publish -c Release -r osx-x64 -p:PublishReadyToRun=true --self-contained true -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=truedotnet publish -c Release -r linux-x64 -p:PublishReadyToRun=true --self-contained true -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=truedotnet publish -c Release -r win-x64 -p:PublishReadyToRun=true --self-contained true -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=trueIf a different target is required, review https://docs.microsoft.com/en-us/dotnet/core/rid-catalog for a full listing.
Produces a single executable file TownSuite.Prometheus.FileSdConfigs.
Configure in appsettings.json file in the same folder as the executable.
appsettings.json example
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"AppSettings": {
"DelayInSeconds": 1800,
"UserAgent": "TownSuiteSD/1.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:107.0) Gecko/20100101 Firefox/107.0",
"OutputPath": "targets.json",
"OutputPathV2": "targets_v2.json",
"OutputPathPrometheusMetrics": "targets_prometheus_metrics.json",
"OutputPathOpenTelemetry": "targets_open_telemetry_metrics.json"
},
"Settings": [
{
"LookupUrl": "http host address and path or filepath",
"AuthHeader": "[If SrcPath is a url and auth this field should be set to basic auth or a bearer token]",
"AppendPaths": [
"/metrics",
"/api/status"
],
"Labels": {
"job": "test",
"env": "dev"
},
"IgnoreList": [
"https://example.townsuite.com"
]
}
],
"SettingsV2": [
{
"ServiceListUrl": "http host address and path or filepath that lists services",
"ServiceDiscoverUrl": "http host address and path or filepath to lookup details for specific services",
"AuthHeader": "[If SrcPath is a url and auth this field should be set to basic auth or a bearer token]",
"IgnoreList": [
"https://example.townsuite.com"
],
"LowercaseLabels": true
}
]
}Download the executable
- Copy it to a folder such as C:\promethues\TownSuite.Prometheus.FileSdConfigs
- Edit appsettings.json
- Use nssm to configure it as a windows service.
nssm install TownSuite.Prometheus.FileSdConfigs C:\prometheus\TownSuite.Prometheus.FileSdConfigs\TownSuite.Prometheus.FileSdConfigs.exe
nssm set TownSuite.Prometheus.FileSdConfigs AppDirectory C:\prometheus\TownSuite.Prometheus.FileSdConfigs
net start TownSuite.Prometheus.FileSdConfigsExtract the release and copy it to /opt/TownSuite.Prometheus.FileSdConfigs.
[Unit]
Description=The description of your service
# How to install:
# Copy YourProgramName binary to /opt/TownSuite.Prometheus.FileSdConfigs/TownSuite.Prometheus.FileSdConfigs
# Copy /etc/systemd/system/townsuite-prometheus-filesdconfigs.service
# systemctl enable townsuite-prometheus-filesdconfigs.service
# systemctl start townsuite-prometheus-filesdconfigs.service
[Service]
ExecStart=/opt/TownSuite.Prometheus.FileSdConfigs/TownSuite.Prometheus.FileSdConfigs
Restart=always
RestartSec=10 # Restart service after 10 seconds if node service crashes
StandardOutput=syslog # Output to syslog" >> /etc/systemd/system/your-program-service-name.service
StandardError=syslog # Output to syslog" >> /etc/systemd/system/your-program-service-name.service
SyslogIdentifier=TownSuite.Prometheus.FileSdConfigs
WorkingDirectory=/opt/TownSuite.Prometheus.FileSdConfigs/
[Install]
WantedBy=multi-user.target
This example configures the Prometheus metrics and rewrites both http and https and custom metric endpoints. Secondly it configures prometheus to do health checks via the blackbox exporter.
sudo apt install prometheus/etc/prometheus/prometheus.yml
- job_name: metrics_service_discovery
scheme: http
file_sd_configs:
- files:
- /opt/TownSuite.Prometheus.FileSdConfigs/targets_prometheus_metrics.json
scrape_interval: 60s
relabel_configs:
- source_labels: [__address__]
regex: '^(https?)://([^/]+)(/.*)?'
target_label: __scheme__
replacement: '${1}'
- source_labels: [__address__]
regex: '^(https?)://([^/]+)(/.*)?'
target_label: __address__
replacement: '${2}'
- source_labels: [__address__]
regex: '^(https?)://([^/]+)(/.*)?'
target_label: __metrics_path__
replacement: '${3}'
- source_labels: [__metrics_path__]
regex: '^$'
replacement: '/metrics'
target_label: __metrics_path__
# Health Checks via Blackbox Exporter
- job_name: health_checks_service_discovery
file_sd_configs:
- files:
- /opt/TownSuite.Prometheus.FileSdConfigs/targets_v2.json
scrape_interval: 60s
metrics_path: /probe
params:
module: [http_2xx]
scheme: http
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9115