Skip to content

johejo/prometheus-tailscalesd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prometheus-tailscalesd

Description

Prometheus HTTP Service Discovery using tailscale localapi or publicapi

You can flexibly translate api response to http_sd using jq expressions powered by gojq.

Install

go install github.com/johejo/prometheus-tailscalesd@latest

Usage

Usage of prometheus-tailscalesd:
  -address string
        listen address (default ":9924")
  -config string
        config file (default "config.yaml")
  -enable-compression
        enable response compression (default true)
  -expose-metadata
        expose metadata on self metrics endpoint (default true)
  -log-level string
        logging level: debug, info, warn, error (default "info")
  -tailscaled-socket string
        unix socket path of tailscaled (default "/var/run/tailscale/tailscaled.sock")

Configuration

A module consists of three jq expressions: filter, targets, and labels.

You can filter for specific devices, build targets with specific port or assign any labels.

See also

Example localapi configuration

modules:
  node-exporter:
    path: /node-exporter # http path for this module
    source: localapi
    filter: | # filter devices
      select(.OS == "linux")
    targets: | # build targets: must be an array
      [(.DNSName | split(".")[0]) + ":9100"]
    labels: | # build labels: must be a object
      {
        "__meta_tailscale_device_id": .ID,
        "__meta_tailscale_device_dns_name": .DNSName | rtrimstr("."),
        "__meta_tailscale_device_ipv4": .TailscaleIPs[0],
      }
prometheus-tailscalesd -config config.yaml

A model showing how to translate localapi response to HTTP SD

[
	[.Peer | to_entries[].value] +
	[.Self] |
	.[] | 
	<filter> |
	{
		targets: <targets>,
		labels: <labels>,
	}
]

See also

Example publicapi configuration

modules:
  node-exporter:
    path: /node-exporter # http path for this module
    source: publicapi
    oauthClientIDEnv: TAILSCALE_OAUTH_CLIENT_ID # env var name for oauth client id
    oauthClientSecretEnv: TAILSCALE_OAUTH_CLIENT_SECRET # env var name for oauth client secret
    filter: | # filter devices
      select(.os == "linux")
    targets: | # build targets: must be an array
      [(.name | split(".")[0]) + ":9100"]
    labels: | # build labels: must be a object
      {
        "__meta_tailscale_device_id": .nodeId,
        "__meta_tailscale_device_dns_name": .name,
        "__meta_tailscale_device_ipv4": .addresses[0][0],
      }
TAILSCALE_OAUTH_CLIENT_ID="xxx" TAILSCALE_OAUTH_CLIENT_SECRET="yyy" prometheus-tailscalesd -config config.yaml

A model showing how to translate publicapi response to HTTP SD

[
	.devices[] |
	<filter> |
	{
		targets: <targets>,
		labels: <labels>,
	}
]

See also

Author

Mitsuo HEIJO

License

Apache License 2.0

About

Prometheus HTTP Service Discovery for Tailscale

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages