Skip to content

Instantly share code, notes, and snippets.

@dfang
Last active May 22, 2019 08:07
Show Gist options
  • Save dfang/e91eec834e995a9a9b72e1f95b3ae113 to your computer and use it in GitHub Desktop.
Save dfang/e91eec834e995a9a9b72e1f95b3ae113 to your computer and use it in GitHub Desktop.
Enable brew service support for prometheus
```
def plist; <<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/prometheus</string>
<string>--config.file</string>
<string>#{etc}/prometheus.yml</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/prometheus.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/prometheus.log</string>
</dict>
</plist>
EOS
end
```
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>homebrew.mxcl.prometheus</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/prometheus/bin/prometheus</string>
<string>--config.file</string>
<string>/usr/local/etc/prometheus.yml</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local/var</string>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/prometheus.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/prometheus.log</string>
</dict>
</plist>
```
```
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
```
@dfang
Copy link
Author

dfang commented Aug 3, 2018

How to use ?

brew edit prometheus
copy  formula extension method to it
brew reinstall prometheus

```brew services start/restart prometheus``` will create  ~/Library/LaunchAgents/homebrew.mxcl.prometheus.plist, so don't need to copy it

touch /usr/local/etc/prometheus.yml
copy the content of prometheus.yml to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment