Skip to content

Commit f00f458

Browse files
authored
feat/metrics example (#11) + fix new sybase package structure issue
Add an example to support metrics/timers in stored procedure / sql in sybase - use sp_sendmsg to send udp pakets - create a script sample to find the best trafeoffs and alternative to a common stopwatch - integrate metrics in prometheus with statsd-exporter adapter # Stopwatch tradeoff Measuring delay with 2 dates is not recommended but to measure high latencies (> 1s since the precision is up to 1/300 second according to sybase documentation) without true stopwatch/timestamp, it is ok.
1 parent 08796e1 commit f00f458

File tree

11 files changed

+168
-2
lines changed

11 files changed

+168
-2
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
FROM centos:7 as base
22
FROM base as builder
33

4-
ADD https://d1cuw2q49dpd0p.cloudfront.net/ASE16/Current/ASE_Suite.linuxamd64.tgz /tmp/ASE
5-
RUN pushd /tmp && tar -xvzf /tmp/ASE && rm -f ASE && mv ebf30399 ASE && popd
4+
ADD https://d1cuw2q49dpd0p.cloudfront.net/ASE16/Current/ASE_Suite.linuxamd64.tgz /tmp/ASE/ASE_Suite.linuxamd64.tgz
5+
RUN pushd /tmp/ASE && tar -xvzf ASE_Suite.linuxamd64.tgz && rm -f ASE_Suite.linuxamd64.tgz && popd
66
COPY ./sybase_response.txt /tmp/ASE
77

88
FROM base as basedeps

examples/compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
graphite:
3+
image: graphiteapp/graphite-statsd
4+
ports:
5+
- 80:80
6+
- 81:81
7+
- 2003-2004:2003-2004
8+
- 2023-2024:2023-2024
9+
- 8125:8125/udp
10+
- 8126:8126

examples/observability/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# sybase statsd
2+
3+
## run the demo
4+
```bash
5+
cd examples/observability
6+
7+
docker compose down --remove-orphans -v --rmi local && docker compose up
8+
```
9+
10+
go to [prometheus dashboard and observe the percentile metrics](http://localhost:9090/graph?g0.expr=sybase_test_table_insert&g0.tab=0&g0.stacked=1&g0.show_exemplars=0&g0.range_input=1h&g0.step_input=1)
11+
12+
## configure send udp paket from sybase
13+
14+
### setup
15+
```sql
16+
sp_configure 'allow sendmsg', 1
17+
go
18+
```
19+
20+
### send metrics example
21+
```sql
22+
sp_sendmsg "host.docker.internal", 8125, "sybase.hello:10|c"
23+
go
24+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use TESTDB
2+
go
3+
4+
/* Tradeoff : measure delay with datetime (no support for ticks nor timestamp nor true stopwatch, precision is 1/300 second). Ok to measure high latencies ie : > 1s */
5+
declare @s datetime
6+
select @s = GETUTCDATE()
7+
8+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
9+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
10+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
11+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
12+
insert into dbo.TEST_TABLE(TEST_FIELD1) values ('1')
13+
14+
declare @e datetime
15+
select @e = GETUTCDATE()
16+
17+
declare @t integer
18+
select @t = DATEDIFF(MILLISECOND, @s, @e)
19+
20+
declare @msg varchar(255)
21+
select @msg = "sybase.test_table.insert:" + convert(varchar, @t) + "|ms"
22+
exec sp_sendmsg "statsd", 8125, @msg
23+
24+
go
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
. /opt/sap/SYBASE.sh
3+
4+
set -u
5+
6+
while true
7+
do
8+
echo running $1
9+
isql -Usa -S${SERVER}:5000 -P${SA_PASSWORD} -D${DATABASE} -i $1
10+
sleep 1
11+
done

examples/observability/compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
services:
2+
prometheus:
3+
image: prom/prometheus:v2.41.0
4+
volumes:
5+
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
6+
ports:
7+
- 9090:9090
8+
9+
statsd:
10+
image: prom/statsd-exporter:v0.23.0
11+
command: "--statsd.listen-udp=:8125 --web.listen-address=:9102 --log.level=debug"
12+
13+
database:
14+
image: superbeeeeeee/docker-sybase
15+
environment:
16+
- DATABASE=TESTDB
17+
- SA_PASSWORD=Sybase1234
18+
volumes:
19+
- ./database/:/docker-entrypoint-initdb.d/
20+
healthcheck:
21+
test: healthcheck
22+
interval: 5s
23+
24+
client:
25+
image: superbeeeeeee/docker-sybase
26+
entrypoint: ["/schedule.sh", "/data.sql"]
27+
environment:
28+
- DATABASE=TESTDB
29+
- SA_PASSWORD=Sybase1234
30+
- SERVER=database
31+
volumes:
32+
- ./client/schedule.sh:/schedule.sh:ro
33+
- ./client/data.sql:/data.sql:ro
34+
depends_on:
35+
database:
36+
condition: service_healthy
37+
statsd:
38+
condition: service_started
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use TESTDB
2+
go
3+
sp_configure 'allow sendmsg', 1
4+
go
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use TESTDB
2+
go
3+
CREATE TABLE dbo.TEST_TABLE (
4+
IDROW numeric(18,0) IDENTITY NOT NULL,
5+
TEST_FIELD1 char(4) NOT NULL,
6+
)
7+
LOCK DATAROWS
8+
WITH exp_row_size = 0, reservepagegap = 0, identity_gap = 500, DML_LOGGING = FULL
9+
ON [default]
10+
GO
11+
CREATE NONCLUSTERED INDEX I1_TEST_TABLE
12+
ON dbo.TEST_TABLE(TEST_FIELD1)
13+
ON [default]
14+
GO
15+
CREATE UNIQUE NONCLUSTERED INDEX UI_TEST_TABLE
16+
ON dbo.TEST_TABLE(IDROW)
17+
ON [default]
18+
GO
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
global:
2+
scrape_interval: 15s # By default, scrape targets every 15 seconds.
3+
4+
external_labels:
5+
monitor: 'prometheus-monitor'
6+
7+
scrape_configs:
8+
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
9+
- job_name: 'prometheus'
10+
11+
# Override the global default and scrape targets from this job every 5 seconds.
12+
scrape_interval: 5s
13+
14+
static_configs:
15+
- targets: ['localhost:9090']
16+
17+
- job_name: 'statsd-exporter'
18+
19+
# Override the global default and scrape targets from this job every 5 seconds.
20+
scrape_interval: 5s
21+
22+
static_configs:
23+
- targets: ['statsd:9102']
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
port: 8125
3+
, backends: ["./backends/console"]
4+
, debug: true
5+
, dumpMessages: true
6+
, console:
7+
{ prettyprint: true }
8+
}

0 commit comments

Comments
 (0)