当前位置:网站首页>Grafana influxdb simple script
Grafana influxdb simple script
2022-04-22 06:18:00 【Crazy snail】
One 、 demand
machine IP:ip1 ip2 ip3
File storage path :/data/logs/bireport/statistics
File update time : Every morning 1 spot
The contents of the document : The first line is the number of timeouts , The second line is the total number of calls
#rsync client
1 2 * * * sh /root/rsync_bi.sh
cat /root/rsync_bi.sh
#!/bin/bash
passwdfile="/root/.rsync.passwd"
server="[email protected]::backup"
server_patch=$server/ip1
pathfile=/data/logs/bireport/statistics
/usr/bin/rsync -qazu --password-file=$passwdfile $pathfile $server_patch/
#grafana server
30 2 * * * sh /data/bireport/bi_request.sh
[root@localhost bireport]# cat bi_request.sh
#!/bin/bash
pathdir="/data/bireport"
filename="bi_history"
ip_num=(ip1
ip2
ip3)
datetime1=`date -d "yesterday" +%Y%m%d`
datetime=`date -d "$datetime1 0 +8 hour" +"%Y%m%d %H"`
timeStamp_y=`date -d "$datetime" +%s`
#hour_8=28800000
timeStamp=`expr $timeStamp_y \* 1000`
for ip in ${ip_num[@]}
do
if [ ! -f "$pathdir/$ip/statistics" ]; then
echo "ERROR: $pathdir/$ip/statistics is not exist!"
exit 1
else
timeout_num=`cat $pathdir/$ip/statistics |awk 'NR<2'`
request_num=`cat $pathdir/$ip/statistics |awk 'NR>1'`
rate_num=`echo "scale=4; a = $timeout_num / $request_num; if (length(a)==scale(a)) print 0;print a" | bc`
echo $timeStamp $ip $request_num $timeout_num $rate_num >> $pathdir/$filename
/usr/bin/curl -i -XPOST 'http://127.0.0.1:8086/write?db=bi_request_info&precision=ms' -u admin:cAauFWEtLerqH4EP --data-binary 'bi_info,host_id='$ip' request_num='$request_num',timeout_num='$timeout_num',rate_mun='$rate_num' '$timeStamp''
mv $pathdir/$ip/statistics $pathdir/$ip/$timeStamp"statistics"
fi
done
notes : Cause right influxdb I'm not familiar with the time format , Waste a lot of time ;
Two 、influxdb In time format
influxdb Three time formats are supported ,epoch_time Outside , And support rfc3339_date_time_string and rfc3339_like_date_time_string.
1、epoch_time Format
A time stamp indicates , We usually use 10 Bit and 13 position , stay influxdb The timestamp used in is 19 position , The unit is ns( nanosecond )
2、rfc3339_date_time_string Format
This format is :'YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ', among nnnnnnnnn It's optional , If you don't write, it will be set to 000000000. Be careful , If you use this time format , You need to use single quotes ’ Enclose time .
3、rfc3339_like_date_time_string
This format is :'YYYY-MM-DD HH:MM:SS.nnnnnnnnn' , among HH::MM:SS.nnnnnnnnn It can be omitted , Must be enclosed in single quotes .
4、 Query by timestamp
Second level :
select * from disk where time >= 1542954639s and time <= 1542964713s
millisecond :
select * from disk where time >= 1542954639000ms and time <= 1542964714000ms
Nanosecond :
select * from disk where time >= 1542954639000000000ms and time <= 1542964714000000000ms
5、 Adjust time zone query - Beijing time.
select * from disk where time >= '2018-11-23 14:30:39' and time <= '2018-11-23 14:32:32' tz('Asia/Shanghai')
notes :
1、 because grafana To use UTC Time , So... Is added in this example 8 Hours
2、curl When inserting data , Such as insertion time The time format needs to be set &precision=ms For milliseconds , Or for s
3、 Inserted data --data-binary You need to add single quotation marks after ''
版权声明
本文为[Crazy snail]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220547471423.html
边栏推荐
猜你喜欢
随机推荐
vscode之 settings.json 的配置
!!!!!!!!!!!!!!!!!!
Directive redis
JS waits for asynchronous execution to complete before executing
laravel路由设置
Complete binary tree
软考备考通关经验心得
Graylog服务器rpm安装
两位小数正则验证
Interface test seldom
Fastapi (II)
重读Scrapy:Spider篇_CrawlSpider的使用分析
Table example
SSH免密登录
Ehcache memcache redis 三大缓存
uniapp原生插件使用
在components文件夹下创建Tabbar组件,公用
Regular verification of two decimal places
svn: E155004: is already locked.
PHP month difference








![[required] 123](/img/ea/fa6d212be7ac63974f57a206e6368d.png)
