Skip to content

Commit

Permalink
enable node-export and cadvistor
Browse files Browse the repository at this point in the history
  • Loading branch information
yunlzheng committed May 9, 2017
1 parent 7e319c0 commit 5be2ad7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var cfg = struct {

func init() {
flag.StringVar(
&cfg.configFile, "config.file", "prometheus.yml",
&cfg.configFile, "config.file", "prometheus_pusher.yml",
"Prometheus configuration file name.",
)
}
Expand Down
26 changes: 3 additions & 23 deletions prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,17 @@ global:
evaluation_interval: 15s
external_labels:
monitor: 'exporter-metrics'

scrape_configs:

- job_name: 'HostsMetrics'
- job_name: 'push-metrics'
dns_sd_configs:
- names:
- node-exporter
- pushgateway
refresh_interval: 15s
type: A
port: 9100

- job_name: 'ContainerMetrics'
static_configs:
- targets:
- 'rancher-server:9108'
- job_name: 'RancherServerMetrics'
dns_sd_configs:
- names:
- cadvisor
refresh_interval: 15s
type: A
port: 8080

- job_name: 'RancherApi'
dns_sd_configs:
- names:
- 'prometheus-rancher-exporter'
refresh_interval: 15s
type: A
port: 9173

- job_name: 'Prometheus'
static_configs:
- targets:
Expand Down
36 changes: 36 additions & 0 deletions prometheus_pusher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: 'exporter-metrics'

scrape_configs:

- job_name: 'HostsMetrics'
dns_sd_configs:
- names:
- node-exporter
refresh_interval: 15s
type: A
port: 9100

- job_name: 'RancherServerMetrics'
dns_sd_configs:
- names:
- cadvisor
refresh_interval: 15s
type: A
port: 9120

#- job_name: 'RancherApi'
# dns_sd_configs:
# - names:
# - 'prometheus-rancher-exporter'
# refresh_interval: 15s
# type: A
# port: 9173
#
#- job_name: 'ContainerMetrics'
# static_configs:
# - targets:
# - 'rancher-server:9108'
10 changes: 3 additions & 7 deletions scrape/exporterscrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"io"
"bytes"
"strings"
"io/ioutil"
"os"
"io/ioutil"
)

var pushGateway string
Expand Down Expand Up @@ -86,10 +86,6 @@ var userAgentHeader = fmt.Sprintf("Prometheus/%s", version.Version)

func (endpoint *jobEndpoint) scrape(jobName string) error {

if jobName!="HostsMetrics" {
return nil
}

req, err := http.NewRequest("GET", endpoint.Endpoint, nil)
if err != nil {
return err
Expand Down Expand Up @@ -143,12 +139,12 @@ func (endpoint *jobEndpoint) scrape(jobName string) error {

for _, sample := range allSamples {
metric := fmt.Sprintf("%s %s\n", sample.Metric, sample.Value)
if !strings.Contains(metric, "go_") && !strings.Contains(metric, "http_") {
if strings.Contains(metric, "node_") || strings.Contains(metric, "container_") {
buffer.WriteString(metric)
}
}

url := fmt.Sprintf("%s/metrics/job/%s", pushGateway, jobName)
url := fmt.Sprintf("%s/metrics/job/%s/instance/%s", pushGateway, jobName, jobName)
fmt.Println("send data to pushgateway :" + url)

post, err := http.NewRequest("POST", url, strings.NewReader(buffer.String()))
Expand Down

0 comments on commit 5be2ad7

Please sign in to comment.