| 
									
										
										
										
											2014-07-28 03:37:01 -07:00
										 |  |  | // +build !notime
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package collector | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/golang/glog" | 
					
						
							|  |  |  | 	"github.com/prometheus/client_golang/prometheus" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type timeCollector struct { | 
					
						
							| 
									
										
										
										
											2015-05-20 11:04:49 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-11-24 18:00:17 -08:00
										 |  |  | 	metric prometheus.Counter | 
					
						
							| 
									
										
										
										
											2014-07-28 03:37:01 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func init() { | 
					
						
							|  |  |  | 	Factories["time"] = NewTimeCollector | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-20 11:04:49 -07:00
										 |  |  | // Takes a prometheus registry and returns a new Collector exposing
 | 
					
						
							| 
									
										
										
										
											2014-07-28 03:37:01 -07:00
										 |  |  | // the current system time in seconds since epoch.
 | 
					
						
							| 
									
										
										
										
											2015-05-20 11:04:49 -07:00
										 |  |  | func NewTimeCollector() (Collector, error) { | 
					
						
							| 
									
										
										
										
											2014-11-24 18:00:17 -08:00
										 |  |  | 	return &timeCollector{ | 
					
						
							| 
									
										
										
										
											2015-05-20 11:04:49 -07:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2014-11-24 18:00:17 -08:00
										 |  |  | 		metric: prometheus.NewCounter(prometheus.CounterOpts{ | 
					
						
							|  |  |  | 			Namespace: Namespace, | 
					
						
							|  |  |  | 			Name:      "time", | 
					
						
							|  |  |  | 			Help:      "System time in seconds since epoch (1970).", | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	}, nil | 
					
						
							| 
									
										
										
										
											2014-07-28 03:37:01 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-29 07:16:43 -07:00
										 |  |  | func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) { | 
					
						
							| 
									
										
										
										
											2014-07-28 03:37:01 -07:00
										 |  |  | 	now := time.Now() | 
					
						
							|  |  |  | 	glog.V(1).Infof("Set time: %f", now.Unix()) | 
					
						
							| 
									
										
										
										
											2014-11-24 18:00:17 -08:00
										 |  |  | 	c.metric.Set(float64(now.Unix())) | 
					
						
							|  |  |  | 	c.metric.Collect(ch) | 
					
						
							| 
									
										
										
										
											2014-10-29 07:16:43 -07:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2014-07-28 03:37:01 -07:00
										 |  |  | } |