-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsl_stats.php
210 lines (196 loc) · 5.83 KB
/
sl_stats.php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
///////////////
// HANDLE AUTH
///////////////
$query_field = 'user_id';
$id = 150;
$query_prefix = "$query_field=$id ";
?><html>
<head>
<?php include "../head.include.php";?>
<link href="/static/api/style.css" rel="stylesheet"/>
<style>
#min_sum {
width: 70px;
padding-left: 4px;
padding-right: 4px;
}
#wait {
position: fixed;
top:20%;
left:calc( 50% - 322px );
background: rgba(0,0,0,0.7);
border-radius: 20px;
padding:50px 50px;
color: #fff;
font-size:14px;
}
#wait>div {
float:left;
height:77px;
vertical-align: top;
}
#wait .wait_spinner {
width:77px;
height:77px;
}
#top_buttons {
line-height: 34px;
}
#top_buttons .btn {
height: 34px;
}
#top_buttons>*,#time_container>* {
vertical-align: bottom;
}
#timeslice {
width:auto;
}
iframe[name="result"] {
width:calc(100% - 25px);
height:calc(100% - 60px);
border:1px solid #ddd;
}
#ago{
width:61px;
padding-right:5px;
padding-left:5px;
}
#time_container {
display: inline;
}
#time_container>input {
width: 140px;
font-size: 12px;
line-height: 12px;
}
</style>
<script src="sl_queries.js?v=35"></script>
<script>
function copy_to_clipboard(value, onsuccess, onfail) {
var elem = $('<textarea>').val(value).appendTo('body').select();
try {
var success = document.execCommand('copy');
if (success) {
onsuccess && onsuccess();
} else {
console.log('Failed to copy')
onfail && onfail();
}
} catch (e) {
onfail && onfail();
console.log('Failed to copy: ', e);
}
elem.remove();
return success;
}
</script>
</head>
<body>
<div id="top_buttons">
<div id="time_container">
<!--
<select id="ago" class="form-control">
<option value="3">3h</option>
<option value="12">12h</option>
<option value="24" selected>24h</option>
<option value="48">48h</option>
<option value="144">6d</option>
<option value="720">30d</option>
</select> ago.
-->
<input id="from" type="date" value="<?=date("Y-m-d")?>" class="form-control">
to
<input id="to" type="date" value="<?=date("Y-m-d")?>" class="form-control">
<select id="timeslice" class="form-control">
<option value="1d">day</option>
<option value="1h">hour</option>
</select>
</div>
<select id="q" class="form-control" placeholder="Select query"></select>
<script>
$q=$('#q');
function populate_queries(){
var selectedIndex = Math.max(0,$q[0].selectedIndex || 0);
$q.empty();
Object.keys(sl_queries).forEach(function(k){
var query = "<?=$query_prefix?>" + sl_queries[k].replace(/\b1d\b/g,$('#timeslice').val());
var min_sum = $('#min_sum').val();
if (min_sum && /sum\(/.test(query)){
query = query.replace(/(\|\s*transpose[^|]*|$)/,' | where _sum >' + min_sum + ' $1');
}
query = optimize_sumo_query(query,$('#from').val(),$('#to').val());
var option = $('<option>').val(query).html(k);
$q.append(option);
});
$q[0].selectedIndex = selectedIndex;
}
populate_queries();
$('#timeslice,#from,#to,#min_sum').change(populate_queries);
</script>
<div id="chart_types" class="btn-group" role="group">
<button type="button" class="btn btn-default btn-s" val="Table" title="Simple Table"><i class="fa fa-table" ></i></button>
<button type="button" class="btn btn-default btn-s" val="LineChart" title="Line Chart" ><i class="fa fa-line-chart" ></i></button>
<button type="button" class="btn btn-default btn-s" val="PieChart" title="Pie Chart" ><i class="fa fa-pie-chart" ></i></button>
<button type="button" class="btn btn-default btn-s" val="ColumnChart" title="Bar Chart" ><i class="fa fa-bar-chart" ></i></button>
<button type="button" class="btn btn-default btn-s" val="GeoChart" title="World Map" ><i class="fa fa-globe" ></i></button>
</div>
Filter by min value of <input id="min_sum" type="number" value="" class="form-control">
<a id="go" target="result" class="btn btn-primary btn-s">Go</a>
<span id="copy" class="btn btn-default btn-s adoptOnly" title="Copy query for sumologic website"></span>
</div>
<iframe id="frm" name="result"></iframe>
<div id="wait">
<div>
<i class="wait_spinner"></i>
</div>
<div>
<h3>Loading data...</h3>
Some queries may take longer to complete
</div>
</div>
<script>
$('#wait').hide();
$('#frm').on('load',function(){
$('#wait').fadeOut();
});
$('#go').click(function(){
$('#wait').fadeIn();
});
var AUTOCLOSE_NOTIFICATION = 10;
var href_tmpl = "chart.php?api_key=<?=$api_key?>&id=<?=$id?>&mode=<?=$mode?>&q=_QUERY_&chartType=_CHARTTYPE_&html_table=0&from=_FROM_&to=_TO_";
// to support 'ago' remove to &to and use: &from=-_AGO_h
$('#chart_types button').click(function(){
$('#chart_types button.btn-primary').removeClass('btn-primary');
$(this).addClass('btn-primary');
}).first().click();
$('#copy').click(function(){
copy_to_clipboard($('#q').val(),
function(){
$('#copy').addClass('btn-success').text('Copied');
},
function(){
$('#copy').addClass('btn-danger').text("Can't Copy");
});
});
function update_go(){
$('#copy').removeClass('btn-success btn-danger').text('Copy Query');
var query = $('#q').val();
$('#chart_types [val="GeoChart"]').prop('disabled',!/by geo/.test(query));
var $go = $('#go');
var chartType=$('#chart_types .btn-primary').attr('val');
var timeFrom = $('#from').val() + '+00:00:00';
var timeTo = $('#to').val() + '+23:59:59';
$go.prop('href',href_tmpl
.replace('_QUERY_',encodeURIComponent(query))
.replace('_TO_',timeTo)
.replace('_FROM_',timeFrom)
.replace('_CHARTTYPE_',chartType)
);
}
$('#q,#from,#to,#timeslice,#chart_types button').on('click change',update_go);
update_go();
</script>
</body>
</html>