| 
									
										
										
										
											2019-02-21 16:32:46 +01:00
										 |  |  | import ./make-test.nix { | 
					
						
							|  |  |  |   name = "prometheus-2"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   nodes = { | 
					
						
							|  |  |  |     one = { pkgs, ... }: { | 
					
						
							| 
									
										
										
										
											2019-04-15 23:46:25 +02:00
										 |  |  |       environment.systemPackages = [ pkgs.jq ]; | 
					
						
							| 
									
										
										
										
											2019-02-21 16:32:46 +01:00
										 |  |  |       services.prometheus2 = { | 
					
						
							|  |  |  |         enable = true; | 
					
						
							| 
									
										
										
										
											2019-04-15 23:46:25 +02:00
										 |  |  |         scrapeConfigs = [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             job_name = "prometheus"; | 
					
						
							|  |  |  |             static_configs = [ | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 targets = [ "127.0.0.1:9090" ]; | 
					
						
							|  |  |  |                 labels = { instance = "localhost"; }; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             job_name = "pushgateway"; | 
					
						
							|  |  |  |             scrape_interval = "1s"; | 
					
						
							|  |  |  |             static_configs = [ | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 targets = [ "127.0.0.1:9091" ]; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2019-02-21 16:32:46 +01:00
										 |  |  |         rules = [ | 
					
						
							|  |  |  |           ''
 | 
					
						
							|  |  |  |             groups: | 
					
						
							|  |  |  |               - name: test | 
					
						
							|  |  |  |                 rules: | 
					
						
							|  |  |  |                   - record: testrule | 
					
						
							|  |  |  |                     expr: count(up{job="prometheus"}) | 
					
						
							|  |  |  |           ''
 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2019-04-15 23:46:25 +02:00
										 |  |  |       services.prometheus.pushgateway = { | 
					
						
							|  |  |  |         enable = true; | 
					
						
							|  |  |  |         persistMetrics = true; | 
					
						
							|  |  |  |         persistence.interval = "1s"; | 
					
						
							|  |  |  |         stateDir = "prometheus-pushgateway"; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2019-02-21 16:32:46 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = ''
 | 
					
						
							|  |  |  |     startAll; | 
					
						
							|  |  |  |     $one->waitForUnit("prometheus2.service"); | 
					
						
							|  |  |  |     $one->waitForOpenPort(9090); | 
					
						
							|  |  |  |     $one->succeed("curl -s http://127.0.0.1:9090/metrics"); | 
					
						
							| 
									
										
										
										
											2019-04-15 23:46:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Let's test if pushing a metric to the pushgateway succeeds | 
					
						
							|  |  |  |     # and whether that metric gets ingested by prometheus. | 
					
						
							|  |  |  |     $one->waitForUnit("pushgateway.service"); | 
					
						
							|  |  |  |     $one->succeed( | 
					
						
							|  |  |  |       "echo 'some_metric 3.14' | " . | 
					
						
							|  |  |  |       "curl --data-binary \@- http://127.0.0.1:9091/metrics/job/some_job"); | 
					
						
							|  |  |  |     $one->waitUntilSucceeds( | 
					
						
							|  |  |  |       "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=some_metric' " . | 
					
						
							|  |  |  |       "| jq '.data.result[0].value[1]' | grep '\"3.14\"'"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Let's test if the pushgateway persists metrics to the configured location. | 
					
						
							|  |  |  |     $one->waitUntilSucceeds("test -e /var/lib/prometheus-pushgateway/metrics"); | 
					
						
							| 
									
										
										
										
											2019-02-21 16:32:46 +01:00
										 |  |  |   '';
 | 
					
						
							|  |  |  | } |