@@ -35,8 +35,12 @@ def _convert_candidates_to_upgrade_infos(candidates):
3535 changes_dict = collections .defaultdict (lambda : collections .defaultdict (int ))
3636
3737 for candidate in candidates :
38+ # The 'now' archive only shows that packages are not installed. We tend
39+ # to filter the candidates on those kinds of conditions before reaching
40+ # here so here we don't want to include this information in order to
41+ # reduce noise in the data.
3842 origins = sorted (
39- {f"{ o .origin } :{ o .codename } /{ o .archive } " for o in candidate .origins }
43+ {f"{ o .origin } :{ o .codename } /{ o .archive } " for o in candidate .origins if o . archive != 'now' }
4044 )
4145 changes_dict ["," .join (origins )][candidate .architecture ] += 1
4246
@@ -101,6 +105,17 @@ def _write_autoremove_pending(registry, cache):
101105 g .set (len (autoremovable_packages ))
102106
103107
108+ def _write_installed_packages_per_origin (registry , cache ):
109+ installed_packages = {p .candidate for p in cache if p .is_installed }
110+ per_origin = _convert_candidates_to_upgrade_infos (installed_packages )
111+
112+ if per_origin :
113+ g = Gauge ('apt_installed_per_origin' , "Numberof ppt packages installed per origin." ,
114+ ['origin' , 'arch' ], registry = registry )
115+ for o in per_origin :
116+ g .labels (o .labels ['origin' ], o .labels ['arch' ]).set (o .count )
117+
118+
104119def _write_cache_timestamps (registry ):
105120 g = Gauge ('apt_package_cache_timestamp_seconds' , "Apt update last run time." , registry = registry )
106121 apt_pkg .init_config ()
@@ -134,6 +149,7 @@ def _main():
134149 _write_held_upgrades (registry , cache )
135150 _write_obsolete_packages (registry , cache )
136151 _write_autoremove_pending (registry , cache )
152+ _write_installed_packages_per_origin (registry , cache )
137153 _write_cache_timestamps (registry )
138154 _write_reboot_required (registry )
139155 print (generate_latest (registry ).decode (), end = '' )
0 commit comments