-
Notifications
You must be signed in to change notification settings - Fork 2
/
lokiheart.js
76 lines (66 loc) · 1.78 KB
/
lokiheart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import exec from 'k6/execution';
import { sleep } from 'k6'
import http from 'k6/http';
// See https://k6.io/docs/using-k6/options
export const options = {
stages: [
{ duration: '1m', target: 2 },
{ duration: '3m', target: 2 },
{ duration: '1m', target: 0 },
],
thresholds: {
http_req_failed: ['rate<0.02'], // http errors should be less than 2%
http_req_duration: ['p(95)<2000'], // 95% requests should be below 2s
},
ext: {
loadimpact: {
distribution: {
'amazon:us:ashburn': { loadZone: 'amazon:us:ashburn', percent: 100 },
},
},
},
}
export default function main() {
let data= {
"streams": [
{
"stream": {
"app": "lokiheart"
},
"values": [
]
}
]
};
let now= new Date();
let start= (now.getTime()- 5*60*1000)*1000*1000;
let line1= new Array();
let phi= Math.random()*2.0*Math.PI;
let x, y;
let found= false;
do {
x= -1.5+Math.random()*3;
y= -1.5+Math.random()*3;
if( ((x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1) - x*x*y*y*y ) < 0)
found= true;
} while(!found)
x= x*0.04/1.5;
y= y*0.02/1.5;
let rx= -0.1752099746981364;
let ry= 51.494115339030685;
line1[0]= ""+start;
line1[1]="longitude="+(rx+x)+" latitude="+(ry+y)+ " value="+Math.random();
/* if you want to have json logs instead of logfmt
let json='{"longitude":'+(rx+x)+', "latitude":'+(ry+y)+', "value":'+Math.random()+'}';
console.log("JSON: "+ json);
line1[1]= json;
*/
let v1=data.streams[0].values[0]= line1;
let url= "https://"+__ENV.LOKIUSER+":"+__ENV.LOKITOKEN+"@"+__ENV.LOKIURL+"/loki/api/v1/push";
console.log("url: "+url);
console.log("data: "+JSON.stringify(data));
let res = http.post(url, JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' },
});
sleep(1)
}