grafana配置文件

猪小花1号2018-11-25 11:29

此文已由作者赵计刚薪授权网易云社区发布。

欢迎访问网易云社区,了解更多网易技术产品运营经验。


一、配置文件位置

  • /usr/local/opt/grafana/share/grafana/default.ini
  • /usr/local/etc/grafana/grafana.ini

 

二、init格式

1、注释:

  • 以";"开头,不管多长或多短,独占一行

 

三、配置文件调用顺序

1、grafana启动时,首先会调用/usr/local/opt/grafana/share/grafana/default.ini(定义了默认的启动信息)

2、之后会调用我们写的--config所指向的配置文件(默认为/usr/local/etc/grafana/grafana.ini),所以通过该文件我们可以覆盖default.ini的配置。

 

四、完整文件及注释

  1 ##################### Grafana Configuration Example #####################
  2 # use "--config" to specified via command line
  3 # Everything has defaults so you only need to uncomment(解开注释,去掉";") things you want to
  4 # change
  5 
  6 # possible values : production, development
  7 app_mode = production
  8 
  9 # grafana-server instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty
 10 # Used in logging and internal metrics and in clustering info
 11 # use "echo ${HOSTNAME}" to view ${HOSTNAME} name
 12 instance_name = ${HOSTNAME}
 13 
 14 #################################### Paths ####################################
 15 [paths]
 16 # Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
 17 # use "cfg:default.paths.data" to specified via command line
 18 data = /usr/local/var/lib/grafana
 19 #
 20 # Directory where grafana can store logs
 21 # use "cfg:default.paths.logs" to specified via command line
 22 logs = /usr/local/var/log/grafana
 23 #
 24 # Directory where grafana will automatically scan and look for plugins
 25 # use "cfg:default.paths.plugins" to specified via command line
 26 plugins = /usr/local/var/lib/grafana/plugins
 27 
 28 #################################### Server ####################################
 29 [server]
 30 # Protocol (http or https)
 31 protocol = http
 32 
 33 The ip address to bind to, empty will bind to all interfaces
 34 http_addr = 192.168.20.237
 35 
 36 # The http port  to use, defaults to 3000
 37 http_port = 3000
 38 
 39 # The public facing domain name used to access grafana from a browser
 40 domain = mygrafana
 41 
 42 # Redirect to correct domain if host header does not match domain
 43 # Prevents DNS rebinding attacks
 44 ;enforce_domain = false
 45 
 46 # The full public facing url
 47 root_url = %(protocol)s://%(domain)s:%(http_port)s/
 48 
 49 # Log web requests
 50 ;router_logging = false
 51 
 52 # the path relative working path(The path to the directory where the front end files (HTML, JS, and CSS files))
 53 static_root_path = public
 54 
 55 # enable gzip
 56 ;enable_gzip = false
 57 
 58 # https certs & key file(if protocol is set to https)
 59 ;cert_file =
 60 ;cert_key =
 61 
 62 #################################### Database ####################################
 63 [database]
 64 # Grafana needs a database to store users and dashboards (and other things)
 65 # Either "mysql", "postgres" or "sqlite3"(default), it's your choice
 66 ;type = sqlite3
 67 # host : Only applicable to MySQL or Postgres. Includes IP or hostname and port
 68 ;host = 127.0.0.1:3306
 69 # The name of the Grafana database
 70 ;name = grafana
 71 ;user = root
 72 ;password =
 73 
 74 # For "postgres" only, either "disable", "require" or "verify-full"
 75 ;ssl_mode = disable
 76 
 77 # For "sqlite3" only, path relative to data_path setting
 78 ;path = grafana.db
 79 
 80 #################################### Session ####################################
 81 [session]
 82 # Either "memory", "file", "redis", "mysql", "postgres", default is "file"
 83 provider = file
 84 
 85 # Provider config options
 86 # memory: not have any config yet
 87 # file: session dir path, is relative to grafana data_path
 88 # redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=grafana`
 89 # mysql: go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1:3306)/database_name`
 90 # postgres: user=a password=b host=localhost port=5432 dbname=c sslmode=disable
 91 ;provider_config = sessions
 92 
 93 # Session cookie name
 94 cookie_name = grafana_sess
 95 
 96 # If you use session in https only, default is false
 97 ;cookie_secure = false
 98 
 99 # Session life time, default is 86400(in seconds,24h)
100 session_life_time = 86400
101 
102 #################################### Analytics ####################################
103 [analytics]
104 # Server reporting, sends usage counters to stats.grafana.org every 24 hours.
105 # No ip addresses are being tracked, only simple counters to track
106 # running instances, dashboard and error counts. It is very helpful to us.
107 # Change this option to false to disable reporting.
108 reporting_enabled = true
109 
110 # Set to false to disable all checks to https://grafana.net
111 # for new vesions (grafana itself and plugins), check is used
112 # in some UI views to notify that grafana or plugin update exists
113 # This option does not cause any auto updates, nor send any information
114 # only a GET request to http://grafana.net to get latest versions
115 check_for_updates = true
116 
117 # Google Analytics universal tracking code, only enabled if you specify an id here
118 ;google_analytics_ua_id =
119 
120 #################################### Security ####################################
121 [security]
122 # default admin user, created on startup
123 ;admin_user = admin
124 admin_user = zhaojigang
125 
126 # default admin password, can be changed before first start of grafana,  or in profile settings
127 ;admin_password = admin
128 admin_password = zhaojigang
129 
130 # used for signing(Used for signing keep me logged in / remember me cookies)
131 ;secret_key = SW2YcwTIb9zpOOhoPsMm
132 
133 # Auto-login remember days(The number of days the keep me logged in / remember me cookie lasts)
134 login_remember_days = 7
135 ;cookie_username = grafana_user
136 ;cookie_remember_name = grafana_remember
137 
138 # disable gravatar profile images
139 ;disable_gravatar = false
140 
141 # data source proxy whitelist (ip_or_domain:port separated by spaces)
142 ;data_source_proxy_whitelist =
143 
144 [snapshots]
145 # snapshot sharing options
146 ;external_enabled = true
147 ;external_snapshot_url = https://snapshots-origin.raintank.io
148 ;external_snapshot_name = Publish to snapshot.raintank.io
149 
150 #################################### Users ####################################
151 [users]
152 # disable user signup / registration(Set to false to prohibit users from being able to sign up / create user accounts. Defaults to true. The admin user 
153 # can still create users from the Grafana Admin Pages)
154 allow_sign_up = true
155 
156 # Allow non admin users to create organizations(Set to false to prohibit users from creating new organizations)
157 ;allow_org_create = true
158 
159 # Set to true to automatically assign new users to the default organization (id 1)
160 ;auto_assign_org = true
161 
162 # Default role new users will be automatically assigned (if disabled above is set to true)
163 # other valid options are Admin and Editor and Read-Only Editor
164 auto_assign_org_role = Viewer
165 
166 # Background text for the user field on the login page
167 ;login_hint = email or username
168 
169 # Default UI theme ("dark" or "light")
170 ;default_theme = dark
171 
172 #################################### Anonymous Auth ##########################
173 [auth.anonymous]
174 # enable anonymous access
175 ;enabled = false
176 
177 # specify organization name that should be used for anonymous users
178 ;org_name = Main Org.
179 
180 # Specify role for anonymous users. Defaults to Viewer, other valid options are Editor and Admin
181 ;org_role = Viewer
182 
183 #################################### Github Auth ##########################
184 [auth.github]
185 ;enabled = false
186 ;allow_sign_up = false
187 ;client_id = some_id
188 ;client_secret = some_secret
189 ;scopes = user:email,read:org
190 ;auth_url = https://github.com/login/oauth/authorize
191 ;token_url = https://github.com/login/oauth/access_token
192 ;api_url = https://api.github.com/user
193 ;team_ids =
194 ;allowed_organizations =
195 
196 #################################### Google Auth ##########################
197 [auth.google]
198 ;enabled = false
199 ;allow_sign_up = false
200 ;client_id = some_client_id
201 ;client_secret = some_client_secret
202 ;scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
203 ;auth_url = https://accounts.google.com/o/oauth2/auth
204 ;token_url = https://accounts.google.com/o/oauth2/token
205 ;api_url = https://www.googleapis.com/oauth2/v1/userinfo
206 ;allowed_domains =
207 
208 #################################### Auth Proxy ##########################
209 [auth.proxy]
210 ;enabled = false
211 ;header_name = X-WEBAUTH-USER
212 ;header_property = username
213 ;auto_sign_up = true
214 
215 #################################### Basic Auth ##########################
216 [auth.basic]
217 ;enabled = true
218 
219 #################################### Auth LDAP ##########################
220 [auth.ldap]
221 ;enabled = false
222 ;config_file = /etc/grafana/ldap.toml
223 
224 #################################### SMTP / Emailing ##########################
225 [smtp]
226 ;enabled = false
227 ;host = localhost:25
228 ;user =
229 ;password =
230 ;cert_file =
231 ;key_file =
232 ;skip_verify = false
233 ;from_address = admin@grafana.localhost
234 
235 [emails]
236 ;welcome_email_on_sign_up = false
237 
238 #################################### Logging ##########################
239 [log]
240 # Either "console", "file", "syslog". Default is console and  file
241 # Use space to separate multiple modes, e.g. "console file"
242 ;mode = console, file
243 
244 # Either "trace", "debug", "info", "warn", "error", "critical", default is "info"
245 ;level = info
246 
247 # For "console" mode only
248 [log.console]
249 ;level =
250 
251 # log line format, valid options are text, console and json
252 ;format = console
253 
254 # For "file" mode only
255 [log.file]
256 ;level =
257 
258 # log line format, valid options are text, console and json
259 ;format = text
260 
261 # This enables automated log rotate(switch of following options), default is true
262 ;log_rotate = true
263 
264 # Max line number of single file, default is 1000000
265 ;max_lines = 1000000
266 
267 # Max size shift of single file, default is 28 means 1 << 28, 256MB
268 ;max_size_shift = 28
269 
270 # Segment log daily, default is true
271 ;daily_rotate = true
272 
273 # Expired days of log file(delete after max days), default is 7
274 ;max_days = 7
275 
276 [log.syslog]
277 ;level =
278 
279 # log line format, valid options are text, console and json
280 ;format = text
281 
282 # Syslog network type and address. This can be udp, tcp, or unix. If left blank, the default unix endpoints will be used.
283 ;network =
284 ;address =
285 
286 # Syslog facility. user, daemon and local0 through local7 are valid.
287 ;facility =
288 
289 # Syslog tag. By default, the process' argv[0] is used.
290 ;tag =
291 
292 
293 #################################### AMQP Event Publisher ##########################
294 [event_publisher]
295 ;enabled = false
296 ;rabbitmq_url = amqp://localhost/
297 ;exchange = grafana_events
298 
299 ;#################################### Dashboard JSON files ##########################
300 [dashboards.json]
301 ;enabled = false
302 ;path = /var/lib/grafana/dashboards
303 
304 #################################### Internal Grafana Metrics ##########################
305 # Metrics available at HTTP API Url /api/metrics
306 [metrics]
307 # Disable / Enable internal metrics
308 enabled           = true
309 
310 # Publish interval(Flush/Write interval when sending metrics to external TSDB.)
311 ;interval_seconds  = 10
312 
313 # Include this section if you want to send internal Grafana metrics to Graphite
314 ; [metrics.graphite]
315 ; address = localhost:2003
316 ; prefix = prod.grafana.%(instance_name)s.
317 
318 #################################### Internal Grafana Metrics ##########################
319 # Url used to to import dashboards directly from Grafana.net
320 [grafana_net]
321 url = https://grafana.net

注意:grafana的管理员只是在第一次启动时设置一次,之后无法再进行设置 。

所以,上边的admin_user=zhaojigang admin_password=zhaojigang如果不是第一次启动之前设置的,那么就是不起作用的

https://github.com/grafana/grafana/issues/6156

或者:参考:https://my.oschina.net/guol/blog/515126


免费体验云安全(易盾)内容安全、验证码等服务

更多网易技术、产品、运营经验分享请点击