diff --git a/codexcrawler/config.nim b/codexcrawler/config.nim index 5506407..1fa4328 100644 --- a/codexcrawler/config.nim +++ b/codexcrawler/config.nim @@ -10,7 +10,7 @@ Usage: Options: --logLevel= Sets log level [default: TRACE] - --metricsAddress= Listen address of the metrics server [default: 127.0.0.1] + --metricsAddress= Listen address of the metrics server [default: 0.0.0.0] --metricsPort=

Listen HTTP port of the metrics server [default: 8008] --dataDir=

Directory for storing data [default: crawler_data] --discoveryPort=

Port used for DHT [default: 8090] diff --git a/codexcrawler/list.nim b/codexcrawler/list.nim new file mode 100644 index 0000000..591ba21 --- /dev/null +++ b/codexcrawler/list.nim @@ -0,0 +1,20 @@ +import pkg/metrics + +type + OnUpdateMetric = proc(value: int64): void {.gcsafe, raises:[].} + List*[T] = ref object + items: seq[T] + onMetric: OnUpdateMetric + +proc new*[T]( + _: type List[T], + onMetric: OnUpdateMetric +): List[T] = + List[T]( + items: newSeq[T](), + onMetric: onMetric + ) + +proc add*[T](this: List[T], item: T) = + this.items.add(item) + this.onMetric(this.items.len.int64) diff --git a/codexcrawler/main.nim b/codexcrawler/main.nim index e3e8748..5fb488a 100644 --- a/codexcrawler/main.nim +++ b/codexcrawler/main.nim @@ -1,14 +1,26 @@ import pkg/chronicles import pkg/chronos +import pkg/metrics + +import ./list + logScope: topics = "main" +declareGauge(example, "testing") + proc startApplication*() {.async.} = + proc onExampleMetric(value: int64) = + example.set(value) + var exampleList = List[string].new(onExampleMetric) + proc aaa() {.async.} = while true: notice "a" await sleepAsync(1000) + exampleList.add("str!") + asyncSpawn aaa() diff --git a/config.nims b/config.nims new file mode 100644 index 0000000..d8bdeee --- /dev/null +++ b/config.nims @@ -0,0 +1 @@ +--define:metrics