2016-10-21 17:01:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								+++
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title = "Scripted Dashboards"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								keywords = ["grafana", "dashboard", "documentation", "scripted"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type = "docs"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[menu.docs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								parent = "dashboard_features"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								weight = 9
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								+++
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-10 15:55:42 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Scripted Dashboards
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								If you have lots of metric names that change (new servers etc) in a defined pattern it is irritating to constantly have to create new dashboards.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-13 20:12:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								With scripted dashboards you can dynamically create your dashboards using javascript. In the folder grafana install folder
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								under `public/dashboards/`  there is a file named `scripted.js` . This file contains an example of a scripted dashboard. You can access it by using the url:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`http://grafana_url/dashboard/script/scripted.js?rows=3&name=myName`  
						 
					
						
							
								
									
										
										
										
											2015-03-10 15:55:42 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-06-02 23:45:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								If you open scripted.js you can see how it reads url parameters from ARGS variable and then adds rows and panels.
							 
						 
					
						
							
								
									
										
										
										
											2015-03-10 15:55:42 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Example
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```javascript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var rows = 1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var seriesName = 'argName';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if(!_.isUndefined(ARGS.rows)) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  rows = parseInt(ARGS.rows, 10);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if(!_.isUndefined(ARGS.name)) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  seriesName = ARGS.name;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								for (var i = 0; i <  rows ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  dashboard.rows.push({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    title: 'Scripted Graph ' + i,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    height: '300px',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    panels: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        title: 'Events',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        type: 'graph',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        span: 12,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        fill: 1,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        linewidth: 2,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        targets: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            'target': "randomWalk('" + seriesName + "')"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          },
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            'target': "randomWalk('random walk2')"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								return dashboard;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## More examples
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-13 20:12:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can find more examples in `public/dashboards/`  directory of your grafana installation.