Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json.Unmarshal failed #75

Closed
Lvzhenqian opened this issue May 21, 2019 · 4 comments
Closed

json.Unmarshal failed #75

Lvzhenqian opened this issue May 21, 2019 · 4 comments

Comments

@Lvzhenqian
Copy link

Lvzhenqian commented May 21, 2019

[root@localhost nginx_export]# ./nginx-vts-exporter -nginx.scrape_uri=http://xxx/status/format/json
2019/05/20 18:57:51 Starting nginx_vts_exporter (version=0.10.3, branch=HEAD, revision=8aa2881c7050d9b28f2312d7ce99d93458611d04)
2019/05/20 18:57:51 Build context (go=go1.10, user=root@56ca8763ee48, date=20180328-05:47:47)
2019/05/20 18:57:51 Starting Server at : :9913
2019/05/20 18:57:51 Metrics endpoint: /metrics
2019/05/20 18:57:51 Metrics namespace: nginx
2019/05/20 18:57:51 Scraping information from : http://xxx/status/format/json
2019/05/20 18:58:28 json.Unmarshal failed invalid character '\x1f' in string literal

func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
	body, err := fetchHTTP(e.URI, time.Duration(*nginxScrapeTimeout)*time.Second)()
	if err != nil {
		log.Println("fetchHTTP failed", err)
		return
	}
	defer body.Close()

	data, err := ioutil.ReadAll(body)
	if err != nil {
		log.Println("ioutil.ReadAll failed", err)
		return
	}
      // add this  code to remove character . now it worker 
	for index, char := range data {
		switch {
		case char > '~':
			data[index] = ' '
		case char == '\r':
		case char == '\n':
		case char == '\t':
		case char < ' ':
			data[index] = ' '
		}
	}
	var nginxVtx NginxVts
	err = json.Unmarshal(data, &nginxVtx)
@sysulq
Copy link
Owner

sysulq commented May 21, 2019

可以看下你的http://xxx/status/format/json 这个页面是什么数据

Please check what is it in your http://xxx/status/format/json page

@Lvzhenqian
Copy link
Author

json.txt
这是我的json文件,在serverZones里面拿到有特殊字符,所以解析失败了。

@sysulq
Copy link
Owner

sysulq commented May 21, 2019

@Lvzhenqian
Maybe you should justify your nginx config instead of replaceing special charactors...
也许你应该调整nginx配置,而不是替换特殊字符。。。

@Lvzhenqian
Copy link
Author

@Lvzhenqian
Maybe you should justify your nginx config instead of replaceing special charactors...
也许你应该调整nginx配置,而不是替换特殊字符。。。

serverZones 里的server_name,nginx-vts-module 拿出来时就有特殊字符。没看到有相关的详细配置。
vhost_traffic_status_filter_by_host on; 配置都加上了。所以我也是没办法中的办法 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants