// Collect implements the prometheus.Collector interface.This method may be called concurrently and must therefore be // implemented in a concurrency safe way func(p PidCollector)Collect(ch chan<- prometheus.Metric) { p.mutex.Lock() defer p.mutex.Unlock() host,_:= host.Info() ch <- prometheus.MustNewConstMetric( p.pidDesc, prometheus.GaugeValue, float64(os.Getpid()), host.Hostname, ) }
prometheus配置
1 2 3 4 5 6 7 8
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. # metrics_path defaults to '/metrics' # scheme defaults to 'http'. -job_name:'pid collector' static_configs: -targets: -localhost:8080