Skip to content

Commit

Permalink
Merge pull request #9 from tcheronneau/alpha
Browse files Browse the repository at this point in the history
Plex improvements
  • Loading branch information
tcheronneau authored Nov 12, 2024
2 parents dfaa896 + 5887af8 commit 79cbaad
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 112 deletions.
37 changes: 19 additions & 18 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chrono = "0.4.34"
clap = "4.5.1"
clap-verbosity-flag = "2.2.0"
figment = { version = "0.10.14", features = ["toml", "env"] }
futures = "0.3.31"
ipgeolocate = "0.3.6"
json = "0.12.4"
lazy_static = "1.4.0"
Expand Down
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# HOMERS

![dev build](https://github.com/github/tcheronneau/homers/workflows/build.yml/badge.svg?branch=dev)
![latest build](https://github.com/tcheronneau/homers/actions/workflows/build-latest.yml/badge.svg?branch=main)

This project has the purposed to be a replacement for [Varken](https://github.com/Boerderij/Varken).
Since InfluxDB is not a good option for me, I decided to use prometheus and to build an exporter.

It's not ready yet, but some features are already there.
The project is still in early stage and a lot can still change.

![image](https://github.com/user-attachments/assets/9a0c2fb0-52f3-439d-b590-9c6698994d10)

Expand All @@ -20,7 +23,7 @@ You can either use configuration file or environment variables.
Each config key has a correspondent environment variable.
Example: `config.toml`:
```toml
[server]
[http]
port=8000
address="0.0.0.0"
[sonarr.main]
Expand All @@ -44,6 +47,18 @@ api_key=""
address="http://localhost:5055"
api_key=""
requests=200

[plex.main]
address="http://localhost:32400"
token=""

```

Example: `environement`:
```bash
HOMERS_HTTP_ADDRESS: "0.0.0.0"
HOMERS_SONARR_MAIN_ADDRESS: "http://localhost:8989"
HOMERS_SONARR_MAIN_APIKEY: ""
```

For overseerr you can customize the number of requests you want to pull. Default is 20.
Expand All @@ -61,7 +76,7 @@ Then you can run `cargo build --release`.

Alternatively you can also use nix.
To build the project using nix, you can run `nix build .#`.
And for the docker image :
And for the docker image (not used anymore for the current build):
```
nix build .#docker
docker load < ./result
Expand All @@ -71,20 +86,21 @@ docker load < ./result
## Advancement

So far it's not doing much.
[X] Retrieve Sonarr today's calendar
[X] Retrieve Tautulli activity
[X] Retrieve Tautulli library information
[X] Retrieve Overseerr requests
[X] Retrieve missing episodes from sonarr
[ ] Retrieve watch information from tautulli
[ ] Connect to ombi (I'm not using it but if required could do)
[ ] Other
[X] Retrieve Sonarr today's calendar
[X] Retrieve Tautulli activity
[X] Retrieve Tautulli library information
[X] Retrieve Overseerr requests
[X] Retrieve missing episodes from sonarr
[X] Retrieve watch information from tautulli
[ ] Retrieve watch information from plex (in progress available in dev tag)
[ ] Retrieve watch information from jellyfin
[ ] Connect to ombi (I'm not using it but if required could do)
[ ] Other

## Roadmap

The point is to at least support what Varken was doing.
There will also be a Grafana dashboard.
Grafana dashboard is now live at [Grafana](https://grafana.com/grafana/dashboards/20744).
Grafana dashboard example can be found at [Grafana](https://grafana.com/grafana/dashboards/20744).


## Acknowledgments
Expand Down
21 changes: 14 additions & 7 deletions src/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use prometheus_client::metrics::family::Family;
use prometheus_client::metrics::gauge::Gauge;
use prometheus_client::registry::Registry;
use std::collections::HashMap;
use std::fmt::Write;
use std::sync::atomic::AtomicU64;

use crate::providers::overseerr::{self, OverseerrRequest};
use crate::providers::overseerr::OverseerrRequest;
use crate::providers::plex::{LibraryInfos, PlexSessions};
use crate::providers::radarr::RadarrMovie;
use crate::providers::sonarr::SonarrEpisode;
Expand Down Expand Up @@ -80,6 +79,8 @@ struct PlexLibraryLabels {
pub name: String,
pub library_name: String,
pub library_type: String,
pub season_count: Option<i64>,
pub episode_count: Option<i64>,
}

#[derive(Clone, Hash, Eq, PartialEq, EncodeLabelSet, Debug)]
Expand Down Expand Up @@ -143,6 +144,7 @@ struct OverseerrLabels {
pub media_type: String,
pub requested_by: String,
pub request_status: String,
pub media_status: String,
pub media_title: String,
pub requested_at: String,
}
Expand Down Expand Up @@ -341,14 +343,15 @@ fn format_radarr_metrics(radarr_hash: HashMap<String, Vec<RadarrMovie>>, registr
fn format_overseerr_metrics(requests: Vec<OverseerrRequest>, registry: &mut Registry) {
debug!("Formatting {requests:?} as Prometheus");
let overseerr_request = Family::<OverseerrLabels, Gauge<f64, AtomicU64>>::default();
let mut registy_request = HashMap::new();
let mut registy_media = HashMap::new();
//let mut registy_request = HashMap::new();
//let mut registy_media = HashMap::new();
registry.register(
"overseerr_requests",
format!("overseerr requests status"),
overseerr_request.clone(),
);

/*
overseerr::MediaStatus::get_all()
.into_iter()
.for_each(|status| {
Expand All @@ -375,18 +378,20 @@ fn format_overseerr_metrics(requests: Vec<OverseerrRequest>, registry: &mut Regi
registy_request.get(&status.to_string()).unwrap().clone(),
);
});
*/
requests.into_iter().for_each(|request| {
let labels = OverseerrLabels {
media_type: request.media_type.clone(),
requested_by: request.requested_by.to_string(),
request_status: request.status.to_string(),
media_status: request.media_status.to_string(),
media_title: request.media_title,
requested_at: request.requested_at,
};
overseerr_request
.get_or_create(&labels)
.set(request.media_status as f64);
match request.status.into() {
.set(request.status.as_f64());
/*match request.status.into() {
overseerr::RequestStatus::Pending => {
registy_request
.get(&overseerr::RequestStatus::Pending.to_string())
Expand Down Expand Up @@ -414,7 +419,7 @@ fn format_overseerr_metrics(requests: Vec<OverseerrRequest>, registry: &mut Regi
})
.inc();
}
};
};*/
});
}

Expand Down Expand Up @@ -504,6 +509,8 @@ fn format_plex_library_metrics(
name: name.clone(),
library_name: lib.library_name.clone(),
library_type: lib.library_type.clone(),
season_count: lib.library_child_size,
episode_count: lib.library_grand_child_size,
})
.set(lib.library_size as f64);
});
Expand Down
Loading

0 comments on commit 79cbaad

Please sign in to comment.