Skip to content

Commit

Permalink
Merge pull request #78 from YellowBloomKnapsack/feature/grafana
Browse files Browse the repository at this point in the history
Feature/grafana
  • Loading branch information
MSPoulaei authored Jul 30, 2024
2 parents 8d9d0c0 + 4136974 commit 6c64499
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adserver/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ func (r *AdServerCache) Add(key string) {
if err != nil {
log.Println("could not insert " + key + " in adserver redis: " + err.Error())
}
}
}
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,32 @@ services:
- REDIS_ADDR=redis:6379
ports:
- "9121:9121"
depends_on:
- redis
kafka-exporter:
image: danielqsj/kafka-exporter:v1.7.0
command:
- --kafka.server=kafka:9092
ports:
- "9308:9308"
depends_on:
- kafka
postgres-exporter:
image: prometheuscommunity/postgres-exporter:v0.15.0
environment:
- DATA_SOURCE_NAME=postgresql://postgres:1234@db:5432/mini_yektanet_db?sslmode=disable
ports:
- "9187:9187"
depends_on:
- db
zookeeper-exporter:
image: dabealu/zookeeper-exporter:v0.1.13
environment:
- ZK_SERVER=zookeeper:2181
ports:
- "9141:9141"
depends_on:
- zookeeper

volumes:
panel_static:
Expand Down
78 changes: 78 additions & 0 deletions panel/grafana/grafana.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package grafana

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"YellowBloomKnapsack/mini-yektanet/common/grafana"
)

var (
ActiveAdsCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "active_ads_count",
Help: "The total number of active ads",
})

AdvertisersCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "advertisers_count",
Help: "The total number of advertisers",
})

PublishersCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "publishers_count",
Help: "The total number of publishers",
})

ImpressionCount = promauto.NewCounter(prometheus.CounterOpts{
Name: "impression_count",
Help: "The total number of impressions",
})

ClickCount = promauto.NewCounter(prometheus.CounterOpts{
Name: "click_count",
Help: "The total number of clicks",
})

TotalRevenue = promauto.NewCounter(prometheus.CounterOpts{
Name: "total_revenue",
Help: "The total revenue generated",
})

NumberOfBids = promauto.NewGauge(prometheus.GaugeOpts{
Name: "number_bids",
Help: "total number of bids",
})

AverageBid = promauto.NewGauge(prometheus.GaugeOpts{
Name: "average_bid",
Help: "The average bid amount",
})

TransactionCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "transaction_count",
Help: "The number of transactions",
}, []string{"status"})

TotalAdvertiserBalance = promauto.NewGauge(prometheus.GaugeOpts{
Name: "total_advertiser_balance",
Help: "The total balance of all advertisers",
})

TotalPublisherBalance = promauto.NewGauge(prometheus.GaugeOpts{
Name: "total_publisher_balance",
Help: "The total balance of all publishers",
})
)

func InitializeMetrics() {
ActiveAdsCount.Set(0)
AdvertisersCount.Set(0)
PublishersCount.Set(0)
ImpressionCount.Set(0)
ClickCount.Set(0)
TotalRevenue.Set(0)
NumberOfBids.Set(0)
AverageBid.Set(0)
TransactionCount.Set(0)
TotalAdvertiserBalance.Set(0)
TotalPublisherBalance.Set(0)
}
4 changes: 4 additions & 0 deletions prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ scrape_configs:
- job_name: 'postgres'
static_configs:
- targets: ['postgres-exporter:9187']

- job_name: 'zookeeper'
static_configs:
- targets: ['zookeeper-exporter:9141']
# - job_name: 'redis'
# static_configs:
# - targets: ['redis:6379']
Expand Down

0 comments on commit 6c64499

Please sign in to comment.