Skip to content

Commit

Permalink
Add various prometheus metrics
Browse files Browse the repository at this point in the history
Add routes for tracking command usage via influxdb
Add routes for getting analytics like cmd usage
Update year in LICENSE
Response code cleanup
Make get post route work with slugs and only public/unlisted visibility
Add new features to readme
  • Loading branch information
dustinrouillard committed Jul 5, 2024
1 parent c702fc9 commit 6a04305
Show file tree
Hide file tree
Showing 30 changed files with 814 additions and 271 deletions.
183 changes: 180 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ sha1 = "0.10.6"
hex = "0.4.3"
gql_client = "1.0.7"
actix-cors = "0.7.0"
prometheus = { version = "0.13.4", features = ["process"] }
futures-util = "0.3.30"
prometheus-http-query = "0.8.3"
influxdb2 = "0.5.1"
influxdb2-structmap = "0.2.0"

[profile.release]
lto = true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License Copyright (c) 2022 Dustin Rouillard
MIT License Copyright (c) 2024 Dustin Rouillard

Permission is hereby granted,
free of charge, to any person obtaining a copy of this software and associated
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Dustin API
# dstn.to API

There is probably a lot of better ways to do many of the things I've done here, but this is one of the first things I've done in rust, make suggestions if you see anything done weirdly!

Built with actix-web, makes use of prisma to handle queries to a postgresql database and uses valkey/redis for storage of tokens and caching data.

## Used for

- Spotify History and Now Playing API / Queue Messages
- File and Screenshot Uploads
- Spotify History and Now Playing API / Provides realtime queue for [gateway](https://github.com/dustinrouillard/dustin-gateway)
- File and Screenshot Uploads (Multipart uploads to an s3 bucket)
- Github pinned repositories
- Blog System for Personal Site
- Blog System for [Personal Site](https://github.com/dustinrouillard/personal-site)
- Local weather (This just proxies my [weather worker](https://github.com/dustinrouillard/weather-worker))
- Analytics tracking (commands per day, etc)
- Prometheus metrics (API route and process metrics)
27 changes: 27 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub struct Config {
#[envconfig(from = "LISTEN_PORT", default = "8080")]
pub listen_port: u16,

#[envconfig(from = "METRICS_LISTEN_PORT", default = "8081")]
pub metrics_listen_port: u16,

#[envconfig(
from = "SPOTIFY_CLIENT_ID",
default = "01ba26764aca4594a26f4cc59cd3f01f"
Expand Down Expand Up @@ -64,4 +67,28 @@ pub struct Config {

#[envconfig(from = "GITHUB_PAT", default = "")]
pub github_pat: String,

#[envconfig(from = "WEATHER_COORDS", default = "37.8283/-96.5795")]
pub weather_coords: String,

#[envconfig(
from = "PROMETHEUS_HOST",
default = "https://prometheus.monit.kush/"
)]
pub prometheus_host: String,

#[envconfig(from = "INFLUXDB_TOKEN", default = "")]
pub influxdb_token: String,

#[envconfig(
from = "INFLUXDB_HOST",
default = "http://influxdb.kube-system"
)]
pub influxdb_host: String,

#[envconfig(from = "INFLUXDB_ORG", default = "lab")]
pub influxdb_org: String,

#[envconfig(from = "INFLUXDB_BUCKET", default = "api")]
pub influxdb_bucket: String,
}
23 changes: 23 additions & 0 deletions src/connectivity/influxdb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use envconfig::Envconfig;
use influxdb2::Client;

use crate::config::Config;

#[derive(Clone)]
pub struct InfluxManager {
pub client: Client,
}

impl InfluxManager {
pub async fn new() -> Self {
let config = Config::init_from_env().unwrap();
let client = influxdb2::Client::new(
config.influxdb_host,
config.influxdb_org,
config.influxdb_token,
);

tracing::info!("Connected to influxdb");
Self { client }
}
}
Loading

0 comments on commit 6a04305

Please sign in to comment.